Skip to content

Commit e383244

Browse files
New CD workflow (#299)
Adjust CD workflow to use new, GitHub actions based workflow.
1 parent 3a720b2 commit e383244

16 files changed

+407
-109
lines changed

.github/workflows/release.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release
2+
3+
env:
4+
GH_TOKEN: ${{ github.token }}
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
release_type:
10+
type: choice
11+
description: "Release type:"
12+
required: true
13+
options:
14+
- bug fix (PATCH)
15+
- new feature (MINOR)
16+
release_title:
17+
description: "The title of the release"
18+
required: true
19+
20+
jobs:
21+
update-version:
22+
runs-on: ubuntu-20.04 # latest
23+
permissions:
24+
contents: write # allow push
25+
pull-requests: write # allow making PR
26+
27+
steps:
28+
- name: Checkout Sources
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Make new release
34+
env:
35+
Title: ${{ github.event.inputs.release_title }}
36+
run: |
37+
# Escape special characters
38+
Title=$(echo ${Title//[\"]\\\"})
39+
Title=$(echo ${Title//[\']\\\'})
40+
Title=$(echo ${Title//[\$]})
41+
42+
./utils/publish-release.sh "${{ github.event.inputs.release_type }}" "$Title"
43+
44+
- name: configure AWS credentials (Release)
45+
uses: aws-actions/configure-aws-credentials@v1
46+
with:
47+
role-to-assume: ${{ secrets.AWS_CI_RELEASE_ROLE }}
48+
aws-region: us-east-1
49+
50+
- name: "Create VERSION file and trigger release"
51+
run: |
52+
version=$(git describe --tags --abbrev=0)
53+
version_without_v=$(echo ${version} | cut -f2 -dv)
54+
echo "${version_without_v}" > VERSION
55+
56+
zip VERSION.zip VERSION
57+
export S3_URL=$(aws secretsmanager get-secret-value --secret-id ci/javascript_v2_version --query "SecretString" | cut -f2 -d\")
58+
aws s3 cp VERSION.zip $S3_URL
59+

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,5 @@ We need your help in making this SDK great. Please participate in the community
126126
## License
127127

128128
This library is licensed under the [Apache 2.0 License](./documents/LICENSE).
129+
130+
Latest released version: v1.8.11

codebuild/cd/publish.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Publishes the new version to NPM.
3+
#
4+
# NOTE: This script assumes that the AWS CLI-V2 is pre-installed!
5+
# - AWS CLI-V2 is a requirement to run this script.
6+
7+
version: 0.2
8+
phases:
9+
install:
10+
runtime-versions:
11+
nodejs: 16
12+
commands:
13+
- echo "\nBuild version data:"
14+
- echo "\nNode Version:"; node --version
15+
- echo "\nNPM Version:"; npm --version
16+
- echo "\n"
17+
pre_build:
18+
commands:
19+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-js-v2
20+
- bash ./codebuild/cd/update-version.sh $CODEBUILD_SRC_DIR/VERSION
21+
build:
22+
commands:
23+
- aws secretsmanager get-secret-value --secret-id cd/aws-sdk-javascript-v2-prod/.npmrc --region us-east-1 | jq -r .SecretString > .npmrc
24+
- npm install
25+
- npm pack
26+
- npm --userconfig ./.npmrc publish aws-iot-device-sdk-v2*.tgz

codebuild/cd/test-publish.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
VERSION_FILE_PATH=$1
5+
if [ ! readlink -e "$VERSION_FILE_PATH" ]; then
6+
echo "No VERSION file found! Cannot make release!"
7+
exit 1
8+
else
9+
echo "VERSION file found..."
10+
fi
11+
VERSION=$(cat $VERSION_FILE_PATH)
12+
13+
# Make sure the version variable is populated
14+
if [ -z "${VERSION}" ]; then
15+
echo "VERSION file is empty!"
16+
exit 1
17+
else
18+
echo "VERSION file contains: ${VERSION}"
19+
fi
20+
21+
# Make sure the version follows the correct format: major.minor.patch
22+
LENGTH_CHECK="${VERSION//[^.]}"
23+
if [ ${#LENGTH_CHECK} != 2 ]; then
24+
echo "VERSION file contains invalid version (not in format major.minor.patch)"
25+
exit 1
26+
fi
27+
# Use RegX to ensure it only contains numbers and periods
28+
REGX_CHECK='^([0-9]+\.){0,2}(\*|[0-9]+)$'
29+
if [[ $VERSION =~ $REGX_CHECK ]]; then
30+
echo "VERSION file contains valid version"
31+
else
32+
echo "VERSION file contains invalid version (RegX validator failed)"
33+
exit 1
34+
fi
35+
36+
PUBLISHED_TAG_VERSION=`npm show aws-iot-device-sdk-v2 version`
37+
if [ "$PUBLISHED_TAG_VERSION" == "$VERSION" ]; then
38+
echo "$VERSION found in npm. Testing release..."
39+
40+
# install the Typescript and the SDK
41+
npm install -g typescript
42+
npm install
43+
44+
# Move to the sample folder and get the endpoint
45+
cd samples/node/pub_sub
46+
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --region us-east-1 --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
47+
48+
# Run the sample!
49+
npm install
50+
node dist/index.js --endpoint $ENDPOINT --ca_file /tmp/AmazonRootCA1.pem --cert /tmp/certificate.pem --key /tmp/privatekey.pem
51+
52+
exit 0
53+
54+
else
55+
echo "$VERSION was not found in npm. Release failed!"
56+
fi
57+
58+
exit 1

codebuild/cd/test-publish.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Tests to make sure the NPM publish worked as expected.
3+
#
4+
# NOTE: This script assumes that the AWS CLI-V2 is pre-installed!
5+
# - AWS CLI-V2 is a requirement to run this script.
6+
7+
version: 0.2
8+
phases:
9+
install:
10+
runtime-versions:
11+
nodejs: 16
12+
commands:
13+
- echo "\nBuild version data:"
14+
- echo "\nNode Version:"; node --version
15+
- echo "\nNPM Version:"; npm --version
16+
- echo "\n"
17+
pre_build:
18+
commands:
19+
# Material for PubSub sample
20+
- curl https://www.amazontrust.com/repository/AmazonRootCA1.pem --output /tmp/AmazonRootCA1.pem
21+
- cert=$(aws secretsmanager get-secret-value --secret-id "ci/PubSub/cert" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo "$cert" > /tmp/certificate.pem
22+
- key=$(aws secretsmanager get-secret-value --secret-id "ci/PubSub/key" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo "$key" > /tmp/privatekey.pem
23+
build:
24+
commands:
25+
- echo Build started on `date`
26+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-js-v2
27+
- bash ./codebuild/cd/test-publish.sh $CODEBUILD_SRC_DIR/VERSION

codebuild/cd/test-version-exists.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
VERSION_FILE_PATH=$1
5+
if [ ! readlink -e "$VERSION_FILE_PATH" ]; then
6+
echo "No VERSION file found! Cannot make release!"
7+
exit 1
8+
else
9+
echo "VERSION file found..."
10+
fi
11+
VERSION=$(cat $VERSION_FILE_PATH)
12+
13+
# Make sure the version variable is populated
14+
if [ -z "${VERSION}" ]; then
15+
echo "VERSION file is empty!"
16+
exit 1
17+
else
18+
echo "VERSION file contains: ${VERSION}"
19+
fi
20+
21+
# Make sure the version follows the correct format: major.minor.patch
22+
LENGTH_CHECK="${VERSION//[^.]}"
23+
if [ ${#LENGTH_CHECK} != 2 ]; then
24+
echo "VERSION file contains invalid version (not in format major.minor.patch)"
25+
exit 1
26+
fi
27+
# Use RegX to ensure it only contains numbers and periods
28+
REGX_CHECK='^([0-9]+\.){0,2}(\*|[0-9]+)$'
29+
if [[ $VERSION =~ $REGX_CHECK ]]; then
30+
echo "VERSION file contains valid version"
31+
else
32+
echo "VERSION file contains invalid version (RegX validator failed)"
33+
exit 1
34+
fi
35+
36+
# Does NPM have the version? If so, do not allow it!
37+
PUBLISHED_TAG_VERSION=`npm show aws-iot-device-sdk-v2 version`
38+
if [ "$PUBLISHED_TAG_VERSION" == "$VERSION" ]; then
39+
echo "$VERSION is already in npm, cut a new tag if you want to upload another version."
40+
exit 1
41+
fi
42+
43+
echo "$VERSION currently does not exist in npm, allowing pipeline to continue."
44+
exit 0

codebuild/cd/test-version-exists.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Makes sure the version in CD has not already been released.
3+
# Will fail the build and stop the pipeline if the version has already been released.
4+
#
5+
# NOTE: This script assumes that the AWS CLI-V2 is pre-installed!
6+
# - AWS CLI-V2 is a requirement to run this script.
7+
8+
version: 0.2
9+
phases:
10+
install:
11+
runtime-versions:
12+
nodejs: 16
13+
commands:
14+
- echo "\nBuild version data:"
15+
- echo "\nNode Version:"; node --version
16+
- echo "\nNPM Version:"; npm --version
17+
- echo "\n"
18+
build:
19+
commands:
20+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-js-v2
21+
- bash ./codebuild/cd/test-version-exists.sh $CODEBUILD_SRC_DIR/VERSION
22+

codebuild/cd/update-version.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
VERSION_FILE_PATH=$1
5+
if [ ! readlink -e "$VERSION_FILE_PATH" ]; then
6+
echo "No VERSION file found! Cannot make release!"
7+
exit 1
8+
else
9+
echo "VERSION file found..."
10+
fi
11+
VERSION=$(cat $VERSION_FILE_PATH)
12+
13+
# Make sure the version variable is populated
14+
if [ -z "${VERSION}" ]; then
15+
echo "VERSION file is empty!"
16+
exit 1
17+
else
18+
echo "VERSION file contains: ${VERSION}"
19+
fi
20+
21+
# Make sure the version follows the correct format: major.minor.patch
22+
LENGTH_CHECK="${VERSION//[^.]}"
23+
if [ ${#LENGTH_CHECK} != 2 ]; then
24+
echo "VERSION file contains invalid version (not in format major.minor.patch)"
25+
exit 1
26+
fi
27+
# Use RegX to ensure it only contains numbers and periods
28+
REGX_CHECK='^([0-9]+\.){0,2}(\*|[0-9]+)$'
29+
if [[ $VERSION =~ $REGX_CHECK ]]; then
30+
echo "VERSION file contains valid version"
31+
else
32+
echo "VERSION file contains invalid version (RegX validator failed)"
33+
exit 1
34+
fi
35+
36+
sed -i -E "s/\"version\": \".+\"/\"version\": \"${VERSION}\"/" package.json
37+
38+
exit 0

continuous-delivery/publish.yml

-15
This file was deleted.

continuous-delivery/test-publish.sh

-33
This file was deleted.

continuous-delivery/test-version-exists.sh

-23
This file was deleted.

continuous-delivery/test-version-exists.yml

-10
This file was deleted.

continuous-delivery/test_publish.yml

-10
This file was deleted.

0 commit comments

Comments
 (0)