|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to release (e.g. 0.1.0). Creates tag vX.Y.Z if needed." |
| 11 | + required: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-tarballs: |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - runner: ubuntu-latest |
| 23 | + target: x86_64-linux-musl |
| 24 | + dist_os: linux |
| 25 | + dist_arch: amd64 |
| 26 | + - runner: ubuntu-latest |
| 27 | + target: aarch64-linux-musl |
| 28 | + dist_os: linux |
| 29 | + dist_arch: arm64 |
| 30 | + - runner: macos-latest |
| 31 | + target: x86_64-macos |
| 32 | + dist_os: darwin |
| 33 | + dist_arch: amd64 |
| 34 | + - runner: macos-latest |
| 35 | + target: aarch64-macos |
| 36 | + dist_os: darwin |
| 37 | + dist_arch: arm64 |
| 38 | + |
| 39 | + runs-on: ${{ matrix.runner }} |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + - uses: goto-bus-stop/setup-zig@v2 |
| 43 | + with: |
| 44 | + version: 0.15.1 |
| 45 | + |
| 46 | + - name: Resolve version |
| 47 | + id: meta |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | + raw="${{ github.event.inputs.version || github.ref_name }}" |
| 52 | + if [[ "$raw" != v* ]]; then tag="v$raw"; else tag="$raw"; fi |
| 53 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 54 | + echo "version=${tag#v}" >> "$GITHUB_OUTPUT" |
| 55 | +
|
| 56 | + - name: Build tarball |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + version="${{ steps.meta.outputs.version }}" |
| 61 | + zig build -Doptimize=ReleaseSafe -Dtarget=${{ matrix.target }} -Dversion="${version}" |
| 62 | +
|
| 63 | + mkdir -p dist |
| 64 | + cp zig-out/bin/nytgames dist/nytgames |
| 65 | + cp LICENSE dist/LICENSE |
| 66 | + cp README.md dist/README.md |
| 67 | +
|
| 68 | + tarball="nytgames-cli_${version}_${{ matrix.dist_os }}_${{ matrix.dist_arch }}.tar.gz" |
| 69 | + tar -C dist -czf "${tarball}" nytgames LICENSE README.md |
| 70 | + echo "built ${tarball}" |
| 71 | +
|
| 72 | + - uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: tarballs-${{ matrix.dist_os }}-${{ matrix.dist_arch }} |
| 75 | + path: nytgames-cli_*.tar.gz |
| 76 | + if-no-files-found: error |
| 77 | + |
| 78 | + publish: |
| 79 | + needs: build-tarballs |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + path: dist |
| 87 | + pattern: tarballs-* |
| 88 | + merge-multiple: true |
| 89 | + |
| 90 | + - name: Resolve version |
| 91 | + id: meta |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + set -euo pipefail |
| 95 | + raw="${{ github.event.inputs.version || github.ref_name }}" |
| 96 | + if [[ "$raw" != v* ]]; then tag="v$raw"; else tag="$raw"; fi |
| 97 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 98 | + echo "version=${tag#v}" >> "$GITHUB_OUTPUT" |
| 99 | +
|
| 100 | + - name: Build Linux packages + Homebrew formula |
| 101 | + shell: bash |
| 102 | + run: | |
| 103 | + set -euo pipefail |
| 104 | + version="${{ steps.meta.outputs.version }}" |
| 105 | +
|
| 106 | + ls -la dist |
| 107 | +
|
| 108 | + # Initial checksums (tarballs only) used for generating the brew formula. |
| 109 | + (cd dist && sha256sum nytgames-cli_*.tar.gz > checksums.txt) |
| 110 | +
|
| 111 | + ./scripts/generate-homebrew-formula.sh --version "${version}" --checksums dist/checksums.txt --out dist/nytgames-cli.rb |
| 112 | +
|
| 113 | + sudo apt-get update -y |
| 114 | + sudo apt-get install -y rpm |
| 115 | +
|
| 116 | + mkdir -p dist/_linux_amd64 dist/_linux_arm64 |
| 117 | +
|
| 118 | + tar -xzf "dist/nytgames-cli_${version}_linux_amd64.tar.gz" -C dist/_linux_amd64 |
| 119 | + tar -xzf "dist/nytgames-cli_${version}_linux_arm64.tar.gz" -C dist/_linux_arm64 |
| 120 | +
|
| 121 | + ./scripts/build-deb.sh --version "${version}" --arch amd64 --bin dist/_linux_amd64/nytgames --out "dist/nytgames-cli_${version}_linux_amd64.deb" |
| 122 | + ./scripts/build-deb.sh --version "${version}" --arch arm64 --bin dist/_linux_arm64/nytgames --out "dist/nytgames-cli_${version}_linux_arm64.deb" |
| 123 | +
|
| 124 | + ./scripts/build-rpm.sh --version "${version}" --arch amd64 --tar "dist/nytgames-cli_${version}_linux_amd64.tar.gz" --out "dist/nytgames-cli_${version}_linux_amd64.rpm" |
| 125 | + ./scripts/build-rpm.sh --version "${version}" --arch arm64 --tar "dist/nytgames-cli_${version}_linux_arm64.tar.gz" --out "dist/nytgames-cli_${version}_linux_arm64.rpm" |
| 126 | +
|
| 127 | + # Final checksums include all artifacts (excluding checksums.txt itself). |
| 128 | + (cd dist && sha256sum nytgames-cli_*.tar.gz nytgames-cli_*.deb nytgames-cli_*.rpm nytgames-cli.rb > checksums.txt) |
| 129 | +
|
| 130 | + - name: Upload release assets |
| 131 | + uses: softprops/action-gh-release@v2 |
| 132 | + with: |
| 133 | + tag_name: ${{ steps.meta.outputs.tag }} |
| 134 | + target_commitish: ${{ github.sha }} |
| 135 | + generate_release_notes: true |
| 136 | + files: | |
| 137 | + dist/nytgames-cli_*.tar.gz |
| 138 | + dist/nytgames-cli_*.deb |
| 139 | + dist/nytgames-cli_*.rpm |
| 140 | + dist/nytgames-cli.rb |
| 141 | + dist/checksums.txt |
0 commit comments