Skip to content

Commit eda89ec

Browse files
committed
feat: add custom setup-zig composite action
Create .github/actions/setup-zig to install Zig compiler: - Supports Linux x86_64 and macOS (x86_64/aarch64) - Downloads from ziglang.org/builds (more reliable than /download) - Caches Zig installation between runs - Adds retry logic for network resilience - Verifies installation with zig version Benefits over third-party actions: - Full control over installation logic - No external dependencies - Can customize for our specific needs - Better error messages and debugging Fixes the curl error when downloading from /download endpoint.
1 parent 26afea6 commit eda89ec

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: 'Setup Zig'
2+
description: 'Install Zig compiler'
3+
inputs:
4+
version:
5+
description: 'Zig version to install'
6+
required: true
7+
default: '0.15.2'
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: Cache Zig
12+
uses: actions/cache@v4
13+
id: cache-zig
14+
with:
15+
path: |
16+
~/zig
17+
key: zig-${{ runner.os }}-${{ inputs.version }}
18+
19+
- name: Download and install Zig
20+
if: steps.cache-zig.outputs.cache-hit != 'true'
21+
shell: bash
22+
run: |
23+
set -e
24+
VERSION="${{ inputs.version }}"
25+
26+
# Determine platform
27+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
28+
PLATFORM="linux"
29+
ARCH="x86_64"
30+
elif [[ "$OSTYPE" == "darwin"* ]]; then
31+
PLATFORM="macos"
32+
if [[ "$(uname -m)" == "arm64" ]]; then
33+
ARCH="aarch64"
34+
else
35+
ARCH="x86_64"
36+
fi
37+
else
38+
echo "Unsupported OS: $OSTYPE"
39+
exit 1
40+
fi
41+
42+
# Download from ziglang.org index
43+
TARBALL="zig-${PLATFORM}-${ARCH}-${VERSION}.tar.xz"
44+
URL="https://ziglang.org/builds/zig-${PLATFORM}-${ARCH}-${VERSION}.tar.xz"
45+
46+
echo "Downloading Zig ${VERSION} for ${PLATFORM}-${ARCH}..."
47+
curl --retry 3 --retry-delay 5 -L -o "/tmp/${TARBALL}" "${URL}"
48+
49+
# Extract to home directory
50+
mkdir -p ~/zig
51+
tar -xf "/tmp/${TARBALL}" -C ~/zig --strip-components=1
52+
53+
echo "Zig ${VERSION} installed to ~/zig"
54+
55+
- name: Add Zig to PATH
56+
shell: bash
57+
run: |
58+
echo "$HOME/zig" >> $GITHUB_PATH
59+
60+
- name: Verify Zig installation
61+
shell: bash
62+
run: |
63+
zig version

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
with:
6868
bun-version: latest
6969

70-
- uses: mlugg/setup-zig@v1
70+
- uses: ./.github/actions/setup-zig
7171
with:
7272
version: 0.15.2
7373

@@ -92,7 +92,7 @@ jobs:
9292
with:
9393
bun-version: latest
9494

95-
- uses: mlugg/setup-zig@v1
95+
- uses: ./.github/actions/setup-zig
9696
with:
9797
version: 0.15.2
9898

0 commit comments

Comments
 (0)