Skip to content

Commit 30ab89b

Browse files
aqua5230claude
andcommitted
ci(release): gate releases on tests + auto-bump Homebrew tap
Add a `test` job (ruff/mypy/pytest against the released ref) that `build` now depends on, so a red tag never ships. Add a `bump-homebrew` job that updates the tap formula's url/sha256/version and pushes, removing the manual cross-repo step. Requires HOMEBREW_TAP_TOKEN secret. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 33fb352 commit 30ab89b

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,42 @@ permissions:
1515
contents: write
1616

1717
jobs:
18+
test:
19+
runs-on: macos-latest
20+
steps:
21+
- name: Resolve ref
22+
id: ref
23+
run: |
24+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
25+
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
26+
else
27+
echo "ref=${{ github.ref }}" >> "$GITHUB_OUTPUT"
28+
fi
29+
30+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
31+
with:
32+
ref: ${{ steps.ref.outputs.ref }}
33+
34+
- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
35+
36+
- run: uv python install 3.13
37+
38+
- run: uv sync --frozen --group dev
39+
40+
- name: Run ruff
41+
run: uv run ruff check .
42+
43+
- name: Run mypy
44+
run: uv run mypy .
45+
46+
- name: Run pytest
47+
run: uv run pytest -v
48+
1849
build:
50+
needs: test
1951
runs-on: macos-latest
52+
outputs:
53+
tag: ${{ steps.ref.outputs.tag }}
2054

2155
steps:
2256
- name: Resolve ref and tag
@@ -117,3 +151,58 @@ jobs:
117151
env:
118152
GH_TOKEN: ${{ github.token }}
119153
run: gh release upload "${{ steps.ref.outputs.tag }}" dist/usage.app.zip dist/usage.app.zip.sha256 --clobber
154+
155+
bump-homebrew:
156+
needs: build
157+
runs-on: ubuntu-latest
158+
steps:
159+
- name: Ensure tap token present
160+
env:
161+
TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
162+
run: |
163+
if [[ -z "$TOKEN" ]]; then
164+
echo "::error::HOMEBREW_TAP_TOKEN secret is not set; cannot update Homebrew tap." >&2
165+
exit 1
166+
fi
167+
168+
- name: Checkout tap repo
169+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
170+
with:
171+
repository: aqua5230/homebrew-usage
172+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
173+
174+
- name: Download release checksum
175+
env:
176+
GH_TOKEN: ${{ github.token }}
177+
run: |
178+
gh release download "${{ needs.build.outputs.tag }}" \
179+
--repo aqua5230/usage \
180+
--pattern usage.app.zip.sha256 \
181+
--output checksum.txt
182+
183+
- name: Update formula
184+
run: |
185+
TAG="${{ needs.build.outputs.tag }}"
186+
VERSION="${TAG#v}"
187+
SHA="$(awk '{print $1}' checksum.txt)"
188+
if [[ -z "$SHA" ]]; then
189+
echo "::error::Could not read sha256 from release checksum." >&2
190+
exit 1
191+
fi
192+
sed -i \
193+
-e "s|url \"https://github.com/aqua5230/usage/releases/download/v[^/]*/usage.app.zip\"|url \"https://github.com/aqua5230/usage/releases/download/${TAG}/usage.app.zip\"|" \
194+
-e "s|sha256 \"[0-9a-f]*\"|sha256 \"${SHA}\"|" \
195+
-e "s|version \"[^\"]*\"|version \"${VERSION}\"|" \
196+
Formula/usage.rb
197+
198+
- name: Commit and push
199+
run: |
200+
git config user.name "github-actions[bot]"
201+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
202+
if git diff --quiet -- Formula/usage.rb; then
203+
echo "Formula already up to date; nothing to commit."
204+
exit 0
205+
fi
206+
git add Formula/usage.rb
207+
git commit -m "usage ${{ needs.build.outputs.tag }}"
208+
git push

0 commit comments

Comments
 (0)