Repository navigation
289 lines (250 loc) · 9.39 KB
/
Copy pathwasm.yml
File metadata and controls
289 lines (250 loc) · 9.39 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
name: Wasm
on:
push:
branches:
- main
- release/**
tags:
- v*
paths:
- bindings/wasm/**
- tokenizers/**
- .github/workflows/wasm.yml
pull_request:
paths:
- bindings/wasm/**
- tokenizers/**
- .github/workflows/wasm.yml
permissions: {}
# Fail instead of silently updating Cargo.lock.
env:
CARGO_FLAGS: --locked
jobs:
code-quality:
permissions:
contents: read
name: Lint & format
runs-on: ubuntu-latest
defaults:
run:
working-directory: bindings/wasm
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Cache cargo registry / git / target
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: bindings/wasm
shared-key: wasm
# Test fixtures are immutable — cache them so CI doesn't re-download
# from the Hub (and get rate-limited) on every run.
- name: Cache HF test data
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: bindings/wasm/data
key: hf-test-data-wasm-${{ hashFiles('bindings/wasm/Makefile') }}
restore-keys: hf-test-data-wasm-
# Provides `uvx`, used to run the huggingface_hub CLI that downloads
# test fixtures (see the Makefile) without a separate install step.
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
# Clippy runs on --all-targets, and the tests `include_str!` the fixtures.
- name: Lint with RustFmt and Clippy
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: make check-style HF="uvx --from huggingface_hub hf"
build:
permissions:
contents: read
name: Build bindings
runs-on: ubuntu-latest
defaults:
run:
working-directory: bindings/wasm
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Cache cargo registry / git / target
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: bindings/wasm
shared-key: wasm-release
- name: Install wasm-pack
uses: taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2.87.21
with:
tool: wasm-pack@0.15.0
- name: Build bindings
run: make build
- name: Install Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: latest
test:
permissions:
contents: read
name: Test (${{ matrix.browser }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: [firefox, chrome]
defaults:
run:
working-directory: bindings/wasm
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Cache cargo registry / git / target
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: bindings/wasm
shared-key: wasm
- name: Install wasm-pack
uses: taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2.87.21
with:
tool: wasm-pack@0.15.0
# Test fixtures are immutable — cache them so CI doesn't re-download
# from the Hub (and get rate-limited) on every run.
- name: Cache HF test data
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: bindings/wasm/data
key: hf-test-data-wasm-${{ hashFiles('bindings/wasm/Makefile') }}
restore-keys: hf-test-data-wasm-
# Provides `uvx`, used to run the huggingface_hub CLI that downloads
# test fixtures (see the Makefile) without a separate install step.
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
# The runner image ships Chrome with a matching chromedriver; the one wasm-pack
# downloads tracks the newest Chrome and can refuse the installed one.
- name: Run tests in headless ${{ matrix.browser }}
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
BROWSER: ${{ matrix.browser }}
run: |
if [ "$BROWSER" = chrome ]; then export CHROMEDRIVER="$CHROMEWEBDRIVER/chromedriver"; fi
make test HF="uvx --from huggingface_hub hf"
test-package:
permissions:
contents: read
name: Test packed npm tarball
runs-on: ubuntu-latest
defaults:
run:
working-directory: bindings/wasm
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Cache cargo registry / git / target
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: bindings/wasm
shared-key: wasm-release
- name: Install wasm-pack
uses: taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2.87.21
with:
tool: wasm-pack@0.15.0
- name: Install Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: latest
- name: Cache HF test data
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: bindings/wasm/data
key: hf-test-data-wasm-${{ hashFiles('bindings/wasm/Makefile') }}
restore-keys: hf-test-data-wasm-
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
# Also downloads a tokenizer from the Hub through `from_pretrained`; the token avoids rate limits.
- name: Install the tarball and run it under Node
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: make test-package HF="uvx --from huggingface_hub hf"
publish:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: [code-quality, build, test, test-package]
name: Publish to npm
runs-on: ubuntu-latest
environment: release
permissions:
# Trusted Publishing: the job mints an OIDC token that npm exchanges for a
# short-lived publish token, so there is no long-lived NPM_TOKEN secret. The
# same id-token also signs the provenance attestation.
contents: read
id-token: write
defaults:
run:
working-directory: bindings/wasm
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Cache cargo registry / git / target
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: bindings/wasm
shared-key: wasm-release
- name: Install wasm-pack
uses: taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2.87.21
with:
tool: wasm-pack@0.15.0
# No registry-url: it writes an .npmrc with a ${NODE_AUTH_TOKEN} placeholder that OIDC can't fill.
- name: Install Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: latest
# Staged publishing landed in npm 11.15.0 (OIDC publishing in 11.5.1).
- name: Ensure npm supports staged publishing
run: npm install -g npm@^11.15.0
- name: Build bindings
run: make build
- name: Check the package version matches the tag
run: |
VERSION=$(node -p 'require("./pkg/package.json").version')
if [ "$VERSION" != "${GITHUB_REF_NAME#v}" ]; then
echo "::error::pkg/package.json is $VERSION but the tag is $GITHUB_REF_NAME"
exit 1
fi
- name: Verify package contents
run: npm pack --dry-run ./pkg
- name: Stage for publishing
run: |
TAG=latest
[[ "$GITHUB_REF_NAME" == *-* ]] && TAG=next
npm stage publish ./pkg --access public --provenance --tag "$TAG"