-
Notifications
You must be signed in to change notification settings - Fork 0
238 lines (230 loc) · 8.02 KB
/
Copy pathrelease.yml
File metadata and controls
238 lines (230 loc) · 8.02 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
name: Release
on:
push:
tags:
- "v*"
permissions: {}
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
create-release:
name: Create draft release
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
- name: Verify release contract
env:
TAG: ${{ github.ref_name }}
run: cargo run --quiet -p xtask -- release verify --contract-only --expected-tag "$TAG"
- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
prerelease_flag=""
case "$TAG" in *-*) prerelease_flag="--prerelease" ;; esac
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--draft \
$prerelease_flag \
--title "Switchloom $TAG" \
--generate-notes
build:
name: Build ${{ matrix.target }}
needs: create-release
strategy:
fail-fast: false
matrix:
include:
- target: darwin-arm64
rust_target: aarch64-apple-darwin
runner: macos-14
- target: darwin-x86_64
rust_target: x86_64-apple-darwin
runner: macos-15-intel
- target: linux-x86_64
rust_target: x86_64-unknown-linux-gnu
runner: ubuntu-24.04
- target: linux-arm64
rust_target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
- name: Install Rust target
run: rustup target add ${{ matrix.rust_target }}
- name: Build release archive
env:
TAG: ${{ github.ref_name }}
run: |
cargo run --quiet -p xtask -- release package \
--target "${{ matrix.target }}" \
--cargo-target "${{ matrix.rust_target }}" \
--stage-npm \
--provenance-dir dist/provenance \
--runner "github-actions-${{ matrix.runner }}" \
--git-sha "$GITHUB_SHA" \
--built-at "release-$TAG"
- name: Smoke-test native binary
env:
TAG: ${{ github.ref_name }}
run: test "$(./target/${{ matrix.rust_target }}/release/model-routing --version)" = "model-routing ${TAG#v}"
- name: Upload release archive
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
cp "dist/provenance/${{ matrix.target }}/provenance.json" \
"dist/switchloom-${{ matrix.target }}.provenance.json"
gh release upload "$TAG" \
--repo "$GITHUB_REPOSITORY" \
"dist/switchloom-${{ matrix.target }}.tar.gz" \
"dist/switchloom-${{ matrix.target }}.provenance.json"
finalize:
name: Publish checksums and release
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
- name: Download release archives
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
mkdir assets
gh release download "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--pattern 'switchloom-*.tar.gz' \
--dir assets
- name: Generate aggregate checksums
run: cargo run --quiet -p xtask -- release package --aggregate-checksums-dir assets
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
gh release upload "$TAG" \
--repo "$GITHUB_REPOSITORY" \
assets/SHA256SUMS
gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false
npm-publish:
name: Publish npm package
needs: finalize
if: ${{ vars.NPM_PUBLISH_ENABLED == 'true' }}
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Download and verify release archives
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
mkdir assets
gh release download "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--pattern 'switchloom-*.tar.gz' \
--pattern 'switchloom-*.provenance.json' \
--pattern SHA256SUMS \
--dir assets
cd assets
sha256sum -c SHA256SUMS
- name: Bundle platform binaries
env:
TAG: ${{ github.ref_name }}
run: |
version="${TAG#v}"
for target in darwin-arm64 darwin-x86_64 linux-arm64 linux-x86_64; do
mkdir -p "extract/$target" "npm/native/$target"
tar -xzf "assets/switchloom-$target.tar.gz" -C "extract/$target"
install -m 755 "extract/$target/model-routing" "npm/native/$target/model-routing"
done
cargo run --quiet -p xtask -- release package \
--assemble-provenance \
--provenance-dir assets \
--git-sha "$(git rev-parse HEAD)" \
--built-at "release-$TAG" \
--generated-by github-actions-release
test "$(./npm/native/linux-x86_64/model-routing --version)" = "model-routing $version"
SWITCHLOOM_NATIVE_BIN="$PWD/npm/native/linux-x86_64/model-routing" node npm/bin/model-routing.js --version
cargo run --quiet -p xtask -- release verify --inventory-only --require-provenance
- name: Publish npm package
env:
TAG: ${{ github.ref_name }}
NODE_AUTH_TOKEN: ""
run: |
case "$TAG" in
*-*) npm publish --access public --provenance --tag next ;;
*) npm publish --access public --provenance ;;
esac
homebrew-tap:
name: Update Homebrew tap
needs: finalize
if: ${{ vars.HOMEBREW_TAP_ENABLED == 'true' && !contains(github.ref_name, '-') }}
runs-on: ubuntu-24.04
environment: homebrew-release
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
- name: Download checksums
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
mkdir assets
gh release download "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--pattern SHA256SUMS \
--dir assets
- name: Generate formula
env:
TAG: ${{ github.ref_name }}
run: scripts/generate-formula.sh "${TAG#v}" assets/SHA256SUMS > switchloom.rb
- name: Push formula to tap
env:
TAP_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
test -n "$TAP_TOKEN"
git clone "https://x-access-token:${TAP_TOKEN}@github.com/instructa/homebrew-tap.git" tap
mkdir -p tap/Formula
cp switchloom.rb tap/Formula/switchloom.rb
cd tap
git config user.name "switchloom-release-bot"
git config user.email "release-bot@users.noreply.github.com"
git add Formula/switchloom.rb
if ! git diff --cached --quiet; then
git commit -m "switchloom ${TAG}"
git push origin HEAD
fi