Repository navigation
594 lines (555 loc) · 27.3 KB
/
Copy pathrelease.yml
File metadata and controls
594 lines (555 loc) · 27.3 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
# Copyright 2026 Parity Technologies (UK) Ltd.
# SPDX-License-Identifier: GPL-3.0-or-later
name: Release
# Promotes what <JOLLITY_DOTNS_DOMAIN>next.paseo has been serving onto
# <JOLLITY_DOTNS_DOMAIN>.paseo, with JOLLITY_DOTNS_DOMAIN the bare label in the
# repository variable of that name.
#
# A release rebuilds nothing. deploy.yml already built the paseo artifacts for
# the release name, published them at the staging name and cached their CIDs
# under release-cid-<sha>. This workflow restores those CIDs and repoints the
# release name's executable records at them, so the released bytes are exactly
# the bytes that were staged and tested.
#
# A product is not one contenthash. bulletin-deploy writes text records on the
# root name, a contenthash on `app.<name>`, and registers `worker.<name>` with
# its own CID. Promotion therefore sets those two content records and the root
# manifest, which carries the display name, the description and the
# trustedProducts grants. Nothing else writes that manifest on the release
# name.
#
# It runs every day at 09:00 UTC on main, on a pushed v* tag, and by hand.
# Without a version it releases the next patch of the latest v* release, and it
# skips when main is still the commit that release points at.
#
# The staged CIDs live in the Actions cache, which GitHub evicts after 7 days
# without a read. Release within a week of the main deploy, or re-run Deploy on
# the commit first: the restore fails closed rather than releasing something
# else.
#
# With product humanity, a dispatch promotes <HUMANITY_DOTNS_DOMAIN>next.paseo
# onto <HUMANITY_DOTNS_DOMAIN>.paseo instead, and only that, with
# HUMANITY_DOTNS_DOMAIN the bare label in the repository variable of that name.
# It reads the staged records live from the staging name, so it never expires,
# and it tags humanity-v<version>.
# Bump `version` in apps/humanity-app/package.json in a PR first, since it is
# the appVersion the records carry.
run-name: ${{ inputs.product == 'humanity' && format('Humanity Release {0} to {1}.paseo', inputs.version, vars.HUMANITY_DOTNS_DOMAIN) || format('Release {0}', inputs.version || (github.ref_type == 'tag' && github.ref_name) || 'next patch') }}
on:
push:
tags: ["v*"]
schedule:
- cron: "0 9 * * *"
workflow_dispatch:
inputs:
version:
description: "Version to release, such as 1.4.0. Empty releases the next Jollity patch, and Humanity needs one."
type: string
required: false
product:
description: "Product to release"
type: choice
default: jollity
options: [jollity, humanity]
permissions:
contents: write
concurrency:
group: release-paseo
cancel-in-progress: false
env:
# bulletin-deploy calls the network `paseo-next-v2`, and the dotns CLI rejects
# that name. Only dotns runs here.
DOTNS_ENV: paseo-v2
CAN_WRITE_VERSION: ${{ secrets.GIST_TOKEN != '' && vars.JOLLITY_VERSION_GIST_ID != '' }}
jobs:
version:
name: Resolve the version
if: inputs.product != 'humanity'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
skip: ${{ steps.version.outputs.skip }}
steps:
- name: Resolve the version
id: version
env:
GH_TOKEN: ${{ github.token }}
INPUT_VERSION: ${{ inputs.version }}
TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
run: |
VERSION="${INPUT_VERSION:-${TAG#v}}"
if [ -z "$VERSION" ]; then
LATEST=$(gh release list -R "$GITHUB_REPOSITORY" -L 100 --exclude-drafts --json tagName \
| jq -r '[.[].tagName | select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | sort_by(ltrimstr("v") | split(".") | map(tonumber)) | last // ""')
if [ -z "$LATEST" ]; then
echo "::error title=No previous release::No v* release to bump from. Run this by hand with a version."
exit 1
fi
RELEASED_SHA=$(gh api "repos/$GITHUB_REPOSITORY/commits/$LATEST" --jq .sha)
if [ "$RELEASED_SHA" = "$GITHUB_SHA" ]; then
echo "::notice title=Nothing to release::$LATEST already points at $GITHUB_SHA."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
IFS=. read -r MAJOR MINOR PATCH <<< "${LATEST#v}"
VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
fi
if ! printf '%s' "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error title=Bad version::'$VERSION' is not a semantic version, such as 1.4.0."
exit 1
fi
{
echo "version=$VERSION"
echo "tag=v$VERSION"
} >> "$GITHUB_OUTPUT"
release:
name: Promote to paseo
needs: version
if: needs.version.outputs.skip != 'true'
runs-on: ubuntu-latest
# A release records a deployment, so tools that watch deployments can
# announce it.
environment:
name: paseo
url: ${{ steps.release.outputs.url }}
steps:
- name: Resolve the released name
id: name
env:
DOTNS_DOMAIN: ${{ vars.JOLLITY_DOTNS_DOMAIN }}
run: |
if ! [[ "$DOTNS_DOMAIN" =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]]; then
echo "::error title=JOLLITY_DOTNS_DOMAIN is not a DotNS label::Set the JOLLITY_DOTNS_DOMAIN repo variable to the bare label the product deploys under, without a TLD."
exit 1
fi
echo "domain=${DOTNS_DOMAIN}.paseo" >> "$GITHUB_OUTPUT"
# Validates the shape and exports nothing. The CLI reports a malformed
# phrase only as "Unable to match provided value to a secret URI".
- name: Require the JOLLITY_DOTNS_MNEMONIC secret
env:
DEPLOY_MNEMONIC: ${{ secrets.JOLLITY_DOTNS_MNEMONIC }}
run: |
if [ -z "$DEPLOY_MNEMONIC" ]; then
echo "::error title=JOLLITY_DOTNS_MNEMONIC secret missing::Add the JOLLITY_DOTNS_MNEMONIC repo secret, the seed of the account that owns the released name."
exit 1
fi
WORDS=$(printf '%s' "$DEPLOY_MNEMONIC" | tr -d '\r' | wc -w | tr -d ' ')
case "$WORDS" in
12|15|18|21|24) ;;
*)
echo "::error title=DOTNS_MNEMONIC is not a mnemonic::The secret holds $WORDS whitespace-separated words, and the CLI needs a 12, 15, 18, 21 or 24-word BIP39 phrase."
exit 1
;;
esac
# The tree is read for deploy/constants.ts and scripts/sync-manifest.mts,
# never built.
- uses: actions/checkout@v7
- name: Restore the staged CIDs
uses: actions/cache/restore@v4
with:
path: .deploy-result/paseo-next-v2.json
key: release-cid-${{ github.sha }}
fail-on-cache-miss: true
- name: Read the staged CIDs
id: cids
env:
DOMAIN: ${{ steps.name.outputs.domain }}
run: |
cat .deploy-result/paseo-next-v2.json
APP_CID=$(jq -r '.cid // ""' .deploy-result/paseo-next-v2.json)
WORKER_CID=$(jq -r '.worker // ""' .deploy-result/paseo-next-v2.json)
STAGED=$(jq -r '.domain // ""' .deploy-result/paseo-next-v2.json)
VERSION=$(jq -r '.version // ""' .deploy-result/paseo-next-v2.json)
TIME=$(jq -r '.time // ""' .deploy-result/paseo-next-v2.json)
PRODUCT=$(jq -r '.product // ""' .deploy-result/paseo-next-v2.json)
if [ -z "$APP_CID" ]; then
echo "::error title=No app CID staged::The cached result carries no app CID, so re-run Deploy on this commit."
exit 1
fi
# The staged bundle must already name the release name, or the host
# derives the wrong product account and signing fails after the
# release looks successful.
if [ "$PRODUCT" != "$DOMAIN" ]; then
echo "::error title=Staged for the wrong product::${STAGED} was built as another product than the released name. Promoting it would break signing."
exit 1
fi
{
echo "app=$APP_CID"
echo "worker=$WORKER_CID"
echo "staged=$STAGED"
echo "appversion=$VERSION"
echo "apptime=$TIME"
} >> "$GITHUB_OUTPUT"
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
check-latest: true
- name: Install the dotns CLI
run: npm install -g @parity/dotns-cli
# One step, so the seed is normalised once and held by one step only.
# DOTNS_MNEMONIC is the CLI's own variable for the phrase. The manifest
# carries the same grants deploy.yml publishes on the staging name.
- name: Point the released name at the staged CIDs
env:
DEPLOY_MNEMONIC: ${{ secrets.JOLLITY_DOTNS_MNEMONIC }}
DOTNS_DOMAIN: ${{ vars.JOLLITY_DOTNS_DOMAIN }}
TRUSTED_PRODUCTS: ${{ vars.JOLLITY_TRUSTED_PRODUCTS }}
DOMAIN: ${{ steps.name.outputs.domain }}
APP_CID: ${{ steps.cids.outputs.app }}
WORKER_CID: ${{ steps.cids.outputs.worker }}
run: |
# The manifest is rewritten whole, so an unset variable would strip
# every grant the released name holds. Write {} to grant nothing.
if [ -z "$TRUSTED_PRODUCTS" ]; then
echo "::error title=JOLLITY_TRUSTED_PRODUCTS variable missing::Set the JOLLITY_TRUSTED_PRODUCTS repo variable to the grants of the released name, or {} for none."
exit 1
fi
DOTNS_MNEMONIC=$(printf '%s' "$DEPLOY_MNEMONIC" | tr -d '\r' \
| sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' \
-e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'\$/\1/")
echo "::add-mask::$DOTNS_MNEMONIC"
export DOTNS_MNEMONIC
dotns content set "app.${DOMAIN}" "$APP_CID" --env "$DOTNS_ENV"
if [ -n "$WORKER_CID" ]; then
dotns content set "worker.${DOMAIN}" "$WORKER_CID" --env "$DOTNS_ENV"
else
echo "::warning title=Worker not promoted::No worker CID was staged, so the released name keeps its previous chat extension."
fi
DEPLOY_TRUSTED_PRODUCTS=$(jq -cn --argjson base "$TRUSTED_PRODUCTS" --arg staging "${DOTNS_DOMAIN}next" '$base + {($staging): ["context"]}')
export DEPLOY_TRUSTED_PRODUCTS
# sync-manifest emits nothing when the manifests match, and fails
# rather than writing when the name carries no manifest to build on.
dotns text view "$DOMAIN" manifest --env "$DOTNS_ENV" --json > manifest-published.json
npx --yes tsx scripts/sync-manifest.mts < manifest-published.json > manifest-next.json
if [ -s manifest-next.json ]; then
cat manifest-next.json
dotns text set "$DOMAIN" manifest --env "$DOTNS_ENV" < manifest-next.json
else
echo "The published manifest already matches deploy/constants.ts."
fi
# The promoted bytes are the staged bundle, so the released name's
# version is the staged result's APP_VERSION and its time. Never fails
# the release.
- name: Publish the released version for running apps
if: env.CAN_WRITE_VERSION == 'true' && steps.cids.outputs.appversion != '' && steps.cids.outputs.apptime != ''
continue-on-error: true
env:
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
GIST_ID: ${{ vars.JOLLITY_VERSION_GIST_ID }}
GIST_FILE: ${{ vars.JOLLITY_DOTNS_DOMAIN }}-version.json
KEY: ${{ steps.name.outputs.domain }}
VERSION: ${{ steps.cids.outputs.appversion }}
TIME: ${{ steps.cids.outputs.apptime }}
run: node scripts/ci/merge-version-gist.mjs
# Generated notes start at the most recent release of any tag, so start
# them at this product's own previous one. Never blocks the release.
- name: Find the previous release
id: previous
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.version.outputs.tag }}
run: |
prev=$(gh release list -R "$GITHUB_REPOSITORY" -L 100 --exclude-drafts --json tagName \
| jq -r --arg tag "$TAG" '[.[].tagName | select(test("^v[0-9]") and . != $tag)][0] // ""')
echo "Notes start at ${prev:-the first release}"
echo "tag=$prev" >> "$GITHUB_OUTPUT"
- name: Create the release
id: release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.tag }}
name: Jollity ${{ needs.version.outputs.version }}
generate_release_notes: true
previous_tag: ${{ steps.previous.outputs.tag }}
append_body: true
body: |
### Deployment
| | |
|---|---|
| Version | `${{ needs.version.outputs.version }}` |
| Domain | `${{ steps.name.outputs.domain }}` |
| Staged at | `${{ steps.cids.outputs.staged }}` |
| App CID | `${{ steps.cids.outputs.app }}` |
| Worker CID | `${{ steps.cids.outputs.worker }}` |
| Browser | https://${{ steps.name.outputs.domain }}.li |
Open `${{ steps.name.outputs.domain }}` in the Polkadot app. To roll back, re-run
`dotns content set` with a prior release's CIDs.
- name: Release summary
env:
VERSION: ${{ needs.version.outputs.version }}
DOMAIN: ${{ steps.name.outputs.domain }}
STAGED: ${{ steps.cids.outputs.staged }}
APP_CID: ${{ steps.cids.outputs.app }}
WORKER_CID: ${{ steps.cids.outputs.worker }}
run: |
{
echo "### ${DOMAIN} ${VERSION}"
echo ""
echo "Promoted from \`${STAGED}\`"
echo "App CID \`${APP_CID}\`"
echo "Worker CID \`${WORKER_CID}\`"
echo "Browser https://${DOMAIN}.li"
} >> "$GITHUB_STEP_SUMMARY"
humanity:
name: Promote to ${{ vars.HUMANITY_DOTNS_DOMAIN }}.paseo
if: github.event_name == 'workflow_dispatch' && inputs.product == 'humanity'
runs-on: ubuntu-latest
environment: humanity-paseo-next-v2
permissions:
contents: write
actions: read
env:
LABEL: ${{ vars.HUMANITY_DOTNS_DOMAIN }}
DOMAIN: ${{ vars.HUMANITY_DOTNS_DOMAIN }}.paseo
STAGED: ${{ vars.HUMANITY_DOTNS_DOMAIN }}next.paseo
DOTNS_CLI_VERSION: 1.1.0
steps:
- name: Require the HUMANITY_DOTNS_DOMAIN variable
run: |
if ! [[ "$LABEL" =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]]; then
echo "::error title=HUMANITY_DOTNS_DOMAIN is not a DotNS label::Set the HUMANITY_DOTNS_DOMAIN repo variable to the bare label Humanity deploys under, without a TLD."
exit 1
fi
- name: Resolve the version
id: version
env:
VERSION: ${{ inputs.version }}
run: |
if ! printf '%s' "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error title=Bad version::'$VERSION' is not a semantic version, such as 0.24.0. A Humanity release needs one."
exit 1
fi
echo "tag=humanity-v${VERSION}" >> "$GITHUB_OUTPUT"
# The staged records come from the last Deploy run on main whose
# "Humanity paseo staging" job passed, and that commit is what the
# release tags. A run still publishing may be halfway through rewriting
# the staged name, so the release refuses until it is done.
- name: Find the staged commit
id: staged
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -euo pipefail
if gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG}" >/dev/null 2>&1; then
echo "::error title=Already released::${TAG} exists. Pick the next version."
exit 1
fi
jobs_of() { gh api "repos/${GITHUB_REPOSITORY}/actions/runs/$1/jobs?per_page=100" --jq "$2"; }
sha=""
while read -r id status head; do
if [ "$status" != "completed" ]; then
busy=$(jobs_of "$id" "[.jobs[] | select((.name == \"Humanity sources\" or .name == \"Humanity paseo staging\") and .status != \"completed\")] | length")
if [ "$busy" != "0" ]; then
echo "::error title=Staging is being published::Deploy run $id on main may still be writing $STAGED. Wait for it, then run the release again."
exit 1
fi
fi
staged=$(jobs_of "$id" "[.jobs[] | select(.name == \"Humanity paseo staging\" and .conclusion == \"success\")] | length")
if [ "$staged" != "0" ]; then
sha=$head
break
fi
done < <(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/deploy.yml/runs?branch=main&per_page=100" \
--jq '.workflow_runs[] | "\(.id) \(.status) \(.head_sha)"')
if [ -z "$sha" ]; then
echo "::error title=Nothing staged::No Deploy run on main has published $STAGED in its last 100 runs."
exit 1
fi
echo "Staged from $sha"
# main requires no checks, so a red merge still stages, and it must
# not reach the released name.
green=0
for run in $(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/ci.yml/runs?head_sha=${sha}&per_page=20" --jq '.workflow_runs[].id'); do
n=$(jobs_of "$run" '[.jobs[] | select(.name == "Humanity" and .conclusion == "success")] | length')
green=$((green + n))
done
if [ "$green" = "0" ]; then
echo "::error title=Staged commit not green::The Humanity job of CI has not passed on $sha (still running, failed or cancelled). Wait for it, re-run CI on main, or fix main and stage again."
exit 1
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
- name: Require the HUMANITY_DOTNS_MNEMONIC secret
env:
MNEMONIC: ${{ secrets.HUMANITY_DOTNS_MNEMONIC }}
run: |
if [ -z "$MNEMONIC" ]; then
echo "::error title=HUMANITY_DOTNS_MNEMONIC secret missing::Add the HUMANITY_DOTNS_MNEMONIC repo secret, the seed of the account that owns $DOMAIN and $STAGED."
exit 1
fi
WORDS=$(printf '%s' "$MNEMONIC" | tr -d '\r' | wc -w | tr -d ' ')
case "$WORDS" in
12|15|18|21|24) ;;
*) echo "::error title=Not a mnemonic::The secret holds $WORDS words, and the CLI needs a 12, 15, 18, 21 or 24-word BIP39 phrase."; exit 1 ;;
esac
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
check-latest: true
- name: Install the dotns CLI ${{ env.DOTNS_CLI_VERSION }}
run: npm install -g "@parity/dotns-cli@${DOTNS_CLI_VERSION}"
# Every record is read before anything is written, with what
# the released name held before, which is the rollback.
- name: Read the staged and the current records
id: read
run: |
set -euo pipefail
mkdir -p records
for side in "$STAGED" "$DOMAIN"; do
for sub in "" "app." "worker."; do
dotns content view "${sub}${side}" --env "$DOTNS_ENV" --json > "records/${sub}${side}.content.json"
done
dotns text view "$side" manifest --env "$DOTNS_ENV" --json > "records/${side}.manifest.json"
dotns text view "app.$side" executable --env "$DOTNS_ENV" --json > "records/app.${side}.executable.json"
dotns text view "worker.$side" executable --env "$DOTNS_ENV" --json > "records/worker.${side}.executable.json"
done
head -c 2000 records/*.json
cid() { jq -r '.cid // ""' "records/$1.content.json"; }
APP=$(cid "app.$STAGED"); WORKER=$(cid "worker.$STAGED"); ROOT=$(cid "$STAGED")
if [ -z "$APP" ] || [ -z "$WORKER" ]; then
echo "::error title=Nothing staged::$STAGED has no app or worker CID. Publish to staging first (push to main, or run Deploy)."
exit 1
fi
if [ "$ROOT" != "$APP" ]; then
echo "::error title=Staging is half-published::$STAGED serves $ROOT but app.$STAGED holds $APP. Run Deploy again."
exit 1
fi
{
echo "app=$APP"
echo "worker=$WORKER"
echo "prev_app=$(cid "app.$DOMAIN")"
echo "prev_worker=$(cid "worker.$DOMAIN")"
echo "app_version=$(jq -r '.value' "records/app.${STAGED}.executable.json" | jq -r '.appVersion | join(".")')"
} >> "$GITHUB_OUTPUT"
- name: Compare the staged app version with the release version
env:
STAGED_VERSION: ${{ steps.read.outputs.app_version }}
VERSION: ${{ inputs.version }}
run: |
if [ "$STAGED_VERSION" != "$VERSION" ]; then
echo "::warning title=Version differs::The staged bundle reports appVersion $STAGED_VERSION (apps/humanity-app/package.json) but this release is $VERSION. Bump the package version in a PR before the next release."
fi
- name: Plan
run: |
set -euo pipefail
plan() {
if [ "$2" = "$3" ]; then printf '| %s | unchanged |\n' "$1"
else printf "| %s | \`%s\` to \`%s\` |\n" "$1" "${3:-(none)}" "$2"; fi
}
cid() { jq -r '.cid // ""' "records/$1.content.json"; }
text() { jq -r '.value // ""' "records/$1.$2.json"; }
brief() { jq -c '{appVersion, cards: (.pocket.cards // [] | length)}' 2>/dev/null <<<"$1" || printf '%s' "$1"; }
{
echo "### $STAGED to $DOMAIN"
echo ""
echo "| Record | Change |"
echo "|---|---|"
plan "$DOMAIN contenthash" "$(cid "$STAGED")" "$(cid "$DOMAIN")"
plan "app.$DOMAIN contenthash" "$(cid "app.$STAGED")" "$(cid "app.$DOMAIN")"
plan "worker.$DOMAIN contenthash" "$(cid "worker.$STAGED")" "$(cid "worker.$DOMAIN")"
plan "app.$DOMAIN executable" "$(brief "$(text "app.$STAGED" executable)")" "$(brief "$(text "app.$DOMAIN" executable)")"
plan "worker.$DOMAIN executable" "$(brief "$(text "worker.$STAGED" executable)")" "$(brief "$(text "worker.$DOMAIN" executable)")"
if [ "$(text "$STAGED" manifest)" = "$(text "$DOMAIN" manifest)" ]; then plan "$DOMAIN manifest" x x
else plan "$DOMAIN manifest" "$(text "$STAGED" manifest | jq -c .trustedProducts)" "$(text "$DOMAIN" manifest | jq -c .trustedProducts)"; fi
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Point the released name at the staged records
env:
DEPLOY_MNEMONIC: ${{ secrets.HUMANITY_DOTNS_MNEMONIC }}
APP_CID: ${{ steps.read.outputs.app }}
WORKER_CID: ${{ steps.read.outputs.worker }}
run: |
set -euo pipefail
DOTNS_MNEMONIC=$(printf '%s' "$DEPLOY_MNEMONIC" | tr -d '\r' \
| sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' \
-e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'\$/\1/")
echo "::add-mask::$DOTNS_MNEMONIC"
export DOTNS_MNEMONIC
# Text records first: the executables carry appVersion and the Pocket
# cards, which must describe the bytes the contenthash will point at.
copy_text() {
local staged="records/$1.$3.json" released="records/$2.$3.json"
if [ "$(jq -r '.value // ""' "$staged")" = "$(jq -r '.value // ""' "$released")" ]; then
echo "$2 $3 already matches."
else
jq -r '.value' "$staged" | dotns text set "$2" "$3" --env "$DOTNS_ENV"
fi
}
copy_text "app.$STAGED" "app.$DOMAIN" executable
copy_text "worker.$STAGED" "worker.$DOMAIN" executable
copy_text "$STAGED" "$DOMAIN" manifest
dotns content set "worker.$DOMAIN" "$WORKER_CID" --env "$DOTNS_ENV"
dotns content set "app.$DOMAIN" "$APP_CID" --env "$DOTNS_ENV"
dotns content set "$DOMAIN" "$APP_CID" --env "$DOTNS_ENV"
- name: Verify the released name
env:
APP_CID: ${{ steps.read.outputs.app }}
WORKER_CID: ${{ steps.read.outputs.worker }}
run: |
set -euo pipefail
for pair in "$DOMAIN=$APP_CID" "app.$DOMAIN=$APP_CID" "worker.$DOMAIN=$WORKER_CID"; do
name=${pair%%=*}; want=${pair#*=}
got=$(dotns content view "$name" --env "$DOTNS_ENV" --json | jq -r '.cid')
[ "$got" = "$want" ] || { echo "::error title=Not promoted::$name serves $got, expected $want."; exit 1; }
echo "$name serves $got"
done
for pair in "app.$DOMAIN=app.$STAGED=executable" "worker.$DOMAIN=worker.$STAGED=executable" "$DOMAIN=$STAGED=manifest"; do
name=${pair%%=*}; rest=${pair#*=}; staged=${rest%%=*}; key=${rest#*=}
got=$(dotns text view "$name" "$key" --env "$DOTNS_ENV" --json | jq -r '.value // ""')
want=$(jq -r '.value // ""' "records/$staged.$key.json")
[ "$got" = "$want" ] || { echo "::error title=Not promoted::$name $key differs from $staged's."; exit 1; }
echo "$name $key matches $staged"
done
# The notes list only the commits since the previous humanity-v* tag
# that touched Humanity, since generated notes cannot filter by path.
# Latest stays Jollity's.
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
TARGET: ${{ steps.staged.outputs.sha }}
VERSION: ${{ inputs.version }}
APP_CID: ${{ steps.read.outputs.app }}
WORKER_CID: ${{ steps.read.outputs.worker }}
PREV_APP: ${{ steps.read.outputs.prev_app }}
PREV_WORKER: ${{ steps.read.outputs.prev_worker }}
run: |
set -euo pipefail
PREV_TAG=$(git tag --list 'humanity-v*' --sort=-v:refname | head -n1)
cat > notes.md <<EOF
### Deployment
| | |
|---|---|
| Version | \`${VERSION}\` |
| Domain | \`${DOMAIN}\` |
| Staged at | \`${STAGED}\` |
| Commit | \`${TARGET}\` |
| App CID | \`${APP_CID}\` |
| Worker CID | \`${WORKER_CID}\` |
| Previous app CID | \`${PREV_APP}\` |
| Previous worker CID | \`${PREV_WORKER}\` |
| Browser | https://${DOMAIN}.li |
Open \`${DOMAIN}\` in the Polkadot app. To roll back, \`dotns content set\`
\`app.${DOMAIN}\`, \`${DOMAIN}\` and \`worker.${DOMAIN}\` to the previous CIDs.
### Changes${PREV_TAG:+ since ${PREV_TAG}}
EOF
git log --format='- %s (%an)' "${PREV_TAG:+${PREV_TAG}..}${TARGET}" -- \
apps/humanity-app apps/humanity-worker packages/humanity-shared \
packages/shared-records 'packages/individuality-*' >> notes.md
gh release create "$TAG" --target "$TARGET" --title "Humanity $VERSION" \
--notes-file notes.md --latest=false
- name: Release summary
env:
VERSION: ${{ inputs.version }}
run: |
{
echo "### ${DOMAIN} ${VERSION}"
echo ""
echo "Promoted from \`${STAGED}\`"
echo "App CID \`${{ steps.read.outputs.app }}\`"
echo "Worker CID \`${{ steps.read.outputs.worker }}\`"
} >> "$GITHUB_STEP_SUMMARY"