-
Notifications
You must be signed in to change notification settings - Fork 13
227 lines (201 loc) · 7.14 KB
/
Copy pathrelease.yml
File metadata and controls
227 lines (201 loc) · 7.14 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
packages: write
jobs:
verify:
uses: ./.github/workflows/ci.yml
permissions:
contents: read
create-release:
needs: verify
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Resolve release range
id: range
run: |
PREV_TAG=$(git tag --sort=-v:refname | sed -n '2p')
if [ -z "$PREV_TAG" ]; then
RANGE="HEAD"
else
RANGE="${PREV_TAG}..HEAD"
fi
echo "prev_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
echo "range=${RANGE}" >> "$GITHUB_OUTPUT"
- name: Generate release notes (monorepo grouped)
id: changelog
run: |
bash scripts/release/generate-release-notes.sh \
"${{ steps.version.outputs.version }}" \
"${{ steps.range.outputs.range }}" \
"${{ steps.range.outputs.prev_tag }}" \
> RELEASE_BODY.md
{
echo 'body<<CHANGELOG_EOF'
cat RELEASE_BODY.md
echo 'CHANGELOG_EOF'
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.body }}
draft: false
prerelease: false
- name: Update CHANGELOG.md in default branch
continue-on-error: true
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch origin "${DEFAULT_BRANCH}"
git checkout -B "${DEFAULT_BRANCH}" "origin/${DEFAULT_BRANCH}"
if [ ! -f CHANGELOG.md ]; then
printf '%s\n' \
'# Changelog' \
'' \
'All notable changes to this project are documented in this file.' \
'' \
'<!-- release-entries -->' \
> CHANGELOG.md
fi
if grep -q "^## v${VERSION} " CHANGELOG.md; then
echo "CHANGELOG.md already contains v${VERSION}, skip."
exit 0
fi
DATE_UTC="$(date -u +%Y-%m-%d)"
awk -v version="${VERSION}" -v date_utc="${DATE_UTC}" '
{
print
if ($0 == "<!-- release-entries -->" && !done) {
print ""
print "## v" version " - " date_utc
while ((getline line < "RELEASE_BODY.md") > 0) {
print line
}
print ""
done = 1
}
}
' CHANGELOG.md > CHANGELOG.md.tmp
mv CHANGELOG.md.tmp CHANGELOG.md
if git diff --quiet -- CHANGELOG.md; then
echo "No CHANGELOG diff, skip commit."
exit 0
fi
git add CHANGELOG.md
git commit -m "docs(changelog): update for v${VERSION}"
git push origin "HEAD:${DEFAULT_BRANCH}"
build-binaries:
needs: create-release
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build cloud-claude
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
VERSION="${{ needs.create-release.outputs.version }}"
LDFLAGS="-s -w -X main.Version=${VERSION}"
BINARY="cloud-claude-${{ matrix.goos }}-${{ matrix.goarch }}"
go build -ldflags "${LDFLAGS}" -trimpath -o "${BINARY}" ./cmd/cloud-claude
- name: Compress binary
run: |
BINARY="cloud-claude-${{ matrix.goos }}-${{ matrix.goarch }}"
ARCHIVE="cloud-claude-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
tar czf "${ARCHIVE}" "${BINARY}"
sha256sum "${ARCHIVE}" > "${ARCHIVE}.sha256"
- name: Upload to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ARCHIVE="cloud-claude-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
gh release upload "${{ github.ref_name }}" "${ARCHIVE}" "${ARCHIVE}.sha256" --clobber
update-homebrew:
needs: [create-release, build-binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download sha256 files from release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
for platform in darwin-amd64 darwin-arm64 linux-amd64 linux-arm64; do
gh release download "${TAG}" -p "cloud-claude-${platform}.tar.gz.sha256"
done
- name: Extract checksums
id: shas
run: |
extract_sha() { awk '{print $1}' "cloud-claude-${1}.tar.gz.sha256"; }
echo "darwin_amd64=$(extract_sha darwin-amd64)" >> "$GITHUB_OUTPUT"
echo "darwin_arm64=$(extract_sha darwin-arm64)" >> "$GITHUB_OUTPUT"
echo "linux_amd64=$(extract_sha linux-amd64)" >> "$GITHUB_OUTPUT"
echo "linux_arm64=$(extract_sha linux-arm64)" >> "$GITHUB_OUTPUT"
- name: Generate Formula
run: |
bash scripts/release/generate-homebrew-formula.sh \
"${{ needs.create-release.outputs.version }}" \
"${{ steps.shas.outputs.darwin_amd64 }}" \
"${{ steps.shas.outputs.darwin_arm64 }}" \
"${{ steps.shas.outputs.linux_amd64 }}" \
"${{ steps.shas.outputs.linux_arm64 }}" \
> cloud-claude.rb
- name: Push to Homebrew tap
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
git clone "https://x-access-token:${TAP_TOKEN}@github.com/ZaneL1u/homebrew-tap.git" tap-repo
mkdir -p tap-repo/Formula
cp cloud-claude.rb tap-repo/Formula/cloud-claude.rb
cd tap-repo
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/cloud-claude.rb
if git diff --cached --quiet; then
echo "Formula unchanged, skip."
else
git commit -m "cloud-claude ${GITHUB_REF_NAME}"
git push
fi
publish-images:
needs: create-release
uses: ./.github/workflows/build-images.yml
with:
version: ${{ needs.create-release.outputs.version }}
permissions:
contents: read
packages: write