Repository navigation
v2.8.0 #8
Workflow file for this run
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: Bump Homebrew Formula | |
| # Points Formula/claude-code-zsh-completion.rb at a newly published release and | |
| # opens a PR with the new url and checksum. main is protected, so this cannot | |
| # push the change directly; the PR is set to auto-merge once `test` passes. | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag to point the formula at (e.g. v2.4.0)' | |
| required: true | |
| merge: | |
| description: 'Turn on auto-merge for the PR (off to test this workflow)' | |
| type: boolean | |
| default: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| bump: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: main | |
| - name: Work out the release and its checksum | |
| id: release | |
| env: | |
| TAG: ${{ github.event.release.tag_name || inputs.tag }} | |
| run: | | |
| url="https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${TAG}.tar.gz" | |
| curl -fsSL -o release.tar.gz "$url" | |
| sha=$(sha256sum release.tar.gz | cut -d' ' -f1) | |
| rm release.tar.gz | |
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | |
| echo "url=${url}" >> "$GITHUB_OUTPUT" | |
| echo "sha=${sha}" >> "$GITHUB_OUTPUT" | |
| - name: Update the formula | |
| id: update | |
| env: | |
| URL: ${{ steps.release.outputs.url }} | |
| SHA: ${{ steps.release.outputs.sha }} | |
| run: | | |
| formula=Formula/claude-code-zsh-completion.rb | |
| sed -i -E "s|^ url \".*\"| url \"${URL}\"|" "$formula" | |
| sed -i -E "s|^ sha256 \".*\"| sha256 \"${SHA}\"|" "$formula" | |
| if git diff --quiet -- "$formula"; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Formula already points at this release" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| git diff -- "$formula" | |
| fi | |
| - name: Open the bump PR | |
| if: steps.update.outputs.changed == 'true' | |
| env: | |
| # A PR opened with the workflow token gets its CI held for approval, so | |
| # open it as the maintainer (fine-grained token: this repo, contents and | |
| # pull requests). The push below still uses the workflow token. | |
| GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN || github.token }} | |
| MERGE: ${{ github.event_name == 'release' || inputs.merge }} | |
| TAG: ${{ steps.release.outputs.tag }} | |
| SHA: ${{ steps.release.outputs.sha }} | |
| run: | | |
| branch="chore/formula-${TAG}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git switch -c "$branch" | |
| git commit -qam "Point Homebrew formula at ${TAG}" | |
| git push -q -u origin "$branch" | |
| gh pr create \ | |
| --base main \ | |
| --head "$branch" \ | |
| --title "Point Homebrew formula at ${TAG}" \ | |
| --body "$(printf 'Automated bump after the %s release.\n\n- Checksum: `%s`\n\nMerging this makes `brew upgrade` pick up %s.\n' "$TAG" "$SHA" "$TAG")" | |
| if [ "$MERGE" = "true" ]; then | |
| gh pr merge "$branch" --auto --squash --delete-branch | |
| fi |