Repository navigation
459 lines (450 loc) · 22.7 KB
/
Copy pathdeploy.yml
File metadata and controls
459 lines (450 loc) · 22.7 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
# SPDX-FileCopyrightText: 2026 Anton Wiklund and Solid Memo contributors
#
# SPDX-License-Identifier: MIT
name: Deploy to GitHub Pages
# The site, the newest released version only (docs/deployment.md): when
# CI has passed on a push to main, the commit it checked, if a version
# tag (vX.Y.Z, which release.yml pushes with the release commit) names
# it, as the site CI built and tested, given the version's number; or,
# run by hand from main, the newest version, built here after npm run
# check. Either way, only if the tag is the newest version on main, names
# that version's release commit, and has its GitHub release. Other
# commits on main are not deployed, and neither is an older version: the
# site always runs the newest version the releases page lists, and its
# docs are that version's only.
# CI also runs on pull requests, a fork's included, and a fork's branch
# may be named main too: workflow_run's branch filter matches that name,
# so the job checks that CI ran for a push, in this repository.
on:
workflow_run: # zizmor: ignore[dangerous-triggers] the jobs act only on CI's push runs on main, in this repository
workflows: [CI]
types: [completed]
branches: [main]
workflow_dispatch:
# What every job may read. Only the jobs that publish to GitHub Pages
# may write to it, each saying so: a job's permissions replace these.
permissions:
contents: read
# To download the user journeys' report from the CI run.
actions: read
# A deploy waiting its turn is replaced by a newer one in its group. Only
# a run that may deploy (one by hand, or one after CI on a release
# commit) shares the group pages, so a newer run that deploys nothing
# cannot replace a release's; any other run has a group of its own. A
# re-run after CI on an older release commit shares it too, as nothing
# tells it apart before it runs: it deploys nothing, so if it replaced
# a newer release's deploy waiting its turn, run the deploy by hand.
concurrency:
group: >-
${{ (github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
startsWith(github.event.workflow_run.head_commit.message, 'chore(release): ')))
&& 'pages' || format('pages-{0}', github.run_id) }}
cancel-in-progress: false
jobs:
# The commit to deploy: a released version's, or none.
version:
if: >-
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.head_repository.full_name == github.repository)
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
sha: ${{ steps.release.outputs.sha }}
parent: ${{ steps.release.outputs.parent }}
tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
# release.yml pushes the tag just after the release commit, and CI on
# that commit takes minutes, so the tag is there by now; for a release
# commit, the fetch is tried a few times in case it is not yet. Only
# a plain version tag (vX.Y.Z) counts, and by hand only one on main.
- name: A version tag names the commit
id: tag
env:
EVENT: ${{ github.event_name }}
SHA: ${{ github.event.workflow_run.head_sha }}
RELEASE: "${{ startsWith(github.event.workflow_run.head_commit.message, 'chore(release): ') }}"
run: |
for _ in 1 2 3 4 5 6; do
git fetch --force --tags --quiet origin
if [ "$EVENT" = workflow_dispatch ]; then
tag=$(git tag --merged HEAD --list 'v[0-9]*' --sort=-v:refname |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
else
tag=$(git tag --points-at "$SHA" --list 'v[0-9]*' |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
fi
[ -n "$tag" ] && break
[ "$EVENT" = workflow_dispatch ] && break
[ "$RELEASE" = true ] || break
sleep 20
done
if [ -z "$tag" ]; then
echo "::notice::No version tag names this commit, so the site is not deployed (docs/deployment.md)."
exit 0
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
# Node, for the next step's script, which imports no package; not
# npm's cache, as nothing is installed.
- if: steps.tag.outputs.tag != ''
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
package-manager-cache: false
# The tag alone does not make a release: it must be the newest
# version on main, so a re-run of CI or of this workflow on an older
# release commit cannot put that version back; its commit must be
# the release commit of that version, one semantic-release made
# (npm run release:commit, scripts/releaseCommit.ts: on main's
# first-parent chain, its subject the version's, by
# github-actions[bot], changing only the files a release writes), so
# a tag put on another commit by hand, such as a pull request's
# commit titled as a release, is not deployed; and its GitHub
# release must be made, so the site never runs a version the
# releases page does not list.
# semantic-release makes the release seconds after it pushes the
# tag, so it is looked for a few times. A version that is not the
# newest is a notice; anything else fails the run, as it should not
# happen (docs/deployment.md).
- name: The tag is the newest release
id: release
if: steps.tag.outputs.tag != ''
env:
TAG: ${{ steps.tag.outputs.tag }}
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
git fetch --force --quiet origin main
newest=$(git tag --merged FETCH_HEAD --list 'v[0-9]*' --sort=-v:refname |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
if [ "$TAG" != "$newest" ]; then
echo "::notice::$TAG is not the newest version on main (${newest:-none} is), so the site is not deployed (docs/deployment.md)."
exit 0
fi
RELEASE_MAIN=FETCH_HEAD npm run release:commit -- tag "$TAG"
sha=$(git rev-parse --verify "refs/tags/$TAG^{commit}")
for _ in 1 2 3 4 5 6; do
draft=$(gh release view "$TAG" --json isDraft --jq .isDraft 2>/dev/null || true)
[ "$draft" = false ] && break
sleep 10
done
if [ "$draft" != false ]; then
echo "::error::$TAG has no GitHub release, so the site is not deployed: make it, then deploy by hand (docs/releasing.md#when-a-release-fails)."
exit 1
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
echo "parent=$(git rev-parse "$sha^")" >> "$GITHUB_OUTPUT"
echo "Deploying $TAG."
build:
needs: version
if: needs.version.outputs.sha != ''
runs-on: ubuntu-latest
permissions:
contents: read
# To download the site from the CI run on the release commit.
actions: read
# To check the site's attestation (gh attestation verify).
attestations: read
# To set up GitHub Pages, before the artifact is uploaded.
pages: write
# A run by hand checks and builds first, with no Turbo cache: as long
# as CI's check and site jobs, with room for Ubuntu's mirror to stall
# (actions/playwright-deps gives each apt-get four tries of three
# minutes).
timeout-minutes: 42
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.version.outputs.sha }}
persist-credentials: false
# Nothing in this job comes from GitHub's cache, as the site it
# deploys is made or stated here (docs/deployment.md#the-build-ci-tested):
# any job on main can write main's cache entries. npm's cache neither,
# which setup-node would restore for packageManager in package.json.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
package-manager-cache: false
# No package's install script runs (docs/vendor-code.md#installing),
# though the release checked out may predate the root .npmrc.
- run: npm ci --ignore-scripts
# After CI on the release commit, the site that run carries (its site
# artifact): the build of the tree the merge queue tested, and the
# user journeys ran on, which its reuse job took over, or its own
# site job's when it ran every job. That build came before the
# release wrote its version, so the version is put in its pages, the
# one place it is stated (npm run site:version); its scripts, and
# the commit it names, stay as tested (docs/deployment.md). A version
# from before (no siteVersion.ts) has no such artifact, and is built
# here, as it was then. The artifact is unpacked outside the checkout,
# as the journeys' report is below, so none of its files can stand in
# for one of the checkout's that a later step runs; only once it is
# stated does it go where the build would have written it.
- if: github.event_name == 'workflow_run' && hashFiles('scripts/siteVersion.ts') != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: site
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
path: ${{ runner.temp }}/site/
# The artifact is shipped only as CI's site job built it: its
# manifest, made again here as that job made it, must be attested
# by CI's workflow in the merge queue or on main, for the release
# commit or its parent (docs/deployment.md#the-build-ci-tested).
# Only the site job may attest, so a site any other job of a run
# uploaded in its place, or an older one, is refused. A version
# released before sites were attested fails here: deploy it by hand,
# which builds it.
- name: The site is the one CI's site job attested
if: github.event_name == 'workflow_run' && hashFiles('scripts/siteVersion.ts') != ''
env:
SITE: ${{ runner.temp }}/site
SHA: ${{ needs.version.outputs.sha }}
PARENT: ${{ needs.version.outputs.parent }}
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
manifest="$RUNNER_TEMP/site.sha256"
(cd "$SITE" && find . ! -type d -print0 | LC_ALL=C sort -z | xargs -0r sha256sum) > "$manifest"
for digest in "$SHA" "$PARENT"; do
if gh attestation verify "$manifest" --repo "$GH_REPO" \
--cert-identity-regex "^https://github\.com/$GH_REPO/\.github/workflows/ci\.yml@refs/heads/(main|gh-readonly-queue/main/.+)\$" \
--source-digest "$digest" --deny-self-hosted-runners > /dev/null; then
echo "The site is the one CI's site job attested on $digest."
exit 0
fi
done
echo "::error::The site artifact matches no attestation of CI's site job on $SHA or its parent, so it is not deployed (docs/deployment.md#the-build-ci-tested)."
exit 1
- if: github.event_name == 'workflow_run' && hashFiles('scripts/siteVersion.ts') != ''
env:
SITE: ${{ runner.temp }}/site
run: |
npm run site:version -- "$SITE"
mv "$SITE" apps/web/dist
# A run by hand has no CI run behind it, so it checks the version and
# builds it. Chromium, which npm run check and npm run build draw the
# docs' Mermaid diagrams in (docs/markdown.md), downloaded and
# checked against a committed SHA-256, with its system libraries
# from Ubuntu's signed mirror, not restored from the cache. The
# action is the checked-out version's: one from before the drawings
# has none, and needs none; every version since 6.17.3 takes the
# cache input, and only the newest is deployed.
- if: >-
(github.event_name == 'workflow_dispatch' || hashFiles('scripts/siteVersion.ts') == '') &&
hashFiles('.github/actions/chromium/action.yml') != ''
uses: ./.github/actions/chromium
with:
cache: false
- if: github.event_name == 'workflow_dispatch'
run: npm run check
- if: github.event_name == 'workflow_dispatch' || hashFiles('scripts/siteVersion.ts') == ''
run: npm run build
# The artifact is the whole site: the app, and beside it what the
# build writes: ns/, decks/, the vendored shapes, robots.txt, the
# sitemap, the Client ID Document and the docs (docs/deployment.md).
# The user journeys' report is not in it: the journeys job publishes
# it on a site of its own.
# robots.txt always, and the sitemap whenever CNAME names a domain
# (docs/deployment.md#custom-domain-optional), the Client ID Document
# too, as logins on that domain name it (docs/authentication.md); the
# docs, with their diagrams drawn and the font's license beside them
# (docs/markdown.md), so a build under DOCS_DIAGRAMS=skip is not
# deployed. Each only when the checked-out version's build writes it:
# a version from before (no siteMap.ts, no clientId.ts, no
# publishDocs.ts, in packages/site/ or before that in vocab's and
# markdown's tooling/) can still be deployed.
- name: The vocabulary, the deck library, robots.txt, the sitemap, the Client ID Document and the docs are in the artifact
run: >-
test -f apps/web/dist/ns/vocab/v1.ttl && test -f apps/web/dist/decks/index.ttl
&& { { [ ! -f packages/site/src/siteMap.ts ] && [ ! -f packages/vocab/tooling/siteMap.ts ]; } || {
test -f apps/web/dist/robots.txt
&& { [ ! -s CNAME ] || test -f apps/web/dist/sitemap.xml; }; }; }
&& { [ ! -f packages/site/src/clientId.ts ] || [ ! -s CNAME ] || test -f apps/web/dist/clientid.jsonld; }
&& { { [ ! -f packages/site/src/publishDocs.ts ] && [ ! -f packages/markdown/tooling/publishDocs.ts ]; } || {
test -f apps/web/dist/docs/index.html
&& test -f apps/web/dist/docs/diagrams/OFL-Fredoka.txt
&& compgen -G 'apps/web/dist/docs/diagrams/*.svg' > /dev/null; }; }
- uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
with:
enablement: true
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: apps/web/dist
deploy:
needs: [version, build]
runs-on: ubuntu-latest
# To deploy the artifact to GitHub Pages, which proves the run is this
# workflow's with an OIDC token.
permissions:
contents: read
pages: write
id-token: write
timeout-minutes: 10
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Re-running only this job, or build and this job, of an older run
# skips the version job, so the version is looked up again here: a
# newer one released since stops the deploy.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
filter: blob:none
sparse-checkout: .github
persist-credentials: false
- name: The tag is still the newest version
env:
TAG: ${{ needs.version.outputs.tag }}
run: |
newest=$(git tag --merged origin/main --list 'v[0-9]*' --sort=-v:refname |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
if [ "$TAG" != "$newest" ]; then
echo "::error::$TAG is no longer the newest version on main ($newest is), so the site is not deployed (docs/deployment.md)."
exit 1
fi
- id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
# The user journeys' report of the CI run deployed from, its traces
# viewable step by step, published at journeys.solid-memo.com from the
# repository solid-memo/journeys (docs/deployment.md#the-journeys-report):
# a site of its own, so the report's scripts do not run on the app's
# origin. Each release replaces that repository's main with one commit,
# so it keeps only the newest report. A run by hand has no CI run, so no
# report.
journeys:
needs: [version, deploy]
if: github.event_name == 'workflow_run'
runs-on: ubuntu-latest
# To download the report from the CI run.
permissions:
contents: read
actions: read
timeout-minutes: 15
# Its secret is the journeys repository's deploy key, with write
# access; the environment admits only main.
environment:
name: journeys
url: https://journeys.solid-memo.com/
env:
JOURNEYS_REPO: solid-memo/journeys
JOURNEYS_HOST: journeys.solid-memo.com
steps:
# A copy without the key, such as a fork, publishes no report, and
# says so.
- name: The deploy key is set
id: key
env:
KEY: ${{ secrets.JOURNEYS_DEPLOY_KEY }}
run: |
if [ -z "$KEY" ]; then
echo "::notice::No JOURNEYS_DEPLOY_KEY secret (in the journeys environment), so the journeys' report is not published (docs/deployment.md#the-journeys-report)."
echo "set=false" >> "$GITHUB_OUTPUT"
else
echo "set=true" >> "$GITHUB_OUTPUT"
fi
# As in the deploy job: re-running this job alone of an older run
# must not put an older version's report back.
- if: steps.key.outputs.set == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
filter: blob:none
# .github for the tags, and what stands in for the trace viewer.
sparse-checkout: |
.github
e2e/journeys/report
persist-credentials: false
- name: The tag is still the newest version
if: steps.key.outputs.set == 'true'
env:
TAG: ${{ needs.version.outputs.tag }}
run: |
newest=$(git tag --merged origin/main --list 'v[0-9]*' --sort=-v:refname |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
if [ "$TAG" != "$newest" ]; then
echo "::error::$TAG is no longer the newest version on main ($newest is), so its journeys' report is not published (docs/deployment.md)."
exit 1
fi
- if: steps.key.outputs.set == 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: journeys-report
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
path: ${{ runner.temp }}/journeys
# Any job of the CI run could have uploaded the artifact in the
# report's place, so it is published only as plain files and
# folders, with no name that starts with a dot: no link, no git
# directory or attributes, nothing git or Pages reads as settings.
# Playwright's report has none, and the upload leaves hidden files
# out (docs/deployment.md#the-journeys-report). Checked before the
# key is on disk.
- name: The report is plain files
if: steps.key.outputs.set == 'true'
run: |
cd "$RUNNER_TEMP/journeys"
test -f index.html
odd="$(find . -mindepth 1 \( -name '.*' -o ! \( -type f -o -type d \) \) -print)"
if [ -n "$odd" ]; then
printf '%s\n' "$odd"
echo "::error::The journeys-report artifact holds a hidden entry or one that is neither a file nor a folder (listed above), so it is not published (docs/deployment.md#the-journeys-report)."
exit 1
fi
# The report, with the files Pages needs beside it: CNAME, which
# keeps the custom domain, .nojekyll, so Pages serves the files as
# they are, and robots.txt, which keeps search engines out. Its
# trace viewer is left out: the viewer opens a trace from any
# address, so e2e/journeys/report/trace/ stands in for it, sending
# the report's own traces on to trace.playwright.dev
# (docs/deployment.md#the-journeys-report). One
# commit with no parent, force-pushed over main. The key is written
# to a file for this step alone, which git's ssh reads, as in
# release.yml; GitHub's host keys come from its API. git keeps its
# repository in a folder of its own, not in the report, and runs
# no hooks and no file system monitor.
- name: Publish the report to the journeys repository
if: steps.key.outputs.set == 'true'
env:
KEY: ${{ secrets.JOURNEYS_DEPLOY_KEY }}
TAG: ${{ needs.version.outputs.tag }}
RUN_URL: ${{ github.event.workflow_run.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
ssh="$(mktemp -d "$RUNNER_TEMP/journeys-ssh.XXXXXX")"
trap 'rm -rf "$ssh"' EXIT
(umask 077 && printf '%s\n' "$KEY" > "$ssh/key")
unset KEY
gh api meta --jq '.ssh_keys[] | "github.com " + .' > "$ssh/known_hosts"
export GIT_SSH_COMMAND="ssh -i $ssh/key -o IdentitiesOnly=yes -o UserKnownHostsFile=$ssh/known_hosts -o StrictHostKeyChecking=yes"
GIT_DIR="$(mktemp -d "$RUNNER_TEMP/journeys-git.XXXXXX")"
export GIT_DIR GIT_WORK_TREE="$RUNNER_TEMP/journeys"
export GIT_CONFIG_COUNT=2
export GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0=/dev/null
export GIT_CONFIG_KEY_1=core.fsmonitor GIT_CONFIG_VALUE_1=false
cd "$GIT_WORK_TREE"
test -f index.html
rm -rf trace
cp -R "$GITHUB_WORKSPACE/e2e/journeys/report/trace" trace
echo "$JOURNEYS_HOST" > CNAME
touch .nojekyll
printf 'User-agent: *\nDisallow: /\n' > robots.txt
git init --quiet -b main
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit --quiet \
-m "chore: publish the journeys report of $TAG" \
-m "The user journeys' report of the CI run on $TAG in $GITHUB_REPOSITORY ($RUN_URL). Each release replaces main with one commit, so this repository keeps only the newest report."
git push --force "git@github.com:$JOURNEYS_REPO.git" main
echo "Published the journeys' report of $TAG at https://$JOURNEYS_HOST/."