Skip to content

Commit 7002310

Browse files
fix: disable CGO for all npm builds and improve test coverage
- Set CGO_ENABLED=0 for all platform builds (Darwin, Linux, Windows) since the codebase is pure Go with no C dependencies - Remove unnecessary mingw cross-compiler dependencies from CI - Fix wrapper script error handling: use ?? instead of || for proper null status handling - Enhance test-npm-build.sh with: - Verification of all 6 platform binaries (was only checking 2) - Binary architecture validation using 'file' command - Exit code propagation test for wrapper script The codebase has no CGO imports, so CGO_ENABLED=0 is the accurate setting for cross-compilation. This simplifies the build process and removes the need for platform-specific cross-compilers. See #202 for discussion on Windows 32-bit support. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d99410f commit 7002310

5 files changed

Lines changed: 83 additions & 34 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ jobs:
140140
with:
141141
go-version: 1.24.9
142142

143-
- name: Install Windows cross-compilation tools
144-
run: |
145-
sudo apt-get update
146-
sudo apt-get install -y gcc-mingw-w64-x86-64
147-
148143
- name: Build npm binaries with GoReleaser
149144
uses: goreleaser/goreleaser-action@v5
150145
with:

.github/workflows/test-npm-build.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@ jobs:
1212
steps:
1313
- name: Code checkout
1414
uses: actions/checkout@v4
15-
15+
1616
- name: Set up Go
1717
uses: actions/setup-go@v5
1818
with:
1919
go-version: 1.24.9
20-
21-
- name: Install Windows cross-compilation tools
22-
run: |
23-
sudo apt-get update
24-
sudo apt-get install -y gcc-mingw-w64-x86-64
25-
20+
2621
- name: Set up Node.js
2722
uses: actions/setup-node@v4
2823
with:
2924
node-version: "20.x"
30-
25+
3126
- name: Install GoReleaser
3227
uses: goreleaser/goreleaser-action@v5
3328
with:
3429
version: v2.10.2
3530
install-only: true
36-
31+
3732
- name: Run npm build tests
3833
run: |
3934
chmod +x test-scripts/test-npm-build.sh

.goreleaser/npm.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ before:
77
- go generate ./...
88
project_name: hookdeck
99
builds:
10-
# Darwin builds
10+
# Darwin builds (CGO disabled for cross-compilation from Ubuntu)
1111
- id: npm-darwin-amd64
1212
binary: hookdeck
1313
main: ./main.go
1414
goos: [darwin]
1515
goarch: [amd64]
1616
env:
17-
- CGO_ENABLED=1
17+
- CGO_ENABLED=0
1818
ldflags:
1919
- -s -w -X github.com/hookdeck/hookdeck-cli/pkg/version.Version={{.Version}}
2020
hooks:
@@ -28,6 +28,8 @@ builds:
2828
main: ./main.go
2929
goos: [darwin]
3030
goarch: [arm64]
31+
env:
32+
- CGO_ENABLED=0
3133
ldflags:
3234
- -s -w -X github.com/hookdeck/hookdeck-cli/pkg/version.Version={{.Version}}
3335
hooks:
@@ -67,16 +69,14 @@ builds:
6769
- cp "{{ .Path }}" binaries/linux-arm64/hookdeck
6870
- chmod +x binaries/linux-arm64/hookdeck
6971

70-
# Windows builds
72+
# Windows builds (CGO disabled - codebase is pure Go)
7173
- id: npm-windows-amd64
7274
binary: hookdeck
7375
main: ./main.go
7476
goos: [windows]
7577
goarch: [amd64]
7678
env:
77-
- CGO_ENABLED=1
78-
- CC=x86_64-w64-mingw32-gcc
79-
- CXX=x86_64-w64-mingw32-g++
79+
- CGO_ENABLED=0
8080
ldflags:
8181
- -s -w -X github.com/hookdeck/hookdeck-cli/pkg/version.Version={{.Version}}
8282
hooks:
@@ -90,9 +90,7 @@ builds:
9090
goos: [windows]
9191
goarch: [386]
9292
env:
93-
- CGO_ENABLED=1
94-
- CC=x86_64-w64-mingw32-gcc
95-
- CXX=x86_64-w64-mingw32-g++
93+
- CGO_ENABLED=0
9694
ldflags:
9795
- -s -w -X github.com/hookdeck/hookdeck-cli/pkg/version.Version={{.Version}}
9896
hooks:

bin/hookdeck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ try {
3333
} catch (error) {
3434
// execFileSync will exit with the same code as the binary
3535
// If there's an error executing, exit with code 1
36-
process.exit(error.status || 1);
36+
process.exit(error.status ?? 1);
3737
}

