Skip to content

chore: break up release build #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ batch:
- identifier: testVectorsNodejsLatest
buildspec: codebuild/test_vectors/nodejs_latest.yml
env:
variables:
PUBLISH_LOCAL: "true"
image: aws/codebuild/standard:5.0
- identifier: testVectorsNodejs12
buildspec: codebuild/test_vectors/nodejs12.yml
Expand All @@ -29,3 +31,7 @@ batch:
image: aws/codebuild/standard:5.0
- identifier: testVectorsBrowser
buildspec: codebuild/test_vectors/browser.yml
env:
variables:
PUBLISH_LOCAL: "true"
image: aws/codebuild/standard:5.0
131 changes: 60 additions & 71 deletions codebuild/release/prod-release.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,65 @@
version: 0.2

env:
variables:
NPM_CONFIG_UNSAFE_PERM: true
NODE_OPTIONS: "--max-old-space-size=4096"
BRANCH: "master"
# An explicit version bump
VERSION_BUMP: ""
secrets-manager:
OTP_SECRET_KEY: npm/aws-crypto-tools-ci-bot/2FA:OTP_SECRET_KEY
NPM_TOKEN: npm/aws-crypto-tools-ci-bot/2FA:NPM_TOKEN
git-credential-helper: yes

phases:
install:
commands:
- npm ci --unsafe-perm
# Install `otplib` to extract the OTP from the npm 2FA secret
- npm install otplib --no-save
- npm run build
runtime-versions:
nodejs: 12
pre_build:
commands:
- git config --global user.name "aws-crypto-tools-ci-bot"
- git config --global user.email "no-reply@noemail.local"
- git checkout $BRANCH
build:
commands:
# Pre-check, make sure everything is happy
- npm test
- npm run test_conditions
# Publish to a local verdaccio server and run all tests against it
- npm run verdaccio
# Generate new version and CHANGELOG entry and push it
- npx lerna version --conventional-commits --git-remote origin --yes ${VERSION_BUMP:+$VERSION_BUMP --force-publish}
# Log the commit for posterity
- git log -n 1
# Extract the otp using the secrets environment variables from above.
# This will wait for the next token. This is because npm uses
# TOTP and the tokens time out after 30 seconds. If the process just
# extracted the token then the lifetime for this token
# would be very random. This will maximize the amount of time
# available on the OTP to publish.
- >-
OTP=`node -e "
auth=require('otplib').authenticator;
setTimeout(() =>
console.log(auth.generate(process.env.OTP_SECRET_KEY)),
auth.timeRemaining() * 1000);
"`
# npm will only expand env vars inside .npmrc
# NOTE the ' this is to keep the env var NPM_TOKEN from expanding!
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
# Now we publish to npm.
# This is going to use the OTP generated above and the NPM_TOKEN
# environment variable. This will only publish things that are
# missing from npm. It is therefore safe to run repeatedly.
- npx lerna publish from-package --yes --otp $OTP
# remove after publishing
- rm .npmrc
# Clear out the verdaccio cache so that we get the latest version
# of everything from public npm
- rm -rf verdaccio/storage/
# Since the cache is empty, and we don't call `verdaccio-publish`
# this will run the integrations from the public code in npm
- npx run-s verdaccio-publish-*


# Batching is technically unnecessary for now since we have just the one
# buildspec, but leaving it in place makes it easier to extend later on
batch:
fast-fail: true
build-graph:
- identifier: release_to_prod

# Lint and specification compliance
- identifier: compliance
buildspec: codebuild/compliance.yml

# Unit Tests
- identifier: testNodejsLatest
buildspec: codebuild/nodejs_latest.yml
env:
image: aws/codebuild/standard:5.0
- identifier: testBrowser
buildspec: codebuild/browser.yml

# Integration Tests
- identifier: testVectorsNodejsLatest
buildspec: codebuild/test_vectors/nodejs_latest.yml
env:
variables:
PUBLISH_LOCAL: "true"
image: aws/codebuild/standard:5.0
- identifier: testVectorsBrowser
buildspec: codebuild/test_vectors/browser.yml
env:
variables:
PUBLISH_LOCAL: "true"
image: aws/codebuild/standard:5.0

