-
Notifications
You must be signed in to change notification settings - Fork 2
421 lines (368 loc) · 13.3 KB
/
Copy pathdeploy.yml
File metadata and controls
421 lines (368 loc) · 13.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
name: Deploy on Polkadot
on:
workflow_call:
inputs:
basename:
description: 'Base domain without .dot'
required: true
type: string
mode:
description: 'preview (subname deploy) | production (basename deploy)'
required: false
type: string
default: 'preview'
subname-format:
description: 'pr-number | branch | sha-short (ignored in production mode)'
required: false
type: string
default: 'pr-number'
subname:
description: 'Explicit subname override for preview deployments'
required: false
type: string
default: ''
register-base:
description: 'Attempt base domain registration if not already owned'
required: false
type: boolean
default: false
artifact-name:
description: 'Build artifact to deploy'
required: true
type: string
cli-source:
description: 'CLI install source: release or source'
required: false
type: string
default: 'release'
sdk-ref:
description: 'dotns-sdk ref used for checked out composite actions and source builds'
required: false
type: string
default: 'main'
sdk-repository:
description: 'Repository used for checked out composite actions and source builds'
required: false
type: string
default: 'paritytech/dotns-sdk'
use-car:
description: 'Merkleize with IPFS CLI and upload as a single CAR file'
required: false
type: boolean
default: true
key-uri:
description: 'Substrate key URI for dev/test (e.g., //Alice)'
required: false
type: string
bulletin-rpc:
description: 'Bulletin chain WebSocket RPC endpoint (default: CLI built-in)'
required: false
type: string
rpc:
description: 'WebSocket RPC endpoint (default: CLI built-in)'
required: false
type: string
env:
description: 'DotNS environment'
required: false
type: string
default: 'paseo-v2'
upload-concurrency:
description: 'Adaptive scheduler max window (max: 4)'
required: false
type: number
default: 4
skip-cache:
description: 'Skip deployment cache and force re-upload'
required: false
type: boolean
default: false
cache:
description: 'Write uploaded CID to on-chain Store after upload'
required: false
type: boolean
default: false
max-retries:
description: 'Max retry attempts per step for transient RPC failures'
required: false
type: number
default: 3
retry-delay:
description: 'Seconds to wait between retries'
required: false
type: number
default: 15
secrets:
dotns-mnemonic:
description: 'BIP39 mnemonic for DotNS on-chain operations (register, contenthash)'
required: true
bulletin-mnemonic:
description: 'BIP39 mnemonic for Bulletin uploads (defaults to //Alice dev seed)'
required: false
outputs:
cid:
value: ${{ jobs.deploy.outputs.cid }}
fqdn:
value: ${{ jobs.deploy.outputs.fqdn }}
url:
value: ${{ jobs.deploy.outputs.url }}
url-alt:
value: ${{ jobs.deploy.outputs.url-alt }}
url-direct:
value: ${{ jobs.deploy.outputs.url-direct }}
url-dotli-path:
value: ${{ jobs.deploy.outputs.url-dotli-path }}
url-dotli-host:
value: ${{ jobs.deploy.outputs.url-dotli-host }}
cache-hit:
value: ${{ jobs.deploy.outputs.cache-hit }}
duration-seconds:
value: ${{ jobs.deploy.outputs.duration-seconds }}
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
outputs:
cid: ${{ steps.final.outputs.cid }}
fqdn: ${{ steps.final.outputs.fqdn }}
url: ${{ steps.final.outputs.url }}
url-alt: ${{ steps.final.outputs.url-alt }}
url-direct: ${{ steps.final.outputs.url-direct }}
url-dotli-path: ${{ steps.final.outputs.url-dotli-path }}
url-dotli-host: ${{ steps.final.outputs.url-dotli-host }}
cache-hit: ${{ steps.cache.outputs.cache-hit }}
duration-seconds: ${{ steps.duration.outputs.seconds }}
steps:
- name: Checkout actions
uses: actions/checkout@v4
with:
repository: ${{ inputs.sdk-repository }}
ref: ${{ inputs.sdk-ref }}
sparse-checkout: |
.github/actions
packages/cli
packages/ui/package.json
packages/ui/.papi
package.json
bun.lock
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: build
- name: Setup CLI
uses: ./.github/actions/setup-cli
with:
source: ${{ inputs.cli-source }}
- name: Record deploy start
id: timer-start
run: echo "epoch=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: Resolve target
id: target
run: |
if [[ "$MODE" == "production" ]]; then
echo "domain=$BASENAME" >> "$GITHUB_OUTPUT"
echo "fqdn=${BASENAME}.dot" >> "$GITHUB_OUTPUT"
else
if [[ -n "$SUBNAME_OVERRIDE" ]]; then
SUBNAME="$SUBNAME_OVERRIDE"
else
case "$SUBNAME_FORMAT" in
pr-number)
SUBNAME="pr${PR_NUMBER}"
;;
branch)
SUBNAME=$(echo "$HEAD_REF" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | cut -c1-20 | sed 's/-$//')
;;
sha-short)
SUBNAME=$(echo "$COMMIT_SHA" | cut -c1-7)
;;
esac
fi
echo "subname=$SUBNAME" >> "$GITHUB_OUTPUT"
echo "domain=${SUBNAME}.${BASENAME}" >> "$GITHUB_OUTPUT"
echo "fqdn=${SUBNAME}.${BASENAME}.dot" >> "$GITHUB_OUTPUT"
fi
env:
MODE: ${{ inputs.mode }}
BASENAME: ${{ inputs.basename }}
SUBNAME_FORMAT: ${{ inputs.subname-format }}
SUBNAME_OVERRIDE: ${{ inputs.subname }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_REF: ${{ github.head_ref }}
COMMIT_SHA: ${{ github.sha }}
- name: Compute build hash
id: hash
run: |
HASH=$(find build -type f -exec sha256sum {} \; | sort | sha256sum | cut -d' ' -f1)
echo "hash=$HASH" >> "$GITHUB_OUTPUT"
echo "Build hash: $HASH"
- name: Check deployment cache
id: cache
if: inputs.skip-cache != true
uses: actions/cache@v4
with:
path: .deploy-cache
key: deploy-${{ steps.hash.outputs.hash }}
- name: Load cached CID
id: cached
if: steps.cache.outputs.cache-hit == 'true'
run: |
CID=$(cat .deploy-cache/cid)
echo "cid=$CID" >> "$GITHUB_OUTPUT"
echo "::notice::Cache hit — reusing CID: $CID"
- name: Resolve upload settings
id: upload-settings
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
EFFECTIVE_UPLOAD_CONCURRENCY="$UPLOAD_CONCURRENCY"
if [[ "$MODE" == "preview" && "$EFFECTIVE_UPLOAD_CONCURRENCY" -gt 10 ]]; then
EFFECTIVE_UPLOAD_CONCURRENCY=10
fi
echo "upload-concurrency=$EFFECTIVE_UPLOAD_CONCURRENCY" >> "$GITHUB_OUTPUT"
env:
MODE: ${{ inputs.mode }}
UPLOAD_CONCURRENCY: ${{ inputs.upload-concurrency }}
- name: Export CAR file
id: car
if: steps.cache.outputs.cache-hit != 'true' && inputs.use-car
shell: bash
run: |
# Install IPFS Kubo if not already available
if ! command -v ipfs &>/dev/null; then
echo "Installing IPFS Kubo..."
wget -qO- https://dist.ipfs.tech/kubo/v0.33.2/kubo_v0.33.2_linux-amd64.tar.gz | tar xz
sudo mv kubo/ipfs /usr/local/bin/
rm -rf kubo
fi
ipfs init --profile server 2>/dev/null || true
CID=$(ipfs add -Q -r --cid-version=1 --raw-leaves --pin=false ./build)
ipfs dag export "$CID" > build.car
SIZE=$(stat --printf='%s' build.car)
echo "ipfs-cid=$CID" >> "$GITHUB_OUTPUT"
echo "::notice::CAR file created: $(numfmt --to=iec $SIZE) — IPFS CID: $CID"
- name: Upload to Bulletin
id: bulletin
if: steps.cache.outputs.cache-hit != 'true'
uses: ./.github/actions/bulletin
with:
mnemonic: ${{ secrets.bulletin-mnemonic || 'bottom drive obey lake curtain smoke basket hold race lonely fit walk' }}
env: ${{ inputs.env }}
bulletin-rpc: ${{ inputs.bulletin-rpc }}
build-path: ${{ inputs.use-car && './build.car' || './build' }}
upload-concurrency: ${{ steps.upload-settings.outputs.upload-concurrency }}
max-retries: ${{ inputs.max-retries }}
retry-delay: ${{ inputs.retry-delay }}
cache: ${{ inputs.cache }}
- name: Save CID to cache
if: steps.cache.outputs.cache-hit != 'true' && steps.bulletin.outputs.cid != ''
run: |
mkdir -p .deploy-cache
echo "$CID" > .deploy-cache/cid
env:
CID: ${{ steps.bulletin.outputs.cid }}
- name: Resolve CID
id: cid
run: |
CID="${CACHED_CID:-$UPLOAD_CID}"
if [[ -z "$CID" ]]; then
echo "::error::No CID available from cache or upload"
exit 1
fi
echo "cid=$CID" >> "$GITHUB_OUTPUT"
env:
CACHED_CID: ${{ steps.cached.outputs.cid }}
UPLOAD_CID: ${{ steps.bulletin.outputs.cid }}
- name: Register and set contenthash
uses: ./.github/actions/dotns
with:
mnemonic: ${{ secrets.dotns-mnemonic }}
env: ${{ inputs.env }}
rpc: ${{ inputs.rpc }}
basename: ${{ inputs.basename }}
mode: ${{ inputs.mode }}
subname: ${{ steps.target.outputs.subname }}
domain: ${{ steps.target.outputs.domain }}
register-base: ${{ inputs.register-base }}
cid: ${{ steps.cid.outputs.cid }}
max-retries: ${{ inputs.max-retries }}
retry-delay: ${{ inputs.retry-delay }}
- name: Set outputs
id: final
run: |
DOTLI_PATH_URL="https://dot.li/${FQDN}"
DIRECT_URL="https://${FQDN}"
DOTLI_HOST_URL=""
if [[ -n "$SUBNAME" ]]; then
PRIMARY_URL="$DOTLI_PATH_URL"
else
DOTLI_HOST_URL="https://${DOMAIN}.dot.li"
PRIMARY_URL="$DOTLI_HOST_URL"
fi
echo "cid=$CID" >> "$GITHUB_OUTPUT"
echo "fqdn=$FQDN" >> "$GITHUB_OUTPUT"
echo "url=$PRIMARY_URL" >> "$GITHUB_OUTPUT"
echo "url-alt=$DIRECT_URL" >> "$GITHUB_OUTPUT"
echo "url-direct=$DIRECT_URL" >> "$GITHUB_OUTPUT"
echo "url-dotli-path=$DOTLI_PATH_URL" >> "$GITHUB_OUTPUT"
echo "url-dotli-host=$DOTLI_HOST_URL" >> "$GITHUB_OUTPUT"
env:
CID: ${{ steps.cid.outputs.cid }}
FQDN: ${{ steps.target.outputs.fqdn }}
DOMAIN: ${{ steps.target.outputs.domain }}
SUBNAME: ${{ steps.target.outputs.subname }}
- name: Compute deploy duration
id: duration
run: |
START="${START_EPOCH}"
END=$(date +%s)
ELAPSED=$((END - START))
echo "seconds=$ELAPSED" >> "$GITHUB_OUTPUT"
env:
START_EPOCH: ${{ steps.timer-start.outputs.epoch }}
- name: Summary
run: |
CACHE_NOTE=""
if [[ "$CACHE_HIT" == "true" ]]; then
CACHE_NOTE=" (cached)"
fi
BULLETIN_AUTH="mnemonic"
if [[ -z "$BULLETIN_MNEMONIC" ]]; then
BULLETIN_AUTH="alice"
fi
if [[ -n "$SUBNAME" ]]; then
URL_ROWS=$(cat <<EOF
| URL (dot.li) | [${URL_DOTLI_PATH}](${URL_DOTLI_PATH}) |
| URL (direct) | [${URL_DIRECT}](${URL_DIRECT}) |
EOF
)
else
URL_ROWS="| URL | [${URL_DOTLI_HOST}](${URL_DOTLI_HOST}) |"
fi
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## Deployment Complete
| Property | Value |
|----------|-------|
| Mode | \`${MODE}\` |
| Domain | \`${FQDN}\` |
| CID | \`${CID}\`${CACHE_NOTE} |
${URL_ROWS}
| Duration | ${DURATION_SECONDS}s |
| Bulletin Auth | ${BULLETIN_AUTH} |
EOF
env:
MODE: ${{ inputs.mode }}
FQDN: ${{ steps.final.outputs.fqdn }}
CID: ${{ steps.final.outputs.cid }}
URL_DIRECT: ${{ steps.final.outputs.url-direct }}
URL_DOTLI_PATH: ${{ steps.final.outputs.url-dotli-path }}
URL_DOTLI_HOST: ${{ steps.final.outputs.url-dotli-host }}
SUBNAME: ${{ steps.target.outputs.subname }}
DURATION_SECONDS: ${{ steps.duration.outputs.seconds }}
BULLETIN_MNEMONIC: ${{ secrets.bulletin-mnemonic }}
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}