Repository navigation
605 lines (595 loc) · 28.9 KB
/
Copy pathdeploy-tasknotes.yml
File metadata and controls
605 lines (595 loc) · 28.9 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
name: Publish immutable TaskNotes
on:
workflow_dispatch:
inputs:
source_sha:
description: Full 40-character source commit, reachable from main.
required: true
type: string
target:
description: TaskNotes target; dispatch this workflow on main.
required: true
default: staging
type: choice
options:
- staging
- production
drill:
description: Deliberately fail smoke after uploading the already-live production source (manual only).
type: boolean
default: false
permissions:
actions: read
contents: read
concurrency:
group: tasknotes-pages-${{ github.event_name == 'workflow_dispatch' && inputs.target || github.ref }}
cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' }}
# CI is ci.yml. Ops and direct operators dispatch this immutable publisher.
jobs:
admit:
# Validate dispatch shape before acquiring an environment.
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
timeout-minutes: 3
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- env:
TARGET: ${{ inputs.target }}
SOURCE_SHA: ${{ inputs.source_sha }}
GITHUB_TOKEN: ${{ github.token }}
DRILL: ${{ inputs.drill && 'true' || 'false' }}
run: |
set -euo pipefail
case "$TARGET" in staging|production) ;; *) exit 1 ;; esac
[[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]
[[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]
[[ "$GITHUB_REF" == refs/heads/main ]]
node scripts/publisher/refs.mjs
node scripts/publisher/drill.mjs admit
inputs:
needs: admit
runs-on: ubuntu-24.04
timeout-minutes: 3
environment: ${{ inputs.target }}
outputs:
trust: ${{ steps.hashes.outputs.trust }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Workflow-owned ancestry check before reading environment inputs
env:
TARGET: ${{ inputs.target }}
SOURCE_SHA: ${{ inputs.source_sha }}
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/publisher/refs.mjs
- id: hashes
env:
TASKNOTES_TRUST_ASSET_SHA256: ${{ vars.TASKNOTES_TRUST_ASSET_SHA256 }}
run: |
set -euo pipefail
[[ "$TASKNOTES_TRUST_ASSET_SHA256" =~ ^[0-9a-f]{64}$ ]]
printf 'trust=%s\n' "$TASKNOTES_TRUST_ASSET_SHA256" >> "$GITHUB_OUTPUT"
build:
name: Unprivileged frozen TaskNotes build
needs: inputs
runs-on: ubuntu-24.04
timeout-minutes: 25
# No GitHub environment or Cloudflare secrets. Original intake before hooks.
defaults:
run:
working-directory: candidate
env:
TARGET: ${{ inputs.target }}
SOURCE_SHA: ${{ inputs.source_sha }}
TASKNOTES_TRUST_ASSET_SHA256: ${{ needs.inputs.outputs.trust }}
TASKNOTES_SOURCE_ROOT: ${{ github.workspace }}/candidate
outputs:
artifact-id: ${{ steps.artifact.outputs.artifact-id }}
artifact-digest: ${{ steps.artifact.outputs.artifact-digest }}
self-hosted: ${{ steps.self-hosted.outputs.planned }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: publisher
fetch-depth: 0
persist-credentials: false
- name: Workflow-owned ancestry check before candidate checkout or execution
working-directory: publisher
env:
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/publisher/refs.mjs
# Production only, for a source carrying the exact self-hosted contract.
- name: Workflow-owned self-hosted TaskNotes plan
id: self-hosted
working-directory: publisher
run: |
set -euo pipefail
planned=$(node scripts/publisher/self-hosted.mjs planned)
case "$planned" in true|false) ;; *) exit 1 ;; esac
echo "planned=$planned" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.source_sha }}
path: candidate
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Data-only original intake before dependency execution
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/tasknotes-build"
node ../publisher/scripts/publisher/publisher.mjs guard > "$RUNNER_TEMP/tasknotes-build/plan.json"
- run: node ../publisher/scripts/publisher/install-inputs.mjs "$RUNNER_TEMP/tasknotes-build/plan.json"
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271
with:
# Workspace root has only publisher/ and candidate/, no package.json.
version: 10.7.0
run_install: false
- run: pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfile
- name: ALL installed original members, then unprivileged build once
env:
GITHUB_TOKEN: ${{ github.token }}
TASKNOTES_SELF_HOSTED_UI_ORIGIN: ${{ vars.TASKNOTES_SELF_HOSTED_UI_ORIGIN }}
run: node ../publisher/scripts/publisher/build.mjs "$RUNNER_TEMP/tasknotes-build"
- run: node ../publisher/scripts/publisher/envelope.mjs "$RUNNER_TEMP/tasknotes-build"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
id: artifact
with:
name: tasknotes-build-${{ inputs.target }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-build/
include-hidden-files: true
if-no-files-found: error
retention-days: 90
- name: Retain failed build plan without manufacturing a successful artifact
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: tasknotes-build-failure-${{ inputs.target }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-build/
include-hidden-files: true
if-no-files-found: warn
retention-days: 90
publish:
name: Protected immutable TaskNotes upload
needs: [inputs, build]
outputs:
ready: ${{ steps.compatibility.outputs.ready }}
runs-on: ubuntu-24.04
# Upload has a separate 7-minute bound; leave time for checks and recovery.
timeout-minutes: 60
defaults:
run:
working-directory: publisher
concurrency:
group: tasknotes-upload-${{ inputs.target }}
cancel-in-progress: false
# External environment policy admits main without per-publish approval.
environment:
name: ${{ inputs.target }}
url: ${{ inputs.target == 'production' && 'https://app.tasknotes.dev/' || 'https://staging.tasknotes.dev/' }}
env:
TARGET: ${{ inputs.target }}
SOURCE_SHA: ${{ inputs.source_sha }}
TASKNOTES_TRUST_ASSET_SHA256: ${{ vars.TASKNOTES_TRUST_ASSET_SHA256 }}
ARTIFACT_ID: ${{ needs.build.outputs.artifact-id }}
ARTIFACT_DIGEST: ${{ needs.build.outputs.artifact-digest }}
TASKNOTES_SOURCE_ROOT: ${{ github.workspace }}/candidate
WRANGLER_SEND_METRICS: "false"
steps:
# A recovery point must predate everything its run published.
- name: One publication per run; dispatch a new run to retry
timeout-minutes: 1
working-directory: ${{ github.workspace }}
run: test "$GITHUB_RUN_ATTEMPT" = 1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: publisher
fetch-depth: 0
persist-credentials: false
timeout-minutes: 3
- name: Workflow-owned ancestry check before candidate data is read
timeout-minutes: 1
env:
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/publisher/refs.mjs
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.source_sha }}
path: candidate
fetch-depth: 0
persist-credentials: false
timeout-minutes: 3
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
timeout-minutes: 2
- name: Workflow-owned guard; candidate is data only
timeout-minutes: 7
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/tasknotes-receipt" "$RUNNER_TEMP/tasknotes-upload"
node scripts/publisher/publisher.mjs guard > "$RUNNER_TEMP/tasknotes-receipt/plan.json"
- name: Isolated official tool lock only; no app hooks
timeout-minutes: 3
run: node scripts/publisher/tool.mjs "$RUNNER_TEMP/tasknotes-tool-path"
- name: Immutable artifact identity and full original inventory
timeout-minutes: 4
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/publisher/artifact.mjs "$RUNNER_TEMP/tasknotes-upload/artifact"
cp "$RUNNER_TEMP/tasknotes-upload/artifact/"{inventory.json,envelope.json} "$RUNNER_TEMP/tasknotes-receipt/"
cp "$RUNNER_TEMP/tasknotes-upload/artifact-metadata.json" "$RUNNER_TEMP/tasknotes-receipt/"
cmp "$RUNNER_TEMP/tasknotes-receipt/plan.json" "$RUNNER_TEMP/tasknotes-upload/artifact/plan.json"
node scripts/publisher/publisher.mjs inventory "$RUNNER_TEMP/tasknotes-upload/artifact/publish" "$RUNNER_TEMP/tasknotes-receipt/plan.json" > "$RUNNER_TEMP/tasknotes-receipt/revalidated-inventory.json"
cmp "$RUNNER_TEMP/tasknotes-receipt/inventory.json" "$RUNNER_TEMP/tasknotes-receipt/revalidated-inventory.json"
chmod -R a-w "$RUNNER_TEMP/tasknotes-upload/artifact"
- name: Existing project identity (never provision)
timeout-minutes: 1
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/publisher.mjs project > "$RUNNER_TEMP/tasknotes-receipt/project.json"
# Read-only: a missing project or credential scope refuses before any write.
- name: Existing self-hosted project identity (never provision)
if: needs.build.outputs.self-hosted == 'true'
timeout-minutes: 1
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/self-hosted.mjs project > /dev/null
- name: Live production contains the authenticated SDK producer
id: compatibility
timeout-minutes: 2
env:
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/publisher/compatibility.mjs "$RUNNER_TEMP/tasknotes-receipt/plan.json" "$RUNNER_TEMP/tasknotes-receipt/compatibility.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
timeout-minutes: 2
with:
name: tasknotes-compatibility-${{ inputs.target }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-receipt/compatibility.json
if-no-files-found: error
retention-days: 90
- name: Capture production recovery point before upload
if: steps.compatibility.outputs.ready == 'true'
timeout-minutes: 4
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/rollback.mjs snapshot "$RUNNER_TEMP/tasknotes-receipt"
# Stored before upload, so recovery survives a lost job or receipt.
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: inputs.target == 'production' && steps.compatibility.outputs.ready == 'true'
timeout-minutes: 2
with:
name: tasknotes-production-recovery-point-${{ github.run_id }}
path: ${{ runner.temp }}/tasknotes-receipt/previous.json
if-no-files-found: error
retention-days: 90
- name: Drill requires the exact source already live before upload
if: inputs.drill && steps.compatibility.outputs.ready == 'true'
timeout-minutes: 1
env:
DRILL: ${{ inputs.drill && 'true' || 'false' }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/drill.mjs before-upload "$RUNNER_TEMP/tasknotes-receipt"
- name: Recheck immutable inventory and upload once
id: upload
if: steps.compatibility.outputs.ready == 'true'
timeout-minutes: 7
env:
GITHUB_TOKEN: ${{ github.token }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
node scripts/publisher/refs.mjs
branch=$(jq -er .pagesBranch "$RUNNER_TEMP/tasknotes-receipt/plan.json")
node scripts/publisher/publisher.mjs assert-inventory "$RUNNER_TEMP/tasknotes-upload/artifact/publish" "$RUNNER_TEMP/tasknotes-receipt/inventory.json"
cli=$(cat "$RUNNER_TEMP/tasknotes-tool-path")
cd "$RUNNER_TEMP/tasknotes-upload"
node "$cli" pages deploy artifact/publish --no-bundle --project-name tasknotes-app --branch "$branch" --commit-hash "$SOURCE_SHA" --commit-dirty=false > "$RUNNER_TEMP/tasknotes-upload/wrangler-output.txt" 2>&1
- name: Resolve actual full deployment UUID before served checks
id: deployment
timeout-minutes: 3
if: always() && steps.compatibility.outputs.ready == 'true' && (steps.upload.outcome == 'success' || steps.upload.outcome == 'failure' || steps.upload.outcome == 'cancelled')
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/publisher.mjs capture "$RUNNER_TEMP/tasknotes-upload/wrangler-output.txt" > "$RUNNER_TEMP/tasknotes-receipt/deployment.json"
- name: All deployment URL AND alias bytes, source-owned headers and routes
id: verification
timeout-minutes: 9
if: always() && steps.compatibility.outputs.ready == 'true' && steps.deployment.outcome == 'success'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
DRILL: ${{ inputs.drill && 'true' || 'false' }}
run: |
set -euo pipefail
node scripts/publisher/hosting.mjs "$RUNNER_TEMP/tasknotes-receipt/plan.json" "$RUNNER_TEMP/tasknotes-receipt/inventory.json" "$RUNNER_TEMP/tasknotes-receipt/deployment.json" "$RUNNER_TEMP/tasknotes-upload/artifact" > "$RUNNER_TEMP/tasknotes-receipt/verification.json"
if [ "$DRILL" = true ]; then node scripts/publisher/drill.mjs uploaded "$RUNNER_TEMP/tasknotes-receipt"; fi
- name: Preserve honest failure or complete static-publication receipt
timeout-minutes: 1
if: always() && steps.compatibility.outputs.ready == 'true'
run: |
if [ -f "$RUNNER_TEMP/tasknotes-upload/artifact-metadata.json" ]; then cp "$RUNNER_TEMP/tasknotes-upload/artifact-metadata.json" "$RUNNER_TEMP/tasknotes-receipt/"; fi
node scripts/publisher/publisher.mjs receipt "$RUNNER_TEMP/tasknotes-receipt" > "$RUNNER_TEMP/tasknotes-receipt/receipt.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
timeout-minutes: 2
if: always()
with:
name: tasknotes-receipt-${{ inputs.target }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-receipt/
include-hidden-files: true
if-no-files-found: warn
retention-days: 90
smoke:
name: TaskNotes fresh-browser smoke
needs: publish
if: needs.publish.outputs.ready == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 25
# No environment, Cloudflare credentials, candidate checkout or app install.
env:
SOURCE_SHA: ${{ inputs.source_sha }}
TARGET: ${{ inputs.target }}
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.tasknotes-smoke-browsers
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Isolated pinned browser tool with install scripts disabled
timeout-minutes: 15
run: |
set -euo pipefail
node scripts/publisher/tool.mjs "$RUNNER_TEMP/tasknotes-smoke-tool" smoke
module=$(cat "$RUNNER_TEMP/tasknotes-smoke-tool")
node "$(dirname "$module")/cli.js" install --with-deps chromium
- name: Fresh load, source entry asset, readiness and first screen
timeout-minutes: 3
run: node scripts/publisher/smoke.mjs "$RUNNER_TEMP/tasknotes-smoke-tool" "$RUNNER_TEMP/tasknotes-smoke.json"
- name: Read this run's verified upload receipt for the manual drill
if: inputs.drill && inputs.target == 'production' && github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
run: gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name "tasknotes-receipt-production-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" --dir "$RUNNER_TEMP/tasknotes-drill"
- name: Deliberate smoke failure after real same-source production upload
if: inputs.drill && inputs.target == 'production' && github.event_name == 'workflow_dispatch'
env:
DRILL: ${{ inputs.drill && 'true' || 'false' }}
run: node scripts/publisher/drill.mjs fail "$RUNNER_TEMP/tasknotes-drill" "$RUNNER_TEMP/tasknotes-drill.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always() && inputs.drill
with:
name: tasknotes-production-drill-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-drill.json
if-no-files-found: warn
retention-days: 90
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: ${{ inputs.target }}-smoke-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-smoke.json
if-no-files-found: warn
retention-days: 90
self-hosted:
name: Protected immutable self-hosted TaskNotes upload
needs: [inputs, build, publish, smoke]
# After the managed app is published and smoked. A failure here fails the
# run and restores only the self-hosted project; app.tasknotes.dev stays.
if: inputs.target == 'production' && needs.build.outputs.self-hosted == 'true' && needs.smoke.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 45
defaults:
run:
working-directory: publisher
concurrency:
group: tasknotes-self-hosted-upload
cancel-in-progress: false
environment:
name: production
deployment: false
env:
TARGET: ${{ inputs.target }}
SOURCE_SHA: ${{ inputs.source_sha }}
TASKNOTES_TRUST_ASSET_SHA256: ${{ vars.TASKNOTES_TRUST_ASSET_SHA256 }}
ARTIFACT_ID: ${{ needs.build.outputs.artifact-id }}
ARTIFACT_DIGEST: ${{ needs.build.outputs.artifact-digest }}
TASKNOTES_SOURCE_ROOT: ${{ github.workspace }}/candidate
WRANGLER_SEND_METRICS: "false"
steps:
- name: One publication per run; dispatch a new run to retry
timeout-minutes: 1
working-directory: ${{ github.workspace }}
run: test "$GITHUB_RUN_ATTEMPT" = 1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: publisher
fetch-depth: 0
persist-credentials: false
timeout-minutes: 3
- name: Workflow-owned ancestry check before candidate data is read
timeout-minutes: 1
env:
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/publisher/refs.mjs
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.source_sha }}
path: candidate
fetch-depth: 0
persist-credentials: false
timeout-minutes: 3
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
timeout-minutes: 2
- name: Workflow-owned guard; candidate is data only
timeout-minutes: 7
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/self-hosted-receipt" "$RUNNER_TEMP/self-hosted-upload"
node scripts/publisher/publisher.mjs guard > "$RUNNER_TEMP/self-hosted-receipt/plan.json"
test "$(node scripts/publisher/self-hosted.mjs planned)" = true
- name: Isolated official tool lock only; no app hooks
timeout-minutes: 3
run: node scripts/publisher/tool.mjs "$RUNNER_TEMP/self-hosted-tool-path"
- name: Immutable artifact identity and full self-hosted inventory
timeout-minutes: 4
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
artifact="$RUNNER_TEMP/self-hosted-upload/artifact"
node scripts/publisher/artifact.mjs "$artifact"
cp "$RUNNER_TEMP/self-hosted-upload/artifact-metadata.json" "$RUNNER_TEMP/self-hosted-receipt/"
cmp "$RUNNER_TEMP/self-hosted-receipt/plan.json" "$artifact/plan.json"
cp "$artifact/self-hosted/inventory.json" "$RUNNER_TEMP/self-hosted-receipt/inventory.json"
node scripts/publisher/self-hosted.mjs inventory "$artifact/self-hosted/publish" > "$RUNNER_TEMP/self-hosted-receipt/revalidated-inventory.json"
cmp "$RUNNER_TEMP/self-hosted-receipt/inventory.json" "$RUNNER_TEMP/self-hosted-receipt/revalidated-inventory.json"
chmod -R a-w "$artifact"
- name: Existing self-hosted project identity (never provision)
timeout-minutes: 1
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/self-hosted.mjs project > "$RUNNER_TEMP/self-hosted-receipt/project.json"
- name: Capture self-hosted recovery point before upload
id: snapshot
timeout-minutes: 2
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/self-hosted.mjs snapshot > "$RUNNER_TEMP/self-hosted-receipt/previous.json"
- name: Recheck immutable inventory and upload once
id: upload
timeout-minutes: 7
env:
GITHUB_TOKEN: ${{ github.token }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
node scripts/publisher/refs.mjs
node scripts/publisher/self-hosted.mjs assert-inventory "$RUNNER_TEMP/self-hosted-upload/artifact/self-hosted/publish" "$RUNNER_TEMP/self-hosted-receipt/inventory.json"
cli=$(cat "$RUNNER_TEMP/self-hosted-tool-path")
cd "$RUNNER_TEMP/self-hosted-upload"
node "$cli" pages deploy artifact/self-hosted/publish --no-bundle --project-name tasknotes-self-hosted --branch main --commit-hash "$SOURCE_SHA" --commit-dirty=false > "$RUNNER_TEMP/self-hosted-upload/wrangler-output.txt" 2>&1
- name: Resolve actual full deployment UUID before served checks
id: deployment
timeout-minutes: 3
if: always() && (steps.upload.outcome == 'success' || steps.upload.outcome == 'failure' || steps.upload.outcome == 'cancelled')
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/self-hosted.mjs capture "$RUNNER_TEMP/self-hosted-upload/wrangler-output.txt" > "$RUNNER_TEMP/self-hosted-receipt/deployment.json"
- name: All deployment URL AND alias bytes and source-owned headers
id: verification
# Three minutes on the immutable URL, then the 15-minute alias settle window.
timeout-minutes: 20
if: always() && steps.deployment.outcome == 'success'
run: node scripts/publisher/self-hosted.mjs verify "$RUNNER_TEMP/self-hosted-receipt" > "$RUNNER_TEMP/self-hosted-receipt/verification.json"
- name: Restore the previous self-hosted deployment; keep run failed
if: always() && steps.snapshot.outcome == 'success' && steps.upload.outcome != 'skipped' && steps.verification.outcome != 'success'
timeout-minutes: 7
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/self-hosted.mjs recover "$RUNNER_TEMP/self-hosted-receipt"
- name: Preserve honest failure or complete self-hosted receipt
timeout-minutes: 1
if: always()
run: node scripts/publisher/self-hosted.mjs receipt "$RUNNER_TEMP/self-hosted-receipt" > "$RUNNER_TEMP/self-hosted-receipt/receipt.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
timeout-minutes: 2
if: always()
with:
name: tasknotes-self-hosted-receipt-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/self-hosted-receipt/
include-hidden-files: true
if-no-files-found: warn
retention-days: 90
production-recovery:
name: Restore production after incomplete publication or smoke
needs: [publish, smoke]
# A job-level always() still runs after cancellation or a job timeout.
if: always() && inputs.target == 'production' && needs.publish.result != 'skipped' && needs.smoke.result != 'success' && needs.publish.outputs.ready != 'false'
runs-on: ubuntu-24.04
timeout-minutes: 20
environment: production
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
timeout-minutes: 3
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
timeout-minutes: 2
- name: Find the recovery point stored before upload
id: point
timeout-minutes: 1
env:
GH_TOKEN: ${{ github.token }}
DEPLOY_RESULT: ${{ needs.publish.result }}
run: |
set -euo pipefail
id=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?name=tasknotes-production-recovery-point-$GITHUB_RUN_ID" --jq '[.artifacts[]|select(.expired|not)]|first|.id // empty')
if [ -z "$id" ] && [ "$DEPLOY_RESULT" = success ]; then
echo 'A completed publication has no recovery point' >&2
exit 1
fi
echo "artifact-id=$id" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
if: steps.point.outputs.artifact-id != ''
timeout-minutes: 2
with:
artifact-ids: ${{ steps.point.outputs.artifact-id }}
path: ${{ runner.temp }}/tasknotes-recovery
merge-multiple: true
- name: Restore snapshot and verify every previous asset; keep run failed
if: steps.point.outputs.artifact-id != ''
timeout-minutes: 7
env:
SOURCE_SHA: ${{ inputs.source_sha }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node scripts/publisher/rollback.mjs recover "$RUNNER_TEMP/tasknotes-recovery"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
timeout-minutes: 2
if: always() && steps.point.outputs.artifact-id != ''
with:
name: tasknotes-production-recovery-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/tasknotes-recovery/
if-no-files-found: warn
retention-days: 90