Skip to content

Commit c61891e

Browse files
committed
ci: auto-update homebrew formula on release
1 parent 12f2ccc commit c61891e

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

.github/workflows/release.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,51 @@ jobs:
2929
args: release --clean
3030
env:
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
32+
33+
update-formula:
34+
runs-on: ubuntu-latest
35+
needs: goreleaser
36+
steps:
37+
- name: Update Homebrew formula
38+
env:
39+
TAG: ${{ github.ref_name }}
40+
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
41+
run: |
42+
VERSION="${TAG#v}"
43+
URL="https://github.com/WarriorsCode/deck/archive/refs/tags/${TAG}.tar.gz"
44+
SHA256=$(curl -sL "$URL" | sha256sum | cut -d' ' -f1)
45+
46+
FORMULA="class Deck < Formula
47+
desc \"Lightweight local dev orchestrator\"
48+
homepage \"https://github.com/WarriorsCode/deck\"
49+
url \"${URL}\"
50+
sha256 \"${SHA256}\"
51+
license \"MIT\"
52+
53+
depends_on \"go\" => :build
54+
55+
def install
56+
ldflags = \"-s -w -X github.com/warriorscode/deck.Version=#{version}\"
57+
system \"go\", \"build\", *std_go_args(ldflags:), \"./cmd/deck\"
58+
end
59+
60+
test do
61+
system bin/\"deck\", \"--version\"
62+
end
63+
end"
64+
# dedent
65+
FORMULA=$(echo "$FORMULA" | sed 's/^ //')
66+
67+
# get current file sha
68+
FILE_SHA=$(gh api repos/WarriorsCode/homebrew-tap/contents/Formula/deck.rb --jq '.sha' 2>/dev/null || echo "")
69+
70+
ARGS=(-f "message=formula: update deck to ${VERSION}")
71+
ARGS+=(-f "content=$(echo "$FORMULA" | base64 -w0)")
72+
if [ -n "$FILE_SHA" ]; then
73+
ARGS+=(-f "sha=${FILE_SHA}")
74+
fi
75+
76+
gh api -X PUT repos/WarriorsCode/homebrew-tap/contents/Formula/deck.rb "${ARGS[@]}"
3377
3478
sync-docs:
3579
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)