# Version the project and push git commits and tags
- identifier: version
depend-on:
- compliance
- testNodejsLatest
- testBrowser
- testVectorsNodejsLatest
- testVectorsBrowser
buildspec: codebuild/release/version.yml

# Publish the release to npm
- identifier: publish
depend-on:
- version
buildspec: codebuild/release/publish.yml

# Validate that the published versions are available
- identifier: validateNodejs
depend-on:
- publish
buildspec: codebuild/test_vectors/nodejs_latest.yml
env:
variables:
PUBLISH_LOCAL: "false"
image: aws/codebuild/standard:5.0
- identifier: validateBrowser
depend-on:
- publish
buildspec: codebuild/test_vectors/browser.yml
env:
variables:
PUBLISH_LOCAL: "false"
image: aws/codebuild/standard:5.0
48 changes: 48 additions & 0 deletions codebuild/release/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 0.2

env:
variables:
NODE_OPTIONS: "--max-old-space-size=4096"
BRANCH: "master"
secrets-manager:
OTP_SECRET_KEY: npm/aws-crypto-tools-ci-bot/2FA:OTP_SECRET_KEY
NPM_TOKEN: npm/aws-crypto-tools-ci-bot/2FA:NPM_TOKEN

phases:
install:
commands:
- npm ci --unsafe-perm
# Install `otplib` to extract the OTP from the npm 2FA secret
- npm install otplib --no-save
- npm run build
runtime-versions:
nodejs: 12
pre_build:
commands:
- git checkout $BRANCH
build:
commands:
# Extract the otp using the secrets environment variables from above.
# This will wait for the next token. This is because npm uses
# TOTP and the tokens time out after 30 seconds. If the process just
# extracted the token then the lifetime for this token
# would be very random. This will maximize the amount of time
# available on the OTP to publish.
- >-
OTP=`node -e "
auth=require('otplib').authenticator;
setTimeout(() =>
console.log(auth.generate(process.env.OTP_SECRET_KEY)),
auth.timeRemaining() * 1000);
"`
# npm will only expand env vars inside .npmrc
# NOTE the ' this is to keep the env var NPM_TOKEN from expanding!
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
# Now we publish to npm.
# This is going to use the OTP generated above and the NPM_TOKEN
# environment variable. This will only publish things that are
# missing from npm. It is therefore safe to run repeatedly.
- npx lerna publish from-package --yes --otp $OTP
# remove after publishing
- rm .npmrc

27 changes: 27 additions & 0 deletions codebuild/release/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 0.2

env:
variables:
NODE_OPTIONS: "--max-old-space-size=4096"
BRANCH: "master"
# An explicit version bump
VERSION_BUMP: ""
git-credential-helper: yes

phases:
install:
commands:
- npm ci --unsafe-perm
runtime-versions:
nodejs: 12
pre_build:
commands:
- git config --global user.name "aws-crypto-tools-ci-bot"
- git config --global user.email "no-reply@noemail.local"
- git checkout $BRANCH
build:
commands:
# Generate new version and CHANGELOG entry and push it
- npx lerna version --conventional-commits --git-remote origin --yes ${VERSION_BUMP:+$VERSION_BUMP --force-publish}
# Log the commit for posterity
- git log -n 1
10 changes: 8 additions & 2 deletions codebuild/test_vectors/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ phases:
nodejs: latest
commands:
- npm ci
- npm run build
- |-
if [ "$PUBLISH_LOCAL" = "true" ]; then
npm run build
fi
build:
commands:
- npm run verdaccio-publish
- |-
if [ "$PUBLISH_LOCAL" = "true" ]; then
npm run verdaccio-publish
fi
- npm run verdaccio-browser-decrypt
- npm run verdaccio-browser-encrypt
10 changes: 8 additions & 2 deletions codebuild/test_vectors/nodejs_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ phases:
nodejs: latest
commands:
- npm ci
- npm run build
- |-
if [ "$PUBLISH_LOCAL" = "true" ]; then
npm run build
fi
build:
commands:
- npm run verdaccio-publish
- |-
if [ "$PUBLISH_LOCAL" = "true" ]; then
npm run verdaccio-publish
fi
- npm run verdaccio-node-decrypt
- npm run verdaccio-node-encrypt