|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Cut a release by pushing a vX.Y.Z tag (after the version-bump PR merges). |
| 4 | +# Builds the arm64 macOS bottle, publishes it to the tag's GitHub Release, and |
| 5 | +# opens a formula PR (url + sha256 + bottle block) for a maintainer to merge. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: ["v*"] |
| 9 | + # Manual dry-run: build the bottle for an existing tag WITHOUT publishing. |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + tag: |
| 13 | + description: "Existing tag to build a bottle for (dry-run; no publish)" |
| 14 | + required: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + bottle: |
| 25 | + name: build arm64 bottle (macOS) |
| 26 | + runs-on: macos-14 |
| 27 | + timeout-minutes: 40 |
| 28 | + permissions: |
| 29 | + contents: read |
| 30 | + outputs: |
| 31 | + tag: ${{ steps.meta.outputs.tag }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 34 | + with: |
| 35 | + persist-credentials: false # this job doesn't push |
| 36 | + # Homebrew/actions is a monorepo (setup-homebrew is a subpath); pin it to a |
| 37 | + # commit SHA like every other action here — Dependabot keeps it current. |
| 38 | + - uses: Homebrew/actions/setup-homebrew@2ebcf16054461267868620b1414507f3ccc765c1 |
| 39 | + |
| 40 | + - name: Resolve tag + source sha256 |
| 41 | + id: meta |
| 42 | + env: |
| 43 | + # Pass via env (not inline ${{ }}) to satisfy zizmor template-injection. |
| 44 | + INPUT_TAG: ${{ github.event.inputs.tag }} |
| 45 | + REF_NAME: ${{ github.ref_name }} |
| 46 | + REPO: ${{ github.repository }} |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + tag="${INPUT_TAG:-$REF_NAME}" |
| 50 | + url="https://github.com/${REPO}/archive/refs/tags/${tag}.tar.gz" |
| 51 | + curl -fL "$url" -o source.tar.gz |
| 52 | + sha="$(shasum -a 256 source.tar.gz | awk '{print $1}')" |
| 53 | + { |
| 54 | + echo "tag=${tag}" |
| 55 | + echo "source_sha=${sha}" |
| 56 | + echo "root_url=https://github.com/${REPO}/releases/download/${tag}" |
| 57 | + } >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Pin the formula to the release tag |
| 60 | + env: |
| 61 | + TAG: ${{ steps.meta.outputs.tag }} |
| 62 | + SOURCE_SHA: ${{ steps.meta.outputs.source_sha }} |
| 63 | + REPO: ${{ github.repository }} |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + python3 - <<'PY' |
| 67 | + import os, re, pathlib |
| 68 | + tag, sha, repo = os.environ["TAG"], os.environ["SOURCE_SHA"], os.environ["REPO"] |
| 69 | + url = f"https://github.com/{repo}/archive/refs/tags/{tag}.tar.gz" |
| 70 | + p = pathlib.Path("Formula/assembly.rb") |
| 71 | + src = p.read_text() |
| 72 | + src = re.sub(r'url ".*?"', f'url "{url}"', src, count=1) |
| 73 | + src = re.sub(r"sha256 .*", f'sha256 "{sha}"', src, count=1) |
| 74 | + p.write_text(src) |
| 75 | + PY |
| 76 | + grep -nE '^ (url|sha256) ' Formula/assembly.rb | head -2 |
| 77 | +
|
| 78 | + - name: Build the bottle + merge the block into the formula |
| 79 | + env: |
| 80 | + ROOT_URL: ${{ steps.meta.outputs.root_url }} |
| 81 | + run: | |
| 82 | + set -euo pipefail |
| 83 | + brew tap-new --no-git assembly/local |
| 84 | + tap_formula="$(brew --repository assembly/local)/Formula/assembly.rb" |
| 85 | + cp Formula/assembly.rb "$tap_formula" |
| 86 | + brew install --build-bottle --formula assembly/local/assembly |
| 87 | + brew bottle --json --no-rebuild --root-url="$ROOT_URL" assembly/local/assembly |
| 88 | + for f in assembly--*.bottle.tar.gz; do mv "$f" "${f/--/-}"; done |
| 89 | + shopt -s nullglob |
| 90 | + tarballs=( assembly-*.bottle.tar.gz ) |
| 91 | + shopt -u nullglob |
| 92 | + if [[ ${#tarballs[@]} -ne 1 ]]; then |
| 93 | + echo "Expected exactly one bottle tarball, found ${#tarballs[@]}: ${tarballs[*]:-none}" >&2 |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + brew bottle --merge --write --no-commit assembly--*.bottle.json |
| 97 | + cp "$tap_formula" Formula/assembly.rb |
| 98 | + echo "--- finalized formula head ---" |
| 99 | + sed -n '1,20p' Formula/assembly.rb |
| 100 | +
|
| 101 | + - name: Upload bottle + finalized formula |
| 102 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 103 | + with: |
| 104 | + name: release-artifacts |
| 105 | + path: | |
| 106 | + assembly-*.bottle.tar.gz |
| 107 | + Formula/assembly.rb |
| 108 | + if-no-files-found: error |
| 109 | + |
| 110 | + publish: |
| 111 | + name: publish release + open formula PR |
| 112 | + needs: [bottle] |
| 113 | + if: github.event_name == 'push' |
| 114 | + runs-on: ubuntu-latest |
| 115 | + timeout-minutes: 10 |
| 116 | + permissions: |
| 117 | + contents: write |
| 118 | + pull-requests: write |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 121 | + with: |
| 122 | + persist-credentials: false # push via explicit tokened remote instead |
| 123 | + |
| 124 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 |
| 125 | + with: |
| 126 | + name: release-artifacts |
| 127 | + path: artifacts |
| 128 | + |
| 129 | + - name: Create the GitHub Release with the bottle attached |
| 130 | + env: |
| 131 | + GH_TOKEN: ${{ github.token }} |
| 132 | + TAG: ${{ needs.bottle.outputs.tag }} |
| 133 | + run: | |
| 134 | + set -euo pipefail |
| 135 | + if ! gh release view "$TAG" >/dev/null 2>&1; then |
| 136 | + gh release create "$TAG" --title "$TAG" --generate-notes |
| 137 | + fi |
| 138 | + gh release upload "$TAG" artifacts/assembly-*.bottle.tar.gz --clobber |
| 139 | +
|
| 140 | + - name: Open the formula PR |
| 141 | + env: |
| 142 | + GH_TOKEN: ${{ github.token }} |
| 143 | + TAG: ${{ needs.bottle.outputs.tag }} |
| 144 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 145 | + run: | |
| 146 | + set -euo pipefail |
| 147 | + branch="release/${TAG}-formula" |
| 148 | + cp artifacts/Formula/assembly.rb Formula/assembly.rb |
| 149 | + git config user.name "github-actions[bot]" |
| 150 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 151 | + git checkout -B "$branch" |
| 152 | + git add Formula/assembly.rb |
| 153 | + git commit -m "Bottle ${TAG}: pin url + sha256, add arm64_sonoma bottle" |
| 154 | + git push --force "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$branch" |
| 155 | + if ! gh pr view "$branch" >/dev/null 2>&1; then |
| 156 | + gh pr create --base main --head "$branch" \ |
| 157 | + --title "Bottle ${TAG}" \ |
| 158 | + --body "Automated by release.yml: pins the formula to the ${TAG} source tarball and adds the arm64_sonoma bottle block. Merge with the admin override (a GITHUB_TOKEN PR does not trigger CI, so the required check will not report). The diff is formula-only." |
| 159 | + fi |
0 commit comments