Release #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' # Daily at 02:00 UTC | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: 'Force release even if already published' | |
| type: boolean | |
| default: false | |
| zig_version: | |
| description: 'Zig version (default: master)' | |
| type: string | |
| default: '' | |
| npm_version: | |
| description: 'npm version (default: zig version)' | |
| type: string | |
| default: '' | |
| tag_name: | |
| description: 'npm dist-tag (default: master)' | |
| type: string | |
| default: 'master' | |
| jobs: | |
| check: | |
| name: Discover | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_version: ${{ steps.compare.outputs.new_version }} | |
| upstream_version: ${{ steps.compare.outputs.upstream_version }} | |
| npm_version: ${{ steps.compare.outputs.npm_version }} | |
| tag_name: ${{ steps.compare.outputs.tag_name }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Compare versions | |
| id: compare | |
| run: | | |
| OVERRIDE_ZIG_VER="${{ github.event.inputs.zig_version }}" | |
| OVERRIDE_NPM_VER="${{ github.event.inputs.npm_version }}" | |
| TAG_NAME="${{ github.event.inputs.tag_name }}" | |
| TAG_NAME="${TAG_NAME:-master}" | |
| # Resolve upstream Zig version | |
| if [ -n "$OVERRIDE_ZIG_VER" ]; then | |
| UPSTREAM_VER="$OVERRIDE_ZIG_VER" | |
| echo "Using overridden Zig version: $UPSTREAM_VER" | |
| else | |
| curl -fsSL https://ziglang.org/download/index.json -o /tmp/upstream-index.json | |
| UPSTREAM_VER=$(node -p "require('/tmp/upstream-index.json').master.version") | |
| fi | |
| # Resolve npm version (strip build hash unless overridden) | |
| if [ -n "$OVERRIDE_NPM_VER" ]; then | |
| NPM_VER="$OVERRIDE_NPM_VER" | |
| echo "Using overridden npm version: $NPM_VER" | |
| else | |
| # npm doesn't allow '+' in versions — strip the build hash | |
| NPM_VER=$(echo "$UPSTREAM_VER" | sed 's/+.*//') | |
| fi | |
| # Check what's currently published on npm for the @zigc/cli package | |
| PUBLISHED_VER=$(npm view @zigc/cli dist-tags.master 2>/dev/null || echo "none") | |
| echo "Upstream : $UPSTREAM_VER" | |
| echo "Published: $PUBLISHED_VER" | |
| echo "npm ver : $NPM_VER" | |
| echo "tag : $TAG_NAME" | |
| echo "upstream_version=$UPSTREAM_VER" >> "$GITHUB_OUTPUT" | |
| echo "npm_version=$NPM_VER" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| FORCE="${{ github.event.inputs.force }}" | |
| if [ "$NPM_VER" != "$PUBLISHED_VER" ] || [ "$FORCE" = "true" ]; then | |
| echo "new_version=true" >> "$GITHUB_OUTPUT" | |
| echo "New version detected (or force=true)." | |
| else | |
| echo "new_version=false" >> "$GITHUB_OUTPUT" | |
| echo "No new version — skipping release." | |
| fi | |
| prepare: | |
| name: Prepare | |
| needs: check | |
| if: needs.check.outputs.new_version == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| - name: Install minisign | |
| run: | | |
| sudo apt-get update -q | |
| sudo apt-get install -y minisign | |
| - name: Prepare workspace and download binaries | |
| run: | | |
| NPM_VER="${{ needs.check.outputs.npm_version }}" | |
| node -e " | |
| const fs = require('fs'); | |
| const p = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| p.version = '$NPM_VER'; | |
| fs.writeFileSync('package.json', JSON.stringify(p, null, 2) + '\n'); | |
| " | |
| bash prepare.sh | |
| env: | |
| ZIG_UPSTREAM_VERSION: ${{ needs.check.outputs.upstream_version }} | |
| - name: Upload prepared workspace | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: prepared-workspace | |
| path: | | |
| package.json | |
| lib/ | |
| cli/ | |
| darwin-arm64/ | |
| darwin-x64/ | |
| linux-x64/ | |
| linux-arm64/ | |
| win32-x64/ | |
| win32-arm64/ | |
| retention-days: 1 | |
| smoke-test: | |
| name: Test (${{ matrix.os }}) | |
| needs: [check, prepare] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| - name: Download prepared workspace | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prepared-workspace | |
| - name: Restore binary permissions | |
| if: runner.os != 'Windows' | |
| run: chmod +x linux-x64/bin/zig linux-arm64/bin/zig darwin-arm64/bin/zig darwin-x64/bin/zig | |
| - name: Run smoke tests | |
| shell: bash | |
| env: | |
| CI: true | |
| run: bash check.sh "${{ needs.check.outputs.npm_version }}" "${{ needs.check.outputs.upstream_version }}" | |
| publish: | |
| name: Publish | |
| needs: [check, smoke-test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| registry-url: https://registry.npmjs.org | |
| - name: Download prepared workspace | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prepared-workspace | |
| - name: Restore binary permissions | |
| run: chmod +x linux-x64/bin/zig linux-arm64/bin/zig darwin-arm64/bin/zig darwin-x64/bin/zig | |
| - name: Publish to npm | |
| run: | | |
| npm publish --workspaces --access public --provenance --tag ${{ needs.check.outputs.tag_name }} 2>&1 | tee /tmp/npm-publish.log | |
| EXIT_CODE=${PIPESTATUS[0]} | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| if grep -q "already exists\|previously published" /tmp/npm-publish.log; then | |
| echo "Version already published — skipping." | |
| else | |
| exit $EXIT_CODE | |
| fi | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: "" |