Skip to content

Commit 4a5a05c

Browse files
New CD workflow (#371)
Adjust CD workflow to use new, GitHub actions based workflow.
1 parent 252b969 commit 4a5a05c

15 files changed

+344
-109
lines changed

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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/python_v2_version --query "SecretString" | cut -f2 -d\")
58+
aws s3 cp VERSION.zip $S3_URL

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ We need your help in making this SDK great. Please participate in the community
9999
## License
100100

101101
This library is licensed under the [Apache 2.0 License](./documents/LICENSE).
102+
103+
Latest released version: v1.12.0

continuous-delivery/publish_to_prod_pypi.yml renamed to codebuild/cd/publish-to-prod-pypi.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Makes a release deployment to production PyPi repo.
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.
16
version: 0.2
2-
# this image assumes Ubuntu base image
37
phases:
48
install:
59
commands:
@@ -8,11 +12,13 @@ phases:
812
- export PATH=$PATH:$HOME/.local/bin
913
- python3 -m pip install --user --upgrade pip
1014
- python3 -m pip install --user --upgrade twine setuptools wheel awscli PyOpenSSL six
15+
- echo "\nBuild version data:"
16+
- echo "\nPython Version:"; python3 --version
1117
pre_build:
1218
commands:
13-
- cd aws-iot-device-sdk-python-v2
14-
- pypirc=$(aws secretsmanager get-secret-value --secret-id "prod/aws-sdk-python-v2/.pypirc" --query "SecretString" | cut -f2 -d\") && echo "$pypirc" > ~/.pypirc
15-
- export PKG_VERSION=$(git describe --tags | cut -f2 -dv)
19+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-python-v2
20+
- pypirc=$(aws secretsmanager get-secret-value --secret-id "cd/aws-sdk-python-v2-prod/.pypirc" --query "SecretString" | cut -f2 -d\") && echo "$pypirc" > ~/.pypirc
21+
- export PKG_VERSION=$(cat $CODEBUILD_SRC_DIR/VERSION)
1622
- echo "Updating package version to ${PKG_VERSION}"
1723
- sed --in-place -E "s/__version__ = '.+'/__version__ = '${PKG_VERSION}'/" awsiot/__init__.py
1824
build:

continuous-delivery/publish_to_test_pypi.yml renamed to codebuild/cd/publish-to-test-pypi.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Makes a release deployment to test PyPi repo.
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.
16
version: 0.2
2-
# this image assumes Ubuntu base image
37
phases:
48
install:
59
commands:
@@ -8,11 +12,13 @@ phases:
812
- export PATH=$PATH:$HOME/.local/bin
913
- python3 -m pip install --user --upgrade pip
1014
- python3 -m pip install --user --upgrade twine setuptools wheel awscli PyOpenSSL six
15+
- echo "\nBuild version data:"
16+
- echo "\nPython Version:"; python3 --version
1117
pre_build:
1218
commands:
13-
- pypirc=$(aws secretsmanager get-secret-value --secret-id "alpha/aws-crt-python/.pypirc" --query "SecretString" | cut -f2 -d\") && echo "$pypirc" > ~/.pypirc
14-
- cd aws-iot-device-sdk-python-v2
15-
- export PKG_VERSION=$(git describe --tags | cut -f2 -dv)
19+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-python-v2
20+
- pypirc=$(aws secretsmanager get-secret-value --secret-id "cd/aws-sdk-python-v2-test/.pypirc" --query "SecretString" | cut -f2 -d\") && echo "$pypirc" > ~/.pypirc
21+
- export PKG_VERSION=$(cat $CODEBUILD_SRC_DIR/VERSION)
1622
- echo "Updating package version to ${PKG_VERSION}"
1723
- sed --in-place -E "s/__version__ = '.+'/__version__ = '${PKG_VERSION}'/" awsiot/__init__.py
1824
build:

codebuild/cd/test-prod-pypi.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Makes sure the release to test PyPi repository worked
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+
version: 0.2
7+
phases:
8+
install:
9+
commands:
10+
- sudo apt-get update -y
11+
- sudo apt-get install python3 python3-pip -y
12+
- python3 -m pip install --upgrade pip
13+
- python3 -m pip install --upgrade setuptools
14+
- echo "\nBuild version data:"
15+
- echo "\nPython Version:"; python3 --version
16+
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+
- ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
24+
build:
25+
commands:
26+
- echo Build started on `date`
27+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-python-v2
28+
- CURRENT_TAG_VERSION=$(cat $CODEBUILD_SRC_DIR/VERSION)
29+
- python3 codebuild/cd/pip-install-with-retry.py --no-cache-dir --user awsiotsdk==$CURRENT_TAG_VERSION
30+
# Run PubSub sample
31+
- python3 samples/pubsub.py --endpoint ${ENDPOINT} --cert /tmp/certificate.pem --key /tmp/privatekey.pem --ca_file /tmp/AmazonRootCA1.pem --verbosity Trace
32+
33+
post_build:
34+
commands:
35+
- echo Build completed on `date`
36+

codebuild/cd/test-test-pypi.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Assumes are running using the Ubuntu Codebuild standard image
2+
# Makes sure the release to test PyPi repository worked
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+
version: 0.2
7+
phases:
8+
install:
9+
commands:
10+
- sudo apt-get update -y
11+
- sudo apt-get install python3 python3-pip -y
12+
- python3 -m pip install --upgrade pip
13+
- python3 -m pip install --upgrade setuptools
14+
- echo "\nBuild version data:"
15+
- echo "\nPython Version:"; python3 --version
16+
17+
pre_build:
18+
commands:
19+
- curl https://www.amazontrust.com/repository/AmazonRootCA1.pem --output /tmp/AmazonRootCA1.pem
20+
- cert=$(aws secretsmanager get-secret-value --secret-id "ci/PubSub/cert" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo "$cert" > /tmp/certificate.pem
21+
- key=$(aws secretsmanager get-secret-value --secret-id "ci/PubSub/key" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo "$key" > /tmp/privatekey.pem
22+
- ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
23+
build:
24+
commands:
25+
- echo Build started on `date`
26+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-python-v2
27+
- CURRENT_TAG_VERSION=$(cat $CODEBUILD_SRC_DIR/VERSION)
28+
# this is here because typing isn't in test-pypi, so pull it from prod instead
29+
- python3 -m pip install typing
30+
- python3 codebuild/cd/pip-install-with-retry.py -i https://testpypi.python.org/simple --user awsiotsdk==$CURRENT_TAG_VERSION
31+
# Run PubSub sample
32+
- python3 samples/pubsub.py --endpoint ${ENDPOINT} --cert /tmp/certificate.pem --key /tmp/privatekey.pem --ca_file /tmp/AmazonRootCA1.pem --verbosity Trace
33+
34+
post_build:
35+
commands:
36+
- echo Build completed on `date`

codebuild/cd/test-version-exists.sh

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

codebuild/cd/test-version-exists.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
version: 0.2
8+
phases:
9+
install:
10+
commands:
11+
- sudo apt-get update -y
12+
- sudo apt-get install python3 python3-pip -y
13+
- pip3 install --upgrade setuptools
14+
- echo "\nBuild version data:"
15+
- echo "\nPython Version:"; python3 --version
16+
build:
17+
commands:
18+
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-python-v2
19+
- bash ./codebuild/cd/test-version-exists.sh $CODEBUILD_SRC_DIR/VERSION

continuous-delivery/test_prod_pypi.yml

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

continuous-delivery/test_test_pypi.yml

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

continuous-delivery/test_version_exists

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

continuous-delivery/test_version_exists.yml

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

0 commit comments

Comments
 (0)