-
Notifications
You must be signed in to change notification settings - Fork 0
402 lines (342 loc) · 13.2 KB
/
python-react-publish.yml
File metadata and controls
402 lines (342 loc) · 13.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
name: Reusable Python+React Publish
# Reusable tag-triggered publish workflow.
# Sequencing: test-* → docker → release
# - All test-* jobs must pass before docker push
# - docker push must succeed before release creation
# This guarantees: a tag never publishes a GitHub release without a matching
# image in GHCR. If the docker push fails, no release is created.
on:
workflow_call:
inputs:
python-version:
type: string
default: "3.14"
bun-version-file:
type: string
default: ".bun-version"
bun-version:
type: string
default: ""
enable-e2e:
type: boolean
default: true
enable-translations:
type: boolean
default: false
enable-bootstrap-token:
type: boolean
default: false
enable-api-freshness-check:
type: boolean
default: true
runner-os:
type: string
default: ubuntu-latest
security-tripwire-script:
type: string
default: ""
image-name:
type: string
required: true
release-name-prefix:
# E.g. "TideWatch v" → produces "TideWatch v3.9.2"
type: string
required: true
secrets:
github-token:
required: true
permissions:
contents: read
jobs:
test-backend:
name: Backend Tests
runs-on: ${{ inputs.runner-os }}
timeout-minutes: 25
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8
with:
enable-cache: true
cache-dependency-glob: 'backend/uv.lock'
- name: Install dependencies
run: cd backend && uv sync --frozen --all-extras
- name: Run ruff linter
run: cd backend && uv run ruff check .
- name: Run ruff formatter check
run: cd backend && uv run ruff format --check .
- name: Run pyright type checking
run: cd backend && PYTHONPATH=. uv run pyright
- name: Security tripwire
if: inputs.security-tripwire-script != ''
run: bash "${{ inputs.security-tripwire-script }}"
- name: Run pytest
run: cd backend && timeout 25m uv run pytest tests/ -v --tb=short
test-frontend:
name: Frontend Tests
runs-on: ${{ inputs.runner-os }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Bun (from version-file)
if: inputs.bun-version == ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version-file: ${{ inputs.bun-version-file }}
- name: Set up Bun (from explicit override)
if: inputs.bun-version != ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: ${{ inputs.bun-version }}
- name: Install dependencies
run: cd frontend && bun install --frozen-lockfile
- name: Run TypeScript type checking
run: cd frontend && bun run type-check
- name: Run linter
run: cd frontend && bun run lint
- name: Validate translation keys
if: inputs.enable-translations
run: cd frontend && bun run validate:translations
- name: Run tests
run: cd frontend && bun run test:run
test-e2e:
name: E2E Tests
if: inputs.enable-e2e
runs-on: ${{ inputs.runner-os }}
timeout-minutes: 20
needs: [test-backend, test-frontend]
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8
with:
enable-cache: true
cache-dependency-glob: 'backend/uv.lock'
- name: Install backend dependencies
run: cd backend && uv sync --frozen --all-extras
- name: Set up Bun (from version-file)
if: inputs.bun-version == ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version-file: ${{ inputs.bun-version-file }}
- name: Set up Bun (from explicit override)
if: inputs.bun-version != ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: ${{ inputs.bun-version }}
- name: Install frontend dependencies
run: cd frontend && bun install --frozen-lockfile
- name: Install Playwright browsers
run: cd frontend && bunx playwright install chromium --with-deps
- name: Run E2E tests
run: cd frontend && bun run e2e
env:
CI: true
VULNFORGE_BOOTSTRAP_TOKEN: ${{ inputs.enable-bootstrap-token && 'e2e-ci-test-token' || '' }}
- name: Upload Playwright report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
if: ${{ !cancelled() }}
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 14
- name: Upload test results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
if: ${{ !cancelled() }}
with:
name: playwright-results
path: frontend/test-results/
retention-days: 7
api-types-freshness:
name: API Types Freshness
if: inputs.enable-api-freshness-check
runs-on: ${{ inputs.runner-os }}
needs: [test-backend]
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8
with:
enable-cache: true
cache-dependency-glob: 'backend/uv.lock'
- name: Install backend dependencies
run: cd backend && uv sync --frozen --all-extras
- name: Set up Bun (from version-file)
if: inputs.bun-version == ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version-file: ${{ inputs.bun-version-file }}
- name: Set up Bun (from explicit override)
if: inputs.bun-version != ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: ${{ inputs.bun-version }}
- name: Install frontend dependencies
run: cd frontend && bun install --frozen-lockfile
- name: Check API types freshness
run: cd frontend && bun run check:api-freshness
docker:
name: Build and Push Docker Image
runs-on: ${{ inputs.runner-os }}
needs: [test-backend, test-frontend, api-types-freshness]
# api-types-freshness is conditional on inputs.enable-api-freshness-check.
# When that input is false the job is skipped — and a skipped need would
# also skip docker without this guard. Allow docker to proceed when
# api-types-freshness is either successful OR skipped, while still
# blocking on real test failures.
if: |
always()
&& needs.test-backend.result == 'success'
&& needs.test-frontend.result == 'success'
&& (needs.api-types-freshness.result == 'success' || needs.api-types-freshness.result == 'skipped')
permissions:
contents: read
packages: write
id-token: write
attestations: write
outputs:
digest: ${{ steps.push.outputs.digest }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Log in to GitHub Container Registry
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.github-token }}
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f1-2)
# Standard semver pre-release: anything with `-` after patch
# (e.g. v2.27.0-rc1, v2.27.0-beta.1, v3.0.0-alpha).
# Pre-release tags publish only the exact :VERSION image — they
# must NOT move :latest, :MAJOR, or :MINOR away from stable.
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IS_PRERELEASE=false
else
IS_PRERELEASE=true
fi
{
echo "version=$VERSION"
echo "major=$MAJOR"
echo "minor=$MINOR"
echo "is_prerelease=$IS_PRERELEASE"
} >> "$GITHUB_OUTPUT"
- name: Read bun version
id: bun
run: echo "version=$(cat ${{ inputs.bun-version-file }})" >> "$GITHUB_OUTPUT"
- name: Compute Docker tags
id: tags
run: |
# Always publish the exact :VERSION tag.
TAGS="ghcr.io/${{ inputs.image-name }}:${{ steps.version.outputs.version }}"
# Stable tags only update on non-pre-release builds. Pre-release
# users (rc/beta/alpha) pin to the exact version; production
# users on :latest stay on the last stable.
if [[ "${{ steps.version.outputs.is_prerelease }}" == "false" ]]; then
TAGS="$TAGS"$'\n'"ghcr.io/${{ inputs.image-name }}:latest"
TAGS="$TAGS"$'\n'"ghcr.io/${{ inputs.image-name }}:${{ steps.version.outputs.minor }}"
TAGS="$TAGS"$'\n'"ghcr.io/${{ inputs.image-name }}:${{ steps.version.outputs.major }}"
fi
{
echo "tags<<EOF"
echo "$TAGS"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
id: push
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
BUN_VERSION=${{ steps.bun.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Generate artifact attestation
if: github.event.repository.visibility == 'public'
continue-on-error: true
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4
with:
subject-name: ghcr.io/${{ inputs.image-name }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
release:
name: Create GitHub Release
runs-on: ${{ inputs.runner-os }}
needs: [docker]
# The docker job uses `if: always() && ...` to handle the
# api-types-freshness-skipped case. That marks docker as a
# conditional job, which causes downstream `needs:` evaluation to
# treat docker's "success" differently from an unconditional job.
# Use `always() &&` here too so this if: always evaluates, and
# gate explicitly on docker's actual result.
if: always() && needs.docker.result == 'success'
permissions:
contents: write
packages: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Extract changelog for this version
id: changelog
run: |
VERSION=${{ steps.version.outputs.version }}
CHANGELOG=$(awk -v ver="$VERSION" '
/^## \[.*\]/ {
if (found) exit
if ($0 ~ "\\[" ver "\\]") found=1
next
}
found { print }
' CHANGELOG.md)
echo "$CHANGELOG" > release_notes.md
- name: Check if pre-release
id: prerelease
run: |
VERSION=${{ steps.version.outputs.version }}
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.github-token }}
with:
name: ${{ inputs.release-name-prefix }}${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ steps.prerelease.outputs.prerelease }}
generate_release_notes: true