Skip to content

Commit 698140d

Browse files
refactor(ci): single runner builds all targets via Zig cross-compile
- Remove matrix strategy - Zig cross-compiles for any platform from any - Build all 8 targets sequentially on one ubuntu runner - Simplify artifact handling (single binaries-all artifact) - Update assembly script to use artifacts/ directory
1 parent d93bd99 commit 698140d

File tree

2 files changed

+76
-81
lines changed

2 files changed

+76
-81
lines changed

.github/workflows/release.yml

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,59 @@ env:
1616

1717
jobs:
1818
build:
19-
name: Build binaries
19+
name: Build all binaries (Zig cross-compile)
2020
runs-on: ubuntu-latest
21-
strategy:
22-
fail-fast: false
23-
matrix:
24-
include:
25-
# Linux builds
26-
- target: x86_64-linux-gnu
27-
platform: linux-x64-gnu
28-
- target: x86_64-linux-musl
29-
platform: linux-x64-musl
30-
- target: aarch64-linux-gnu
31-
platform: linux-arm64-gnu
32-
- target: aarch64-linux-musl
33-
platform: linux-arm64-musl
34-
- target: arm-linux-gnueabihf
35-
platform: linux-arm-gnu
36-
- target: arm-linux-musleabihf
37-
platform: linux-arm-musl
38-
# macOS builds
39-
- target: x86_64-macos
40-
platform: darwin-x64
41-
- target: aarch64-macos
42-
platform: darwin-arm64
43-
# Windows - DISABLED: POSIX API usage needs fixing
44-
# - target: x86_64-windows
45-
# platform: win32-x64
46-
# i386 - DISABLED: Low priority, test after v1.0.0
47-
# - target: i386-linux-musl
48-
# platform: linux-i386-musl
4921
steps:
5022
- uses: actions/checkout@v4
5123

5224
- name: Install Zig
5325
uses: mlugg/setup-zig@v1
5426

55-
- name: Build ${{ matrix.platform }}
27+
- name: Build all platforms
5628
run: |
57-
zig build -Dtarget=${{ matrix.target }} -Doptimize=ReleaseSafe
58-
59-
- name: Package binary
60-
run: |
61-
mkdir -p release/${{ matrix.platform }}
62-
if [ "${{ matrix.platform }}" = "win32-x64" ]; then
63-
cp zig-out/bin/ansilust.exe release/${{ matrix.platform }}/
64-
else
65-
cp zig-out/bin/ansilust release/${{ matrix.platform }}/
66-
fi
29+
# Zig cross-compiles for any platform from any platform
30+
# No need for matrix - build everything on one runner
31+
32+
TARGETS=(
33+
"x86_64-linux-gnu:linux-x64-gnu"
34+
"x86_64-linux-musl:linux-x64-musl"
35+
"aarch64-linux-gnu:linux-arm64-gnu"
36+
"aarch64-linux-musl:linux-arm64-musl"
37+
"arm-linux-gnueabihf:linux-arm-gnu"
38+
"arm-linux-musleabihf:linux-arm-musl"
39+
"x86_64-macos:darwin-x64"
40+
"aarch64-macos:darwin-arm64"
41+
# Windows - DISABLED: POSIX API usage needs fixing
42+
# "x86_64-windows:win32-x64"
43+
# i386 - DISABLED: Low priority, test after v1.0.0
44+
# "i386-linux-musl:linux-i386-musl"
45+
)
46+
47+
for entry in "${TARGETS[@]}"; do
48+
IFS=':' read -r target platform <<< "$entry"
49+
echo "=== Building $platform (zig target: $target) ==="
50+
51+
zig build -Dtarget="$target" -Doptimize=ReleaseSafe
52+
53+
mkdir -p "release/$platform"
54+
if [[ "$platform" == win32* ]]; then
55+
cp zig-out/bin/ansilust.exe "release/$platform/"
56+
else
57+
cp zig-out/bin/ansilust "release/$platform/"
58+
fi
59+
60+
# Clean for next build
61+
rm -rf zig-out zig-cache
62+
done
63+
64+
echo "=== All builds complete ==="
65+
find release -type f
6766
6867
- name: Upload artifacts
6968
uses: actions/upload-artifact@v4
7069
with:
71-
name: binaries-${{ matrix.platform }}
72-
path: release/${{ matrix.platform }}/
70+
name: binaries-all
71+
path: release/
7372
retention-days: 1
7473

7574
assemble-npm:
@@ -84,27 +83,16 @@ jobs:
8483
with:
8584
node-version: '20'
8685

87-
- name: Download all artifacts
86+
- name: Download binaries artifact
8887
uses: actions/download-artifact@v4
8988
with:
89+
name: binaries-all
9090
path: artifacts/
9191

92-
- name: Organize binaries by platform
92+
- name: Show artifact structure
9393
run: |
94-
# Each artifact directory contains the binary for that platform
95-
# We need to organize them so the assembly script can find them
96-
for platform_dir in artifacts/binaries-*/; do
97-
platform=$(basename "$platform_dir" | sed 's/binaries-//')
98-
mkdir -p "platform-binaries/$platform"
99-
for binary in "$platform_dir"ansilust*; do
100-
if [ -f "$binary" ]; then
101-
echo "Found binary: $binary for platform: $platform"
102-
cp "$binary" "platform-binaries/$platform/"
103-
fi
104-
done
105-
done
106-
echo "Platform binaries organized:"
107-
find platform-binaries -type f
94+
echo "=== Artifact structure ==="
95+
find artifacts -type f
10896
10997
- name: Install dependencies
11098
run: npm install
@@ -187,38 +175,44 @@ jobs:
187175
steps:
188176
- uses: actions/checkout@v4
189177