test-scripts/test-npm-build.sh

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,86 @@ for dir in "${expected_dirs[@]}"; do
3838
fi
3939
done
4040

41-
# Verify binaries exist
42-
echo "Verifying binaries exist..."
43-
if [ ! -f "binaries/darwin-amd64/hookdeck" ]; then
44-
echo "Error: Missing binary: binaries/darwin-amd64/hookdeck"
45-
exit 1
46-
fi
47-
if [ ! -f "binaries/win32-amd64/hookdeck.exe" ]; then
48-
echo "Error: Missing binary: binaries/win32-amd64/hookdeck.exe"
49-
exit 1
50-
fi
41+
# Verify all binaries exist
42+
echo "Verifying all binaries exist..."
43+
expected_binaries=(
44+
"binaries/darwin-amd64/hookdeck"
45+
"binaries/darwin-arm64/hookdeck"
46+
"binaries/linux-amd64/hookdeck"
47+
"binaries/linux-arm64/hookdeck"
48+
"binaries/win32-amd64/hookdeck.exe"
49+
"binaries/win32-386/hookdeck.exe"
50+
)
51+
52+
for binary in "${expected_binaries[@]}"; do
53+
if [ ! -f "$binary" ]; then
54+
echo "Error: Missing binary: $binary"
55+
exit 1
56+
fi
57+
echo "✓ Found: $binary"
58+
done
59+
60+
# Verify binary architectures using 'file' command
61+
echo ""
62+
echo "Verifying binary architectures..."
63+
64+
verify_binary_arch() {
65+
local binary="$1"
66+
local expected_pattern="$2"
67+
local description="$3"
68+
69+
file_output=$(file "$binary")
70+
if echo "$file_output" | grep -q "$expected_pattern"; then
71+
echo "$description: $file_output"
72+
else
73+
echo "$description: Expected '$expected_pattern' but got:"
74+
echo " $file_output"
75+
exit 1
76+
fi
77+
}
78+
79+
# Darwin binaries
80+
verify_binary_arch "binaries/darwin-amd64/hookdeck" "Mach-O 64-bit.*x86_64" "darwin-amd64"
81+
verify_binary_arch "binaries/darwin-arm64/hookdeck" "Mach-O 64-bit.*arm64" "darwin-arm64"
82+
83+
# Linux binaries
84+
verify_binary_arch "binaries/linux-amd64/hookdeck" "ELF 64-bit.*x86-64" "linux-amd64"
85+
verify_binary_arch "binaries/linux-arm64/hookdeck" "ELF 64-bit.*ARM aarch64" "linux-arm64"
86+
87+
# Windows binaries - PE32 is 32-bit, PE32+ is 64-bit
88+
verify_binary_arch "binaries/win32-amd64/hookdeck.exe" "PE32+ executable.*x86-64" "win32-amd64 (64-bit)"
89+
verify_binary_arch "binaries/win32-386/hookdeck.exe" "PE32 executable.*Intel 80386" "win32-386 (32-bit)"
90+
91+
echo ""
92+
echo "✓ All binary architectures verified!"
5193

5294
# Test wrapper script on current platform
95+
echo ""
5396
echo "Testing wrapper script on current platform..."
5497
if node bin/hookdeck.js --version > /dev/null 2>&1; then
5598
echo "✓ Wrapper script works on $(uname -s)-$(uname -m)"
5699
else
57100
echo "⚠ Warning: Wrapper script test skipped (binary may not exist for this platform)"
58101
fi
59102

103+
# Test wrapper script exit code handling
104+
echo ""
105+
echo "Testing wrapper script exit code handling..."
106+
107+
# Test that wrapper propagates non-zero exit codes correctly
108+
# Run an invalid command that will cause the binary to exit with non-zero
109+
set +e # Temporarily disable exit on error
110+
node bin/hookdeck.js invalid-command-that-does-not-exist > /dev/null 2>&1
111+
EXIT_CODE=$?
112+
set -e # Re-enable exit on error
113+
114+
if [ $EXIT_CODE -ne 0 ]; then
115+
echo "✓ Wrapper script correctly propagates non-zero exit code ($EXIT_CODE)"
116+
else
117+
echo "✗ Wrapper script should have returned non-zero exit code for invalid command"
118+
exit 1
119+
fi
120+
60121
# Test npm pack
61122
echo "Testing npm pack..."
62123
npm pack --dry-run > /tmp/npm-pack-output.txt 2>&1

0 commit comments

Comments
 (0)