This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
378 lines (327 loc) · 12 KB
/
Copy pathrelease.yml
File metadata and controls
378 lines (327 loc) · 12 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
env:
CARGO_TERM_COLOR: always
BINARY_NAME: cc-relay-server
DOCKER_IMAGE: wakaka6/claude-code-relay
permissions:
contents: write
packages: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
use_cross: false
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
use_cross: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
use_cross: true
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
use_cross: true
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
use_cross: false
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
use_cross: false
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
use_cross: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Install musl-tools (x86_64-musl without cross)
if: matrix.target == 'x86_64-unknown-linux-musl' && !matrix.use_cross
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build with cross
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }} -p relay-server
- name: Build with cargo
if: ${{ !matrix.use_cross }}
run: cargo build --release --target ${{ matrix.target }} -p relay-server
- name: Get version
id: version
shell: bash
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Package (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar -czvf ../../../${{ env.BINARY_NAME }}-${{ steps.version.outputs.version }}-${{ matrix.target }}.tar.gz ${{ env.BINARY_NAME }}
- name: Package (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path ${{ env.BINARY_NAME }}.exe -DestinationPath ../../../${{ env.BINARY_NAME }}-${{ steps.version.outputs.version }}-${{ matrix.target }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
path: ${{ env.BINARY_NAME }}-${{ steps.version.outputs.version }}-${{ matrix.target }}.${{ matrix.archive }}
if-no-files-found: error
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_IMAGE }}
ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable=${{ !contains(github.ref, '-') }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
needs: [build, docker]
runs-on: ubuntu-latest
steps:
- name: Get version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: ${{ env.BINARY_NAME }}-*
merge-multiple: true
- name: Generate checksums
working-directory: artifacts
run: |
sha256sum * > checksums-sha256.txt
cat checksums-sha256.txt
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: Release v${{ steps.version.outputs.version }}
draft: false
prerelease: ${{ contains(github.ref, '-') }}
generate_release_notes: true
files: |
artifacts/*
update-aur:
needs: release
if: ${{ !contains(github.ref, '-') }}
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Get version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Wait for release tarball
run: |
set -euo pipefail
for i in $(seq 1 30); do
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
"https://github.com/${{ github.repository }}/archive/refs/tags/v${{ steps.version.outputs.version }}.tar.gz")
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "302" ]; then
echo "Release tarball is available"
exit 0
fi
echo "Waiting for release tarball (HTTP $HTTP_CODE)... attempt $i/30"
sleep 10
done
echo "Release tarball not available after 5 minutes"
exit 1
- name: Get tarball SHA256
id: sha256
run: |
set -euo pipefail
SHA256=$(curl -fsSL --retry 3 --retry-delay 10 \
"https://github.com/${{ github.repository }}/archive/refs/tags/v${{ steps.version.outputs.version }}.tar.gz" \
| sha256sum | cut -d' ' -f1)
if [[ ! "$SHA256" =~ ^[a-f0-9]{64}$ ]]; then
echo "Invalid SHA256: $SHA256"
exit 1
fi
echo "SHA256: $SHA256"
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
- name: Setup SSH
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s\n' "${{ secrets.AUR_SSH_PRIVATE_KEY }}" > ~/.ssh/aur
chmod 600 ~/.ssh/aur
ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts
cat >> ~/.ssh/config <<'EOF'
Host aur.archlinux.org
IdentityFile ~/.ssh/aur
User aur
EOF
sed -i 's/^ //' ~/.ssh/config
chmod 600 ~/.ssh/config
- name: Clone AUR repo
run: git clone ssh://aur@aur.archlinux.org/claude-code-relay.git aur-repo
- name: Update PKGBUILD
working-directory: aur-repo
env:
NEW_VERSION: ${{ steps.version.outputs.version }}
NEW_SHA: ${{ steps.sha256.outputs.sha256 }}
run: |
set -euo pipefail
echo "Before update:"
grep -E "^(pkgver|sha256sums)" PKGBUILD | head -3
sed -i "s/^pkgver=.*/pkgver=${NEW_VERSION}/" PKGBUILD
sed -i "0,/'[a-f0-9]\{64\}'/s/'[a-f0-9]\{64\}'/'${NEW_SHA}'/" PKGBUILD
echo "After update:"
grep -E "^(pkgver|sha256sums)" PKGBUILD | head -3
if ! grep -q "${NEW_SHA}" PKGBUILD; then
echo "Error: SHA256 not updated in PKGBUILD"
exit 1
fi
- name: Generate .SRCINFO
working-directory: aur-repo
run: |
docker run --rm -v "$(pwd):/pkg" archlinux:base-devel bash -c "
useradd -m builder
chown -R builder:builder /pkg
cd /pkg
su builder -c 'makepkg --printsrcinfo > .SRCINFO'
"
- name: Commit and push
working-directory: aur-repo
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add PKGBUILD .SRCINFO
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update to v${{ steps.version.outputs.version }}"
git push
update-homebrew:
needs: release
if: ${{ !contains(github.ref, '-') }}
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Get version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Wait for release tarball
run: |
set -euo pipefail
for i in $(seq 1 30); do
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
"https://github.com/${{ github.repository }}/archive/refs/tags/v${{ steps.version.outputs.version }}.tar.gz")
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "302" ]; then
echo "Release tarball is available"
exit 0
fi
echo "Waiting for release tarball (HTTP $HTTP_CODE)... attempt $i/30"
sleep 10
done
echo "Release tarball not available after 5 minutes"
exit 1
- name: Get tarball SHA256
id: sha256
run: |
set -euo pipefail
SHA256=$(curl -fsSL --retry 3 --retry-delay 10 \
"https://github.com/${{ github.repository }}/archive/refs/tags/v${{ steps.version.outputs.version }}.tar.gz" \
| sha256sum | cut -d' ' -f1)
if [[ ! "$SHA256" =~ ^[a-f0-9]{64}$ ]]; then
echo "Invalid SHA256: $SHA256"
exit 1
fi
echo "SHA256: $SHA256"
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
- name: Clone homebrew-tap
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
git clone https://github.com/wakaka6/homebrew-tap.git
cd homebrew-tap
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/wakaka6/homebrew-tap.git"
- name: Update Formula
working-directory: homebrew-tap
env:
NEW_VERSION: ${{ steps.version.outputs.version }}
NEW_SHA: ${{ steps.sha256.outputs.sha256 }}
run: |
set -euo pipefail
FORMULA="Formula/claude-code-relay.rb"
echo "Before update:"
grep -E "^ (url|sha256)" "$FORMULA"
sed -i "s|url \"https://github.com/.*/archive/refs/tags/v[^\"]*\.tar\.gz\"|url \"https://github.com/${{ github.repository }}/archive/refs/tags/v${NEW_VERSION}.tar.gz\"|" "$FORMULA"
sed -i "s/sha256 \"[a-f0-9]\{64\}\"/sha256 \"${NEW_SHA}\"/" "$FORMULA"
echo "After update:"
grep -E "^ (url|sha256)" "$FORMULA"
if ! grep -q "${NEW_SHA}" "$FORMULA"; then
echo "Error: SHA256 not updated in Formula"
exit 1
fi
- name: Commit and push
working-directory: homebrew-tap
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/claude-code-relay.rb
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "claude-code-relay: update to v${{ steps.version.outputs.version }}"
git push