-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (98 loc) · 3.61 KB
/
Copy pathbuild.yml
File metadata and controls
108 lines (98 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
name: goreleaser
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run goreleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew:
name: Update Homebrew Tap
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout this repo
uses: actions/checkout@v4
- name: Get release asset URL and sha256
id: asset
run: |
set -e
TAG=${GITHUB_REF#refs/tags/}
API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}"
# try to find darwin_amd64 asset; fallback to first asset
ASSET_URL=$(curl -s $API_URL | jq -r '.assets[] | select(.name|test("darwin_amd64")) | .browser_download_url' || true)
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
ASSET_URL=$(curl -s $API_URL | jq -r '.assets[0].browser_download_url')
fi
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
echo "no asset url"; exit 1
fi
curl -L "$ASSET_URL" -o /tmp/bb.tar.gz
sha256=$(shasum -a 256 /tmp/bb.tar.gz | awk '{print $1}')
echo "asset_url=$ASSET_URL" >> $GITHUB_OUTPUT
echo "sha256=$sha256" >> $GITHUB_OUTPUT
echo "version=$TAG" >> $GITHUB_OUTPUT
- name: Checkout homebrew tap
uses: actions/checkout@v4
with:
repository: livepo/homebrew-tap
token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
path: tap
fetch-depth: 0
- name: Update formula file in tap
run: |
set -e
# ensure tap repo is aligned with remote master before making edits
cd tap
git checkout .
git fetch origin
git checkout master || git switch -c master
git reset --hard origin/master
cd ..
TAG=${{ steps.asset.outputs.version }}
# strip leading v if present
VERSION=${TAG#v}
sha256=${{ steps.asset.outputs.sha256 }}
ASSET_URL=${{ steps.asset.outputs.asset_url }}
# Ensure formula exists
if [ ! -f tap/Formula/bb.rb ]; then
echo "tap/Formula/bb.rb not found"; ls -al tap; exit 1
fi
# Replace placeholders ${VERSION} and ${sha256}
sed -i.bak "s|\${VERSION}|${VERSION}|g" tap/Formula/bb.rb
sed -i.bak "s|\${sha256}|${sha256}|g" tap/Formula/bb.rb
# Replace url line with actual asset URL
sed -n '1,200p' tap/Formula/bb.rb >/tmp/bb.rb.tmp || true
awk -v url="${ASSET_URL}" '{ if ($1=="url") { print " url \""url"\"" } else print $0 }' /tmp/bb.rb.tmp > tap/Formula/bb.rb
- name: Commit and push formula
run: |
set -e
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/bb.rb
# commit only if there are changes
if git diff --staged --quiet && git diff --quiet; then
echo "no changes to commit"
else
git commit -m "chore: bump bb to ${VERSION}"
git push origin HEAD:master
fi
env:
GIT_ASKPASS: /bin/true
HOMEBREW_GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}