Skip to content

Commit cc44ef2

Browse files
chore: Migrate publishing to GHA, consolidate CI workflows (#879)
1 parent ad7e1cb commit cc44ef2

File tree

7 files changed

+196
-38
lines changed

7 files changed

+196
-38
lines changed

.github/workflows/ci-unit-tests.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/daily_ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# This workflow runs every weekday at 15:00 UTC (8AM PDT)
22
name: Daily CI
3+
permissions:
4+
contents: read
35

46
on:
57
schedule:
68
- cron: "00 15 * * 1-5"
79

810
jobs:
911
daily-ci-js-helpers:
10-
uses: ./.github/workflows/ci-unit-tests.yaml
12+
uses: ./.github/workflows/shared-ci.yml

.github/workflows/prod-release.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Release
2+
permissions:
3+
contents: read
4+
id-token: write
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
version_bump:
10+
required: false
11+
description: '[Optional] Override semantic versioning with explict version (allowed values: "patch", "minor", "major", or explicit version)'
12+
default: ''
13+
dist_tag:
14+
description: 'NPM distribution tag'
15+
required: false
16+
default: 'latest'
17+
branch:
18+
description: 'The branch to release from'
19+
required: false
20+
default: 'master'
21+
22+
env:
23+
NODE_OPTIONS: "--max-old-space-size=4096"
24+
NPM_CONFIG_UNSAFE_PERM: true
25+
26+
jobs:
27+
pre-release-ci:
28+
uses: ./.github/workflows/shared-ci.yml
29+
30+
# Once all tests have passed, run semantic versioning
31+
version:
32+
runs-on: ubuntu-latest
33+
needs: [pre-release-ci]
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
token: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Setup Node.js 20
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: '20'
45+
cache: 'npm'
46+
47+
- name: Install dependencies
48+
run: npm ci --unsafe-perm
49+
50+
- name: Configure git
51+
env:
52+
BRANCH: ${{ github.event.inputs.branch }}
53+
run: |
54+
git config --global user.name "aws-crypto-tools-ci-bot"
55+
git config --global user.email "[email protected]"
56+
git checkout $BRANCH
57+
58+
- name: Version packages and push
59+
env:
60+
VERSION_BUMP: ${{ github.event.inputs.version_bump }}
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
# Generate new version and CHANGELOG entry and push it
64+
npx lerna version --conventional-commits --git-remote origin --yes ${VERSION_BUMP:+$VERSION_BUMP --force-publish}
65+
# Log the commit for posterity
66+
git log -n 1
67+
68+
publish:
69+
runs-on: ubuntu-latest
70+
needs: [pre-release-ci, version]
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- uses: actions/setup-node@v4
75+
with:
76+
node-version: '20'
77+
registry-url: 'https://registry.npmjs.org'
78+
79+
# Ensure npm 11.5.1 or later is installed
80+
- name: Update npm
81+
run: npm install -g npm@latest
82+
- run: npm ci --unsafe-perm
83+
- run: npm run build --if-present
84+
- run: npx lerna publish from-package --yes --dist-tag ${{ github.event.inputs.dist_tag }}
85+
86+
# Once publishing is complete, validate that the published packages are useable
87+
validate:
88+
uses: ./.github/workflows/shared-ci.yml
89+
needs: [publish]
90+
with:
91+
test-published-packages: true

.github/workflows/pull.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# This workflow runs for every pull request
22
name: PR CI
3+
permissions:
4+
contents: read
35

46
on:
57
pull_request:
68

79
jobs:
810
pr-ci-js-helpers-test:
9-
uses: ./.github/workflows/ci-unit-tests.yaml
11+
uses: ./.github/workflows/shared-ci.yml
12+
pr-ci-all-required:
13+
if: always()
14+
needs:
15+
- pr-ci-js-helpers-test
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Verify all required jobs passed
19+
uses: re-actors/alls-green@release/v1
20+
with:
21+
jobs: ${{ toJSON(needs) }}

.github/workflows/push.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This workflow runs for every push to master
22
name: Push CI
3+
permissions:
4+
contents: read
35

46
on:
57
push:
@@ -8,4 +10,4 @@ on:
810

911
jobs:
1012
push-ci-js-helpers-test:
11-
uses: ./.github/workflows/ci-unit-tests.yaml
13+
uses: ./.github/workflows/shared-ci.yml

.github/workflows/shared-ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Shared CI Tests
2+
permissions:
3+
contents: read
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
test-published-packages:
9+
description: 'Test against published packages instead of checked out code'
10+
required: false
11+
type: boolean
12+
default: false
13+
14+
env:
15+
NODE_OPTIONS: "--max-old-space-size=4096"
16+
NPM_CONFIG_UNSAFE_PERM: true
17+
18+
jobs:
19+
ci-unit-tests:
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, windows-latest, macos-latest]
25+
node: ["16.x", "18.x", "20.x"]
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Setup Node.js ${{ matrix.node }}
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: ${{ matrix.node }}
33+
cache: 'npm'
34+
35+
- name: Install dependencies
36+
run: npm ci --unsafe-perm
37+
38+
# `npm test` only works for local code, testing published packages requires setup
39+
- name: Test local code
40+
if: ${{ !inputs.test-published-packages }}
41+
run: npm test
42+
43+
- name: Build (for source code testing)
44+
if: ${{ !inputs.test-published-packages }}
45+
run: npm run build
46+
47+
# Run vector tests for all CI runs (Ubuntu only)
48+
# Verdaccio is only supported on Node.js v18 and higher
49+
# Weird syntax issues on Windows prevent us from running these tests there
50+
- name: Publish locally for vector tests (except Node.js 16)
51+
if: ${{ !inputs.test-published-packages && matrix.node != '16.x' && matrix.os != 'windows-latest' }}
52+
run: npm run verdaccio-publish
53+
54+
- name: Run vector tests (local packages)
55+
if: ${{ !inputs.test-published-packages && matrix.node != '16.x' && matrix.os != 'windows-latest' }}
56+
run: npm run verdaccio-verify-publish -- ci
57+
58+
# Run vector tests against published packages (release workflow validation, Ubuntu only)
59+
- name: Run vector tests (published packages)
60+
if: ${{ inputs.test-published-packages && matrix.node != '16.x' && matrix.os != 'windows-latest' }}
61+
run: npm run verdaccio-verify-publish -- public

