-
Notifications
You must be signed in to change notification settings - Fork 31
104 lines (86 loc) · 3.3 KB
/
Copy pathbrew-update.yml
File metadata and controls
104 lines (86 loc) · 3.3 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
name: brew-update
run-name: "Update Homebrew formula for ${{ github.event.release.tag_name }}"
on:
release:
types: [published]
permissions:
contents: read
jobs:
update-formula:
runs-on: ubuntu-latest
steps:
- name: Extract version
id: ver
env:
TAG: ${{ github.event.release.tag_name }}
run: |
version="${TAG#v}"
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Download standalone tarball
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.event.release.tag_name }}
VERSION: ${{ steps.ver.outputs.version }}
run: |
asset="codexmate-${VERSION}-standalone.tar.gz"
for attempt in 1 2 3; do
assets=$(gh release view "${TAG}" --json assets --jq '.assets[].name')
if printf '%s\n' "${assets}" | grep -Fxq "${asset}"; then
gh release download "${TAG}" \
--pattern "${asset}" \
--dir ./assets
exit 0
fi
echo "Asset ${asset} not found for ${TAG} (attempt ${attempt}/3)."
echo "Available assets:"
printf '%s\n' "${assets}"
sleep $((attempt * 10))
done
echo "::error::Missing release asset ${asset} for ${TAG}."
exit 1
- name: Compute SHA256
id: sha
run: |
sha=$(sha256sum "./assets/codexmate-${{ steps.ver.outputs.version }}-standalone.tar.gz" | awk '{print $1}')
echo "sha256=${sha}" >> "$GITHUB_OUTPUT"
- name: Checkout tap repo
uses: actions/checkout@v4
with:
repository: SakuraByteCore/homebrew-codexmate
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
ref: main
- name: Update formula
env:
VERSION: ${{ steps.ver.outputs.version }}
SHA256: ${{ steps.sha.outputs.sha256 }}
run: |
formula="Formula/codexmate.rb"
url="https://github.com/SakuraByteCore/codexmate/releases/download/v${VERSION}/codexmate-${VERSION}-standalone.tar.gz"
sed -i "s|^ url \".*\"| url \"${url}\"|" "$formula"
sed -i "s|^ sha256 \".*\"| sha256 \"${SHA256}\"|" "$formula"
if ! grep -Fq "${url}" "$formula"; then
echo "::error::Formula URL was not updated to ${url}."
exit 1
fi
if ! grep -Fq "${SHA256}" "$formula"; then
echo "::error::Formula SHA256 was not updated to ${SHA256}."
exit 1
fi
echo "### Formula updated" >> "$GITHUB_STEP_SUMMARY"
echo "- version: \`${VERSION}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- sha256: \`${SHA256}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- url: \`${url}\`" >> "$GITHUB_STEP_SUMMARY"
cat "$formula" >> "$GITHUB_STEP_SUMMARY"
- name: Commit and push
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/codexmate.rb
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "bump codexmate to v${VERSION}"
git push origin main