190-
- name: Download all artifacts
178+
- name: Download binaries artifact
191179
uses: actions/download-artifact@v4
192180
with:
181+
name: binaries-all
193182
path: artifacts/
194183

195184
- name: Prepare release artifacts
196185
run: |
197186
mkdir -p release-artifacts
198187
199-
# Copy and organize binaries
200-
find artifacts -name "ansilust*" -type f | while read file; do
201-
platform=$(basename "$file" | sed 's/ansilust-//' | sed 's/.exe$//')
188+
# Iterate through platform directories
189+
for platform_dir in artifacts/*/; do
190+
platform=$(basename "$platform_dir")
191+
binary="$platform_dir/ansilust"
192+
binary_exe="$platform_dir/ansilust.exe"
202193
203-
if [[ "$platform" == "win32"* ]]; then
194+
if [[ -f "$binary_exe" ]]; then
204195
# Windows: create zip
205-
mkdir -p "temp/$platform/bin"
206-
cp "$file" "temp/$platform/bin/"
196+
mkdir -p "temp/ansilust-$platform"
197+
cp "$binary_exe" "temp/ansilust-$platform/"
207198
cd temp
208-
zip -r "../release-artifacts/ansilust-$platform.zip" "$platform/"
199+
zip -r "../release-artifacts/ansilust-$platform.zip" "ansilust-$platform/"
209200
cd ..
210201
rm -rf temp
211-
else
202+
elif [[ -f "$binary" ]]; then
212203
# Unix: create tar.gz
213-
mkdir -p "temp/$platform/bin"
214-
cp "$file" "temp/$platform/bin/ansilust"
215-
chmod +x "temp/$platform/bin/ansilust"
204+
mkdir -p "temp/ansilust-$platform"
205+
cp "$binary" "temp/ansilust-$platform/"
206+
chmod +x "temp/ansilust-$platform/ansilust"
216207
cd temp
217-
tar -czf "../release-artifacts/ansilust-$platform.tar.gz" "$platform/"
208+
tar -czf "../release-artifacts/ansilust-$platform.tar.gz" "ansilust-$platform/"
218209
cd ..
219210
rm -rf temp
220211
fi
221212
done
213+
214+
echo "=== Release artifacts ==="
215+
ls -la release-artifacts/
222216
223217
- name: Generate checksums
224218
run: bash scripts/generate-checksums.sh release-artifacts/
@@ -287,9 +281,10 @@ jobs:
287281
steps:
288282
- uses: actions/checkout@v4
289283

290-
- name: Download all artifacts
284+
- name: Download binaries artifact
291285
uses: actions/download-artifact@v4
292286
with:
287+
name: binaries-all
293288
path: artifacts/
294289

295290
- name: Set up Docker Buildx

scripts/assemble-npm-packages.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ const PLATFORM_TO_DIR = {
132132
// Main assembly function
133133
function assemble() {
134134
const rootDir = path.join(__dirname, '..');
135-
// Support both local builds (zig-out/bin/) and CI builds (platform-binaries/{platform}/)
135+
// Support both local builds (zig-out/bin/) and CI builds (artifacts/{platform}/)
136136
const localBinDir = path.join(rootDir, 'zig-out', 'bin');
137-
const platformBinDir = path.join(rootDir, 'platform-binaries');
137+
const artifactsDir = path.join(rootDir, 'artifacts');
138138
const packagesDir = path.join(rootDir, 'packages');
139139
const licenseFile = path.join(rootDir, 'LICENSE');
140140

141-
// Detect if we're in CI mode (platform-binaries exists) or local mode
142-
const isCI = fs.existsSync(platformBinDir);
143-
console.log(`Mode: ${isCI ? 'CI (platform-binaries)' : 'Local (zig-out/bin)'}`);
141+
// Detect if we're in CI mode (artifacts exists) or local mode
142+
const isCI = fs.existsSync(artifactsDir);
143+
console.log(`Mode: ${isCI ? 'CI (artifacts/)' : 'Local (zig-out/bin)'}`);
144144

145145
// Get version from environment or package.json
146146
let version = process.env.PACKAGE_VERSION || '0.0.1';
@@ -153,7 +153,7 @@ function assemble() {
153153
console.warn('Warning: Could not read root package.json, using version', version);
154154
}
155155

156-
console.log(`📦 Assembling ansilust npm packages (v${version})`);
156+
console.log(`Assembling ansilust npm packages (v${version})`);
157157
console.log('');
158158

159159
let successCount = 0;
@@ -165,10 +165,10 @@ function assemble() {
165165
if (isCI) {
166166
const platformDir = PLATFORM_TO_DIR[packageName];
167167
if (!platformDir) {
168-
console.log(`⏭️ Skipping ${packageName} (no platform directory mapping)`);
168+
console.log(` Skipping ${packageName} (no platform directory mapping)`);
169169
continue;
170170
}
171-
binaryPath = path.join(platformBinDir, platformDir, 'ansilust');
171+
binaryPath = path.join(artifactsDir, platformDir, 'ansilust');
172172
} else {
173173
binaryPath = path.join(localBinDir, 'ansilust');
174174
}
@@ -180,7 +180,7 @@ function assemble() {
180180
// Check if binary exists
181181
if (!fs.existsSync(binaryPath)) {
182182
// For cross-compilation targets, the binary might not exist if not built
183-
console.log(`⏭️ Skipping ${packageName} (binary not found for ${zigTarget})`);
183+
console.log(` Skipping ${packageName} (binary not found for ${zigTarget})`);
184184
continue;
185185
}
186186

0 commit comments

Comments
 (0)