util/local_verdaccio_publish

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// but now the portability problems loom large.
1111

1212
const { spawn, execSync } = require('child_process')
13-
const { readFileSync } = require('fs')
1413
const pipeStdIo = { stdio: [process.stdin, process.stdout, process.stderr] }
15-
const { workspaces } = JSON.parse(readFileSync("package.json", 'utf8'))
1614

1715
// Always clear storage so the latest versions are published
1816
// I am not worried about _what_ version number is published
@@ -24,6 +22,12 @@ const verdaccio = spawn('npx', ['verdaccio', '-c', 'verdaccio/config.yaml'], pip
2422
.on('error', e => {
2523
throw e
2624
})
25+
.on('close', (code, signal) => {
26+
console.log(`verdaccio process closed with code ${code} or signal ${signal}`);
27+
})
28+
.on('exit', (code, signal) => {
29+
console.log(`verdaccio process exited with code ${code} or signal ${signal}`);
30+
})
2731

2832
// Publish all changed packages the local verdaccio server.
2933
// Anything that has not been changed will match what is in npm
@@ -37,21 +41,32 @@ const args = [
3741
'--no-git-reset',
3842
'--preid', 'ci',
3943
'--no-verify-access',
40-
'--force-publish'
44+
'--force-publish',
45+
'--loglevel', 'warn',
46+
'--no-progress'
4147
]
42-
spawn('npx', args, pipeStdIo)
43-
.on('close', (code) => {
44-
// Kill the background verdaccio server
45-
verdaccio.kill()
46-
48+
timeout = 60000 * 2
49+
console.log(`Starting lerna publish with timeout of ${timeout}`);
50+
spawn('npx', args, {
51+
stdio: [process.stdin, process.stdout, process.stderr],
52+
timeout: timeout
53+
}).on('close', (code, signal) => {
54+
console.log(`lerna terminated due to receipt of signal ${signal} or code ${code}`);
4755
// The above command will make some modifications,
4856
// Roll them back
4957
// Ideally, we would find a way to not have to do this
50-
workspaces.forEach(workspace => execSync(`git checkout -- ${workspace}/package.json`))
5158
execSync('git checkout -- lerna.json')
59+
execSync('git restore package-lock.json')
5260

61+
// Kill the background verdaccio server
62+
verdaccioKilledStatus = verdaccio.kill()
63+
console.log(`killing Verdaccio returned ${verdaccioKilledStatus}`);
64+
5365
// If this command had an error,
5466
// we need to forward this.
5567
// Otherwise the entire CI build may think that things succeeded.
5668
if (code !== 0) throw Error(`Exit code: ${code}`)
57-
})
69+
70+
process.exit()
71+
})
72+

0 commit comments

Comments
 (0)