| 1 | # Releases the g1t CLI (crates/g1t): builds it for Linux and macOS on x64 |
| 2 | # and arm64 and for Windows on x64, signs the release, and publishes it to |
| 3 | # g1t.sh/downloads/cli/ (the g1t-downloads R2 bucket), where g1t.sh/install |
| 4 | # and g1t.sh/install.ps1 find it. |
| 5 | # |
| 6 | # A release is a tag `cli-v<version>`, where the version is the one in |
| 7 | # crates/g1t/Cargo.toml; or run it by hand. scripts/cli-release.mjs does the |
| 8 | # work, and its header says what a release holds. It is signed with the |
| 9 | # runner's release key (RUNNER_RELEASE_KEY, RUNNER_RELEASE_PUBLIC_KEY). |
| 10 | # |
| 11 | # Every platform builds in one job, in the rust-cross/cargo-zigbuild image, |
| 12 | # pinned by digest in scripts/cli-release.mjs: the macOS builds link Apple's |
| 13 | # Security framework (the keychain), and that image carries its SDK. It |
| 14 | # runs on g1t's own machines (g1t-4core), whose jobs have a Docker Engine of |
| 15 | # their own. |
| 16 | name: CLI release |
| 17 | |
| 18 | on: |
| 19 | push: |
| 20 | tags: ["cli-v*"] |
| 21 | workflow_dispatch: |
| 22 | |
| 23 | permissions: |
| 24 | contents: read |
| 25 | |
| 26 | concurrency: |
| 27 | group: cli-release |
| 28 | cancel-in-progress: false |
| 29 | |
| 30 | env: |
| 31 | CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} |
| 32 | WRANGLER_SEND_METRICS: "false" |
| 33 | |
| 34 | jobs: |
| 35 | build: |
| 36 | name: Build every platform |
| 37 | runs-on: g1t-4core |
| 38 | timeout-minutes: 60 |
| 39 | steps: |
| 40 | - uses: actions/checkout@v5 |
| 41 | - name: The tag names this version |
| 42 | if: startsWith(github.ref, 'refs/tags/cli-v') |
| 43 | run: | |
| 44 | version="$(sed -n 's/^version = "\(.*\)"/\1/p' crates/g1t/Cargo.toml | head -1)" |
| 45 | [ "cli-v$version" = "${GITHUB_REF_NAME}" ] || { echo "::error::The tag is ${GITHUB_REF_NAME}, but crates/g1t is $version"; exit 1; } |
| 46 | # zigbuild: the builder image's digest, whose Rust the build uses; |
| 47 | # cargo: Cargo.lock's crates.io and git packages, not the workspace's |
| 48 | # own versions (scripts/deploy/ci-cache.mjs). |
| 49 | - name: Cache keys |
| 50 | id: keys |
| 51 | run: node scripts/deploy/ci-cache.mjs keys |
| 52 | # Every crate the lockfile names, as CI's Rust job saves them on main. |
| 53 | # The builder reads them from this job's ~/.cargo/registry. |
| 54 | - name: Cache crates |
| 55 | uses: actions/cache/restore@v4 |
| 56 | with: |
| 57 | path: | |
| 58 | ~/.cargo/registry/index |
| 59 | ~/.cargo/registry/cache |
| 60 | key: cargo-crates-${{ runner.os }}-${{ steps.keys.outputs.cargo }} |
| 61 | restore-keys: cargo-crates-${{ runner.os }}- |
| 62 | # Every platform's build. A tag's run restores only from its own tag |
| 63 | # and from main, so the Caches workflow (caches.yml) builds and saves |
| 64 | # this on main whenever the key is new; a release compiles the CLI's |
| 65 | # own crates again, and saves nothing. |
| 66 | - name: Cache the CLI's build |
| 67 | uses: actions/cache/restore@v4 |
| 68 | with: |
| 69 | path: | |
| 70 | target/zig |
| 71 | !target/zig/**/incremental |
| 72 | key: cli-release-${{ runner.os }}-${{ steps.keys.outputs.zigbuild }}-${{ steps.keys.outputs.cargo }} |
| 73 | restore-keys: cli-release-${{ runner.os }}-${{ steps.keys.outputs.zigbuild }}- |
| 74 | - name: Build |
| 75 | run: node scripts/cli-release.mjs build |
| 76 | - uses: actions/upload-artifact@v4 |
| 77 | with: |
| 78 | name: cli |
| 79 | path: target/cli-release/ |
| 80 | overwrite: true |
| 81 | |
| 82 | publish: |
| 83 | name: Sign and publish |
| 84 | needs: build |
| 85 | runs-on: ubuntu-latest |
| 86 | # Production's secrets, without a deployment: a release is not a deploy |
| 87 | # of g1t.sh. |
| 88 | environment: |
| 89 | name: production |
| 90 | deployment: false |
| 91 | timeout-minutes: 30 |
| 92 | steps: |
| 93 | - uses: actions/checkout@v5 |
| 94 | - uses: actions/download-artifact@v4 |
| 95 | with: |
| 96 | name: cli |
| 97 | path: target/cli-release |
| 98 | - name: Sign |
| 99 | env: |
| 100 | RUNNER_RELEASE_KEY: ${{ secrets.RUNNER_RELEASE_KEY }} |
| 101 | G1T_RUNNER_RELEASE_KEY: ${{ vars.RUNNER_RELEASE_PUBLIC_KEY }} |
| 102 | run: | |
| 103 | node scripts/cli-release.mjs sign |
| 104 | node scripts/cli-release.mjs verify |
| 105 | - name: Cache npm's downloads |
| 106 | uses: actions/cache/restore@v4 |
| 107 | with: |
| 108 | path: ~/.npm |
| 109 | key: npm-full-${{ runner.os }}-${{ hashFiles('package-lock.json') }} |
| 110 | restore-keys: npm-full-${{ runner.os }}- |
| 111 | - name: Install Wrangler |
| 112 | run: node scripts/deploy/npm-ci.mjs --prefer-offline --workspaces=false --no-audit --no-fund |
| 113 | - name: Publish to g1t.sh/downloads/cli |
| 114 | env: |
| 115 | CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 116 | run: node scripts/cli-release.mjs publish |