|
| 1 | +name: Release binaries |
| 2 | + |
| 3 | +# On a version tag (v*), cross-compile the ponytail Zig runtime binaries for |
| 4 | +# every supported platform, generate SHA-256 checksums, and attach them to the |
| 5 | +# GitHub Release. install.sh downloads the right per-platform archive and |
| 6 | +# SHA-256-verifies it (R6.2) — no Node, no Zig toolchain required by end users. |
| 7 | +# |
| 8 | +# Mirrors caveman's release-binaries.yml, minus the caveman/ponytail tool matrix |
| 9 | +# (ponytail's build only produces the `ponytail` tool) and minus the `*-claw` |
| 10 | +# exclude (ponytail has no claw test binary). |
| 11 | +# |
| 12 | +# Windows is deferred (R6-Windows: stdio/subprocess/argv libc → std.Io). The PS1 |
| 13 | +# shim covers Windows until then, so this workflow ships macOS + Linux only. |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + tags: ["v*"] |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + tag: |
| 21 | + description: "Tag to build (for manual re-runs), e.g. v1.2.3" |
| 22 | + required: true |
| 23 | + |
| 24 | +# No workflow-level write scope — each job requests only the permissions it needs |
| 25 | +# (least privilege). The build and checksums jobs both opt into contents: write |
| 26 | +# locally because they attach assets to the Release. |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + |
| 30 | +jobs: |
| 31 | + build: |
| 32 | + runs-on: [self-hosted, linux] |
| 33 | + permissions: |
| 34 | + contents: write # this job attaches assets to the Release |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + target: |
| 39 | + - { triple: aarch64-macos, name: macos-arm64 } |
| 40 | + - { triple: x86_64-macos, name: macos-x64 } |
| 41 | + - { triple: x86_64-linux-gnu, name: linux-x64 } |
| 42 | + - { triple: aarch64-linux-gnu, name: linux-arm64 } |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + # Resolve + validate the tag once, before any use. A manual workflow_dispatch |
| 47 | + # `tag` input is attacker-influenced free text that flows into shell commands |
| 48 | + # and the gh CLI; constrain it to the v<semver> shape this workflow ships so a |
| 49 | + # crafted value (spaces, $(...), ;, ../) can't smuggle anything downstream. |
| 50 | + - name: Resolve and validate release tag |
| 51 | + id: tag |
| 52 | + env: |
| 53 | + RAW_TAG: ${{ github.event.inputs.tag || github.ref_name }} |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + if [[ ! "$RAW_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then |
| 57 | + echo "::error::Refusing to build: tag '$RAW_TAG' is not a v<semver> tag" >&2 |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + echo "tag=$RAW_TAG" >> "$GITHUB_OUTPUT" |
| 61 | +
|
| 62 | + - name: Cross-compile ponytail for ${{ matrix.target.triple }} |
| 63 | + run: | |
| 64 | + nix develop --command bash -c "cd zig && zig build -Dtool=ponytail -Dtarget=${{ matrix.target.triple }} -Doptimize=ReleaseSafe" |
| 65 | +
|
| 66 | + - name: Package archive + checksum |
| 67 | + id: pkg |
| 68 | + env: |
| 69 | + PLAT: ${{ matrix.target.name }} |
| 70 | + run: | |
| 71 | + set -euo pipefail |
| 72 | + stage="dist/ponytail-$PLAT" |
| 73 | + mkdir -p "$stage" |
| 74 | +
|
| 75 | + # The full set of runtime binaries this release must ship. If the build |
| 76 | + # silently dropped one (e.g. a build.zig regression), packaging an |
| 77 | + # incomplete archive would ship a broken release that install.sh / the |
| 78 | + # launcher can't resolve — so assert every expected binary is present |
| 79 | + # BEFORE we tar anything. |
| 80 | + expected=(ponytail-activate ponytail-hook ponytail-instructions ponytail-mcp ponytail-statusline) |
| 81 | + for name in "${expected[@]}"; do |
| 82 | + if [[ ! -x "zig/zig-out/bin/$name" ]]; then |
| 83 | + echo "::error::Missing expected runtime binary: zig/zig-out/bin/$name" >&2 |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + done |
| 87 | +
|
| 88 | + # Ship the runtime binaries only; defensively skip any .pdb. |
| 89 | + for f in zig/zig-out/bin/ponytail-*; do |
| 90 | + base="$(basename "$f")" |
| 91 | + case "$base" in *.pdb) continue;; esac |
| 92 | + cp "$f" "$stage/" |
| 93 | + done |
| 94 | +
|
| 95 | + archive="ponytail-$PLAT.tar.gz" |
| 96 | + tar -C "$stage" -czf "dist/$archive" . |
| 97 | + ( cd dist && sha256sum "$archive" > "$archive.sha256" ) |
| 98 | + echo "archive=dist/$archive" >> "$GITHUB_OUTPUT" |
| 99 | + echo "checksum=dist/$archive.sha256" >> "$GITHUB_OUTPUT" |
| 100 | +
|
| 101 | + - name: Upload to Release |
| 102 | + uses: softprops/action-gh-release@v2 |
| 103 | + with: |
| 104 | + tag_name: ${{ steps.tag.outputs.tag }} |
| 105 | + files: | |
| 106 | + ${{ steps.pkg.outputs.archive }} |
| 107 | + ${{ steps.pkg.outputs.checksum }} |
| 108 | + fail_on_unmatched_files: true |
| 109 | + |
| 110 | + # Aggregate a single SHA256SUMS manifest across all archives (install.sh reads |
| 111 | + # the per-archive .sha256 sidecar; this manifest is for humans + auditing). |
| 112 | + checksums: |
| 113 | + needs: build |
| 114 | + runs-on: [self-hosted, linux] |
| 115 | + permissions: |
| 116 | + contents: write # this job uploads the aggregate manifest to the Release |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Resolve and validate release tag |
| 121 | + id: tag |
| 122 | + env: |
| 123 | + RAW_TAG: ${{ github.event.inputs.tag || github.ref_name }} |
| 124 | + run: | |
| 125 | + set -euo pipefail |
| 126 | + if [[ ! "$RAW_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then |
| 127 | + echo "::error::Refusing to publish: tag '$RAW_TAG' is not a v<semver> tag" >&2 |
| 128 | + exit 1 |
| 129 | + fi |
| 130 | + echo "tag=$RAW_TAG" >> "$GITHUB_OUTPUT" |
| 131 | +
|
| 132 | + - name: Collect per-archive checksums into SHA256SUMS |
| 133 | + env: |
| 134 | + TAG: ${{ steps.tag.outputs.tag }} |
| 135 | + GH_TOKEN: ${{ github.token }} |
| 136 | + REPO: ${{ github.repository }} |
| 137 | + run: | |
| 138 | + set -euo pipefail |
| 139 | + mkdir -p dist |
| 140 | + gh release download "$TAG" --pattern '*.sha256' --dir dist --repo "$REPO" |
| 141 | +
|
| 142 | + # Refuse to publish an empty manifest: if no per-archive .sha256 sidecars |
| 143 | + # were downloaded, the build job produced nothing and uploading an empty |
| 144 | + # SHA256SUMS would advertise a release with no verifiable artifacts. |
| 145 | + shopt -s nullglob |
| 146 | + sidecars=(dist/*.sha256) |
| 147 | + if (( ${#sidecars[@]} == 0 )); then |
| 148 | + echo "::error::No per-archive .sha256 sidecars found for $TAG — refusing to publish an empty SHA256SUMS" >&2 |
| 149 | + exit 1 |
| 150 | + fi |
| 151 | +
|
| 152 | + cat "${sidecars[@]}" > dist/SHA256SUMS |
| 153 | + if [[ ! -s dist/SHA256SUMS ]]; then |
| 154 | + echo "::error::SHA256SUMS is empty after aggregation — refusing to publish" >&2 |
| 155 | + exit 1 |
| 156 | + fi |
| 157 | +
|
| 158 | + gh release upload "$TAG" dist/SHA256SUMS --clobber --repo "$REPO" |
0 commit comments