Repository navigation
381 lines (370 loc) · 15.2 KB
/
Copy pathci.yml
File metadata and controls
381 lines (370 loc) · 15.2 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
379
380
381
name: CI
on:
push:
# develop too: the agent loop pushes it directly, with no PR, so without
# this nothing checks its range until the release PR (R14)
branches: [master, develop]
# v + semver only (glob, so the release job re-checks it exactly)
tags: ['v[0-9]*.[0-9]*.[0-9]*']
pull_request:
workflow_dispatch:
# Default for every job; release and pypi declare the extra grants they need
permissions:
contents: read
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
cache: pip
# The requirements files are pointers into pyproject.toml, where
# the dependency list actually lives
cache-dependency-path: |
pyproject.toml
requirements.txt
requirements-test.txt
# System libs opencv-python needs at import
- run: sudo apt-get update && sudo apt-get install -y libgl1 libglib2.0-0
# CPU wheels: an order of magnitude smaller than CUDA, and the suite
# is mocked - the two tests that run a real generation skip themselves
# when no accelerator is present
- name: Install torch (CPU)
run: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
- name: Install dependencies
id: install
# requirements.txt resolves pyproject.toml's dependencies + server
# extra; requirements-test.txt the dev extra. diffusers from git
# goes on afterwards so the resolver doesn't replace it with a
# release
run: |
pip install -c constraints-openapi.txt -r requirements.txt -r requirements-test.txt
pip install git+https://github.com/huggingface/diffusers
# Each check below runs whenever the install succeeded, so one failing
# check never hides another: the ratchet was red for three days behind
# a failing test (#790)
# Guards the architecture metrics against drifting past the committed
# baseline (modules, size ceiling, cycles); see docs/stabilization/
- name: Architecture ratchet
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: python scripts/arch_metrics.py --check docs/stabilization/baseline.json
- name: Format check
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: ruff format --check dw dw_mcp tests scripts
- name: Lint
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: ruff check dw dw_mcp tests scripts
- name: Tests
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: pytest -q
ui:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version-file: ui/.nvmrc
cache: npm
cache-dependency-path: ui/package-lock.json
- name: Install
id: install
run: npm ci
# Each check below runs whenever the install succeeded, so one failing
# check never hides another, as in the backend job: a formatting
# failure kept lint, the ratchet, the type check and the unit tests
# from running at all on seven pushes
# The UI's response types are generated from the server's OpenAPI
# document (scripts/dump_openapi.py writes it; the backend job's
# tests/test_api_contract.py fails when it is stale). A stale
# api-schema.ts fails here; a field the UI reads that the server no
# longer sends fails the type check below
- name: Response contract
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm run gen:api && git diff --exit-code src/lib/generated
- name: Format check
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npx prettier --check src e2e scripts *.ts *.js
- name: Lint
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm run lint
- name: Architecture ratchet
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm run metrics -- --check ../docs/stabilization/ui/baseline.json
- name: Type check
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm run check
- name: Unit tests
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm test
- name: Build
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
run: npm run build
e2e:
# Playwright against a real dw.serve before develop moves - on PRs into
# develop or master, and on pushes to develop, since the agent loop
# pushes develop directly with no PR. The release PR (this repo's
# develop into master) is skipped: its every commit is a develop push,
# already run. The job carries the backend install as well as the browser
if: >-
(github.event_name == 'pull_request' &&
(github.base_ref == 'develop' || github.base_ref == 'master') &&
!(github.head_ref == 'develop' &&
github.event.pull_request.head.repo.full_name == github.repository)) ||
(github.event_name == 'push' && github.ref == 'refs/heads/develop')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
cache: pip
cache-dependency-path: |
pyproject.toml
requirements.txt
requirements-test.txt
- run: sudo apt-get update && sudo apt-get install -y libgl1 libglib2.0-0
- name: Install torch (CPU)
run: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
- name: Install dependencies
run: |
pip install -c constraints-openapi.txt -r requirements.txt -r requirements-test.txt
pip install git+https://github.com/huggingface/diffusers
- uses: actions/setup-node@v7
with:
node-version-file: ui/.nvmrc
cache: npm
cache-dependency-path: ui/package-lock.json
- name: Build the UI the fixture server serves
working-directory: ui
run: |
npm ci
npm run build
- name: Install Chromium
working-directory: ui
run: npx playwright install --with-deps chromium
- name: E2E tests
working-directory: ui
env:
DW_E2E_PYTHON: python
run: npx playwright test
- name: Upload the Playwright report
if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: |
ui/playwright-report/
ui/test-results/
retention-days: 7
wheel:
# The packaged artifact: SPA built into the wheel. Tags and manual runs
# only - the jobs above already prove the build on every push.
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
needs: [backend, ui]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version-file: ui/.nvmrc
cache: npm
cache-dependency-path: |
ui/package-lock.json
package-lock.json
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- run: cd ui && npm ci
# The root lock pins the .mcpb packer that build_mcpb.py runs
- run: npm ci
- run: pip install build
- run: bash scripts/build_dist.sh
- uses: actions/upload-artifact@v7
with:
# Only what PyPI receives: the wheel and the sdist
name: diffusers-workflow-dist
path: |
dist/*.whl
dist/*.tar.gz
- uses: astral-sh/setup-uv@v10.4.0
with:
version: "0.9.5"
- name: Build the dw-mcp bundle
run: python scripts/build_mcpb.py --out dist/
- name: Smoke test the bundle
# Unpack it and start its server under uv, the way a host would
run: |
python scripts/build_mcpb.py --unpack dist/dw-mcp-*.mcpb "$RUNNER_TEMP/mcpb"
cd "$RUNNER_TEMP/mcpb"
test -f uv.lock
uv run --frozen --directory . python -m dw_mcp --help
- uses: actions/upload-artifact@v7
with:
name: dw-mcp-bundle
path: dist/dw-mcp-*.mcpb
tag-check:
# Gates every publish: a tag that is not v<semver>, or not the version
# pyproject declares, reaches neither PyPI nor a GitHub release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Check the tag against the declared versions
run: |
tag="${GITHUB_REF_NAME#v}"
if ! echo "$tag" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "Tag $GITHUB_REF_NAME is not v<semver>"; exit 1
fi
pyproject=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
if [ "$tag" != "$pyproject" ]; then
echo "Tag $tag != pyproject version $pyproject"
exit 1
fi
release:
# A v<semver> tag that passed the full test and build chain becomes a
# GitHub release carrying the wheel and sdist. After pypi: the release's
# bootstrap installs this version from PyPI and is the documented
# one-line install, so the release must not exist before the upload
if: startsWith(github.ref, 'refs/tags/v')
needs: [wheel, pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: diffusers-workflow-dist
path: dist
- uses: actions/download-artifact@v8
with:
name: dw-mcp-bundle
path: dist
- name: Add the bootstrap scripts and checksums
run: |
cp dw/install_scripts/bootstrap.sh dw/install_scripts/bootstrap.ps1 dist/
# A script fetched from releases/download/<tag>/ installs that tag;
# fails unless each placeholder is stamped exactly once
python3 scripts/stamp_bootstrap.py "${GITHUB_REF_NAME#v}" dist/bootstrap.sh dist/bootstrap.ps1
(cd dist && sha256sum -- * > ../SHA256SUMS)
mv SHA256SUMS dist/
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
# A pre-release marker in the tag (v1.2.3-rc1) marks the release too
run: |
prerelease=""
case "$GITHUB_REF_NAME" in *-*) prerelease="--prerelease";; esac
gh release create "$GITHUB_REF_NAME" dist/* \
--repo "$GITHUB_REPOSITORY" \
--title "$GITHUB_REF_NAME" \
--generate-notes --verify-tag $prerelease
mcp-registry:
# The bundle is listed in the MCP Registry under io.github.dkackman/dw,
# logged in through GitHub OIDC. A registry outage must not fail a release.
# Off until the repo variable MCP_REGISTRY_PUBLISH is 'true': it is set
# once Claude Desktop is confirmed to run the bundle (docs/RELEASING.md)
needs: release
if: vars.MCP_REGISTRY_PUBLISH == 'true'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: dw-mcp-bundle
path: dist
- name: Render server.json
run: python3 scripts/build_mcpb.py --server-json dist/dw-mcp-*.mcpb > server.json
- name: Install mcp-publisher
run: |
# Pinned release; the sha256 is the asset digest GitHub reports for it
tag=v1.8.16
sha=6e2f799550cf843c6fd3350498d56cc49be3dc0af1e6237eb0e6435c7a9d5c05
curl -fsSL -o mcp-publisher.tar.gz "https://github.com/modelcontextprotocol/registry/releases/download/${tag}/mcp-publisher_linux_amd64.tar.gz"
echo "${sha} mcp-publisher.tar.gz" | sha256sum -c -
tar xzf mcp-publisher.tar.gz mcp-publisher
sudo mv mcp-publisher /usr/local/bin/
- run: mcp-publisher login github-oidc
- run: mcp-publisher publish
pypi:
# Trusted publishing (OIDC) - register on pypi.org first: project
# diffusers-workflow, owner dkackman, repo diffusers-workflow,
# workflow ci.yml, environment pypi. No token or secret is stored.
# Before release (see there); tag-check is what limits it to a tag
needs: [wheel, tag-check]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/diffusers-workflow
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v8
with:
name: diffusers-workflow-dist
path: dist
- uses: pypa/gh-action-pypi-publish@v1.14.3
docker:
# The container image (docker/Dockerfile, docs/DOCKER.md) on Docker Hub,
# from the same tag as the release. One-time setup: a Docker Hub access
# token (read/write) for dkackman, stored as secret DOCKERHUB_TOKEN in a
# GitHub environment named dockerhub. A pre-release tag (v1.2.3-rc1)
# pushes its version only; a release also moves latest.
needs: release
runs-on: ubuntu-latest
environment:
name: dockerhub
url: https://hub.docker.com/r/dkackman/diffusers-workflow
env:
IMAGE: dkackman/diffusers-workflow
steps:
- name: Free disk space
# The image is ~12 GB and torch's wheels are unpacked on the way;
# the runner's preinstalled SDKs leave too little room otherwise
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/opt/hostedtoolcache/CodeQL /usr/local/share/boost
sudo docker image prune --all --force
df -h /
- uses: actions/checkout@v7
- name: Build
run: |
version="${GITHUB_REF_NAME#v}"
tags=(-t "$IMAGE:$version")
case "$version" in *-*) ;; *) tags+=(-t "$IMAGE:latest");; esac
docker buildx build --load -f docker/Dockerfile "${tags[@]}" \
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--label "org.opencontainers.image.version=$version" \
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
.
- name: Smoke test
# No GPU here: the server starts on CPU with the baked diffusers and
# must answer /api/health; the worker starts lazily, so no model loads
run: |
docker run -d --name dw -p 127.0.0.1:8765:8765 \
-e DW_DIFFUSERS_REF=image -e DW_INSECURE_NO_TOKEN=1 \
"$IMAGE:${GITHUB_REF_NAME#v}"
for _ in $(seq 60); do
if curl -fsS http://127.0.0.1:8765/api/health >/dev/null; then
docker logs dw 2>&1 | tail -5; exit 0
fi
sleep 5
done
docker logs dw 2>&1 | tail -50
exit 1
- name: Push
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
echo "$DOCKERHUB_TOKEN" | docker login -u dkackman --password-stdin
docker push --all-tags "$IMAGE"
docker logout