-
Notifications
You must be signed in to change notification settings - Fork 4
460 lines (444 loc) · 14.3 KB
/
release.yml
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
name: CI / Release
on:
push:
tags:
- v**
jobs:
check-lint:
name: "Check / Lint"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linting
run: |
npm install
npm run lint
npm run lint-shell
check-dry:
name: "Check / Dry Run"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
steps:
- uses: actions/checkout@v4
- name: Dry run
run: nix build .#docker --dry-run --no-update-lock-file
check-build:
name: "Check / Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run build
run: |
npm install
npm run build --verbose
check-matrix:
name: "Check / Matrix"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: |
files=$(find tests/* -maxdepth 0 -type d -not -path "tests/integration" | sed 's/.*/"&"/' | paste -sd, -)
files=$files,$(find tests/* -maxdepth 0 -type f | grep -e "/*.test.ts" | sed 's/.*/"&"/' | paste -sd, -)
if [ -z "$files" ]; then
echo "matrix={\"shard\":[]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"shard\":[$files]}" >> $GITHUB_OUTPUT
fi
check-test:
name: "Check / Test"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{fromJson(needs.check-matrix.outputs.matrix)}}
needs: check-matrix
steps:
- uses: actions/checkout@v4
- name: Set artifact name
run: echo "SLUG=$(echo ${{ matrix.shard }} | sed 's/[/.]/-/g')" >> $GITHUB_ENV
- name: Run tests
run: |
npm install
npm run test -- \
--coverageReporters json \
--coverage \
"${{ matrix.shard }}"
mv tmp/coverage/coverage-final.json "tmp/coverage/${{ env.SLUG }}.json"
- uses: actions/upload-artifact@v4
with:
name: coverage-artifacts-${{ env.SLUG }}
path: tmp/coverage/
check-coverage:
name: "Check / Coverage"
runs-on: ubuntu-latest
needs: check-test
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: coverage-artifacts-*
path: tmp/coverage/
merge-multiple: true
- name: Merge coverage results
run: npx nyc merge tmp/coverage/ tmp/coverage/cobertura-coverage.json
- uses: actions/upload-artifact@v4
with:
name: cobertura-coverage
path: tmp/coverage/cobertura-coverage.json
build-prerelease:
name: "Build / Pre-release"
runs-on: ubuntu-latest
concurrency:
group: build-prerelease
cancel-in-progress: false
needs:
- check-lint
- check-dry
- check-build
- check-test
if: contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- name: Run deployment
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
echo 'Publishing library prerelease'
npm install
npm publish --tag prerelease --access public
rm -f ./.npmrc
integration-builds:
name: "Integration / Builds"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
needs:
- check-lint
- check-dry
- check-build
- check-test
steps:
- uses: actions/checkout@v4
- name: Build targets
run: |
mkdir -p ./builds
build_application="$(nix build \
--max-jobs "$(nproc)" \
--cores "$(nproc)" \
--print-out-paths \
.# \
)"
nix-store --export $( \
nix-store --query --requisites "$build_application" \
) | gzip > ./builds/polykey-cli.closure.gz
builds="$(nix build \
--max-jobs "$(nproc)" \
--cores "$(nproc)" \
--print-out-paths \
--print-build-logs \
.# \
.#docker \
.#packages.x86_64-linux.executable \
)"
cp -r $(echo $builds | tr '\n' ' ') ./builds/
nix develop .#ci --command bash -c $'
npm run build
'
- uses: actions/upload-artifact@v4
with:
name: builds
path: ./builds
- uses: actions/upload-artifact@v4
with:
name: dist
path: ./dist
integration-platforms:
name: "Integration / Platforms"
runs-on: ${{ matrix.os }}
container:
image: ${{ (matrix.platform == 'nix' || matrix.platform == 'docker') && 'ghcr.io/matrixai/github-runner' || null }}
needs: integration-builds
strategy:
fail-fast: false
matrix:
include:
- platform: nix
os: ubuntu-latest
env: {}
script: |
build_application="$( \
gunzip -c ./builds/polykey-cli.closure.gz | \
nix-store --import | \
tail -1 \
)"
$build_application/bin/polykey
- platform: docker
os: ubuntu-latest
env:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_TMPDIR: "${{ github.workspace }}/tmp/test"
PK_NETWORK: "testnet"
script: |
docker info
mkdir $PK_TEST_TMPDIR
nix develop .#ci --command bash -c $'
image_and_tag="$(docker load --input ./builds/*docker* | cut -d\' \' -f3)"
docker tag "$image_and_tag" "polykey-cli:testtarget"
'
- platform: linux
os: ubuntu-latest
env: {}
script: |
chmod +x ./builds/*-linux-*
for f in ./builds/*-linux-*; do "$f"; done
- platform: windows
os: windows-latest
env: {}
script: |
mkdir -Force "$GITHUB_WORKSPACE/tmp"
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
.\scripts\choco-install.ps1
refreshenv
npm ci --ignore-scripts
$env:Path = "$(npm root)\.bin;" + $env:Path
$env:version = $(node -p "require('./package.json').version")
npm run pkg -- `
--output=builds\polykey-cli-$env:version-win32-x64 `
--bin=dist\polykey.js `
--node-version=20 `
--platform=win32 `
--arch=x64
Get-ChildItem -File ./builds/*-win32-* | ForEach {& $_.FullName}
- platform: macos
os: macos-latest
env: {}
script: |
version=$(node -p "require('./package.json').version")
npm ci
npm run pkg -- \
--output=builds/polykey-cli-$version-darwin-universal \
--bin=dist/polykey.js \
--node-version=20 \
--platform=darwin \
--arch=arm64
for f in ./builds/*-darwin-universal*; do "$f"; done
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- uses: actions/download-artifact@v4
with:
name: builds
path: ./builds
- uses: actions/download-artifact@v4
with:
name: dist
path: ./dist
- name: Build
env: ${{ matrix.env }}
run: ${{ matrix.script }}
- uses: actions/upload-artifact@v4
with:
name: builds-${{ matrix.platform }}
path: ./builds
integration-prerelease:
name: "Integration / Pre-release"
runs-on: ubuntu-latest
concurrency:
group: integration-prerelease
cancel-in-progress: false
needs: [integration-platforms, integration-test]
if: contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: builds*
path: ./builds
merge-multiple: true
- name: Publish pre-release
env:
CI_REGISTRY_IMAGE: '015248367786.dkr.ecr.ap-southeast-2.amazonaws.com/polykey'
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo 'Publishing application prerelease'
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null; then \
gh release \
upload "$GITHUB_REF_NAME" \
builds/*.closure.gz \
builds/*-docker-* \
builds/*-linux-* \
builds/*-win32-* \
builds/*-darwin-* \
--clobber \
--repo "$GITHUB_REPOSITORY"; \
else \
gh release \
create "$GITHUB_REF_NAME" \
builds/*.closure.gz \
builds/*-docker-* \
builds/*-linux-* \
builds/*-win32-* \
builds/*-darwin-* \
--title "${GITHUB_REF_NAME}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--prerelease \
--target staging \
--repo "$GITHUB_REPOSITORY"; \
fi
integration-deployment:
name: "Integration / Deployment"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
concurrency:
group: integration-deployment
cancel-in-progress: true
environment: testnet
needs: integration-builds
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: builds
path: ./builds
- name: Deploying image to ECR
env:
name: 'testnet'
deployment_tier: 'staging'
url: 'https://testnet.polykey.com'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CI_REGISTRY_IMAGE: '015248367786.dkr.ecr.ap-southeast-2.amazonaws.com/polykey'
run: |
nix develop .#ci --command bash -c $'
aws ecr get-login-password \
| skopeo login \
--username AWS \
--password-stdin \
--authfile "$REGISTRY_AUTH_FILE" \
"$CI_REGISTRY_IMAGE"
image=(./builds/*-docker-*)
./scripts/deploy-image.sh "${image[0]}" \'testnet\' "$CI_REGISTRY_IMAGE"
'
echo 'Waiting for Testnet Deployment'
nix develop .#ci --command bash -c $'
./scripts/wait-for-deploy.js testnet.polykey.com
'
integration-test:
name: "Integration / Test"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
needs: integration-deployment
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: builds
path: ./builds
- name: Run tests
env:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_TMPDIR: "./tmp/test"
PK_NETWORK: "testnet"
run: |
docker info
mkdir -p $PK_TEST_TMPDIR
nix develop .#ci --command bash -c $'
image_and_tag="$(docker load --input ./builds/*docker* | cut -d\' \' -f3)"
docker tag "$image_and_tag" "polykey-cli:testtarget"
npm run test tests/integration/docker
'
release-deployment:
name: "Release / Deployment"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
concurrency:
group: release-deployment
cancel-in-progress: false
environment: mainnet
needs: integration-test
if: >
!contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: builds*
path: ./builds
merge-multiple: true
- name: Run deployment
env:
name: 'mainnet'
deployment_tier: 'production'
url: 'https://mainnet.polykey.com'
REGISTRY_AUTH_FILE: "./tmp/registry-auth-file.json"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CI_REGISTRY_IMAGE: '015248367786.dkr.ecr.ap-southeast-2.amazonaws.com/polykey'
run: |
echo 'Deploying container image to ECR'
nix develop .#ci --command bash -c $'
aws ecr get-login-password \
| skopeo login \
--username AWS \
--password-stdin \
--authfile "$REGISTRY_AUTH_FILE" \
"$CI_REGISTRY_IMAGE"
image=(./builds/*-docker-*)
./scripts/deploy-image.sh "${image[0]}" \'mainnet\' "$CI_REGISTRY_IMAGE"
'
echo 'Waiting for Mainnet Deployment'
nix develop .#ci --command bash -c $'
./scripts/wait-for-deploy.js mainnet.polykey.com
'
rm -f "$REGISTRY_AUTH_FILE"
release-distribution:
name: "Release / Distribution"
runs-on: ubuntu-latest
concurrency:
group: release-distribution
cancel-in-progress: false
needs: [integration-platforms, release-deployment]
if: >
!contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: builds*
path: ./builds
merge-multiple: true
- name: Publish release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
echo 'Publishing library'
npm install
npm publish --access public
echo 'Releasing application builds'
gh release \
create "$GITHUB_REF_NAME" \
builds/*.closure.gz \
builds/*-docker-* \
builds/*-linux-* \
builds/*-win32-* \
builds/*-darwin-* \
--title "${GITHUB_REF_NAME}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--target master \
--repo "$GITHUB_REPOSITORY"
rm -f ./.npmrc