Skip to content

Commit c691279

Browse files
authored
Merge pull request #16 from Bandwidth/scripted-formula-bump
ci: script the Homebrew formula bump (replace mislav action)
2 parents 772f940 + 1d9cbf9 commit c691279

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,40 @@ jobs:
8787
runs-on: ubuntu-latest
8888
steps:
8989
- name: Bump Homebrew formula
90-
uses: mislav/bump-homebrew-formula-action@v3
91-
with:
92-
formula-name: band
93-
formula-path: Formula/band.rb
94-
homebrew-tap: Bandwidth/homebrew-tap
95-
base-branch: main
96-
download-url: https://github.com/Bandwidth/cli/archive/refs/tags/${{ github.ref_name }}.tar.gz
97-
commit-message: |
98-
{{formulaName}} {{version}}
9990
env:
100-
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
91+
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
92+
VERSION: ${{ github.ref_name }}
93+
run: |
94+
set -euo pipefail
95+
96+
TAP="Bandwidth/homebrew-tap"
97+
FORMULA="Formula/band.rb"
98+
URL="https://github.com/Bandwidth/cli/archive/refs/tags/${VERSION}.tar.gz"
99+
100+
# Checksum the exact archive brew downloads: curl follows GitHub's redirect
101+
# to codeload, so this sha256 always matches the formula url's payload.
102+
SHA="$(curl -fsSL "$URL" | sha256sum | cut -d' ' -f1)"
103+
104+
git clone "https://x-access-token:${GH_TOKEN}@github.com/${TAP}.git" tap
105+
cd tap
106+
sed -i -E "s|^(\s*url ).*|\1\"${URL}\"|" "$FORMULA"
107+
sed -i -E "s|^(\s*sha256 ).*|\1\"${SHA}\"|" "$FORMULA"
108+
109+
if git diff --quiet; then
110+
echo "Formula already at ${VERSION}; nothing to bump."
111+
exit 0
112+
fi
113+
114+
BRANCH="bump-band-${VERSION}"
115+
git config user.name "github-actions[bot]"
116+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
117+
git switch -C "$BRANCH"
118+
git commit -am "band ${VERSION}"
119+
git push -f origin "$BRANCH"
120+
121+
# Re-run safe: only open a PR if one isn't already open for this branch.
122+
if [ -z "$(gh pr list --repo "$TAP" --head "$BRANCH" --state open --json number --jq '.[0].number')" ]; then
123+
gh pr create --repo "$TAP" --base main --head "$BRANCH" \
124+
--title "band ${VERSION}" \
125+
--body "Automated formula bump to ${VERSION}."
126+
fi

0 commit comments

Comments
 (0)