Repository navigation
159 lines (141 loc) · 6 KB
/
Copy pathdeploy-playground.yml
File metadata and controls
159 lines (141 loc) · 6 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
name: Deploy Playground
on:
# After CI, not alongside it. A push triggers both at once, so a commit
# that failed its checks would still deploy.
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
workflow_dispatch:
inputs:
environment:
description: bulletin-deploy environment to publish to
type: choice
default: paseo-next-v2
options:
- paseo-next-v2
- preview
- paseo-next
- paseo-review
concurrency:
group: deploy-truapi-playground
cancel-in-progress: false
permissions:
contents: read
jobs:
deploy-playground:
# Only a commit CI validated. workflow_run fires whatever the conclusion
# was, so the conclusion is checked here rather than assumed, and a manual
# dispatch is allowed through deliberately.
if: >-
github.event_name == 'workflow_dispatch'
|| github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
# The run that validated this commit, not whatever main happens to be.
# Between CI finishing and this starting, main can have moved.
- name: Establish the commit CI validated
id: validated
env:
EVENT: ${{ github.event_name }}
RUN_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
if [ "${EVENT}" = "workflow_dispatch" ]; then
echo "sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "dispatched by hand; deploying ${GITHUB_SHA}"
exit 0
fi
if [ -z "${RUN_SHA}" ]; then
echo "::error::No commit on the triggering run, so nothing is known to be validated"
exit 1
fi
echo "sha=${RUN_SHA}" >> "$GITHUB_OUTPUT"
echo "deploying ${RUN_SHA}, validated by run ${{ github.event.workflow_run.id }}"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ steps.validated.outputs.sha }}
# Evidence rather than inference: the codegen artifact exists only if that
# run produced it for this commit. Absent, there is nothing to show CI
# ever saw this tree, so the deploy stops.
- name: Take the evidence from the run that validated it
if: github.event_name != 'workflow_dispatch'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: codegen-output
path: ${{ runner.temp }}/ci-evidence
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Confirm the tree is the one that was validated
env:
EXPECTED: ${{ steps.validated.outputs.sha }}
run: |
set -euo pipefail
actual="$(git rev-parse HEAD)"
if [ "${actual}" != "${EXPECTED}" ]; then
echo "::error::Checked out ${actual}, but CI validated ${EXPECTED}"
exit 1
fi
echo "deploying ${actual}, which is the commit CI validated"
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- uses: dtolnay/rust-toolchain@5b842231ba77f5c045dba54ac5560fed2db780e2 # stable
with:
toolchain: stable
- uses: ./.github/actions/rust-nightly
with:
components: rustfmt
# codegen.sh is the same work as ci.yml's codegen job, which owns the
# cache. The key hashes the default toolchain, so this runs after
# nightly, as it does there.
- uses: ./.github/actions/rust-cache
with:
shared-key: codegen
save: "false"
- name: Build @parity/truapi
run: npm ci && ./scripts/codegen.sh
- name: Install playground dependencies
working-directory: playground
run: yarn install --frozen-lockfile
- name: Cache Next.js build
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: playground/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('playground/yarn.lock') }}-${{ hashFiles('playground/src/**', 'playground/scripts/**', 'playground/public/**', 'playground/next.config.js', 'playground/tsconfig.json', 'playground/package.json') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('playground/yarn.lock') }}-
- name: Build playground
working-directory: playground
run: yarn build
- name: Install bulletin-deploy
run: npm install -g bulletin-deploy
- name: Resolve the dotNS name for this environment
id: dotns
env:
BULLETIN_ENV: ${{ inputs.environment || 'paseo-next-v2' }}
run: |
# A bare label was enough while this was a content-only deploy, but
# publishing the product manifest compares the name passed here
# against `domain` in playground/bulletin-deploy.config.ts byte for
# byte, so both have to carry the environment's TLD. Source of truth
# is bulletin-deploy's assets/environments.json: only `preview` and
# `paseo-next-v2` declare one, the rest fall back to dotNS's `dot`.
case "$BULLETIN_ENV" in
paseo-next-v2) tld="paseo" ;;
preview) tld="test" ;;
*) tld="dot" ;;
esac
echo "name=truapi-playground.$tld" >> "$GITHUB_OUTPUT"
- name: Deploy to DotNS
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
env:
# Read both as the CLI argument and, by the config file, as the
# `domain` it declares, so the two can never drift apart.
PLAYGROUND_DOTNS_NAME: ${{ steps.dotns.outputs.name }}
BULLETIN_ENV: ${{ inputs.environment || 'paseo-next-v2' }}
with:
timeout_minutes: 10
max_attempts: 3
command: cd playground && bulletin-deploy ./out "$PLAYGROUND_DOTNS_NAME" --js-merkle --env "$BULLETIN_ENV"