Skip to content

add workflow to test against multiple aws-cdk versions #26

add workflow to test against multiple aws-cdk versions

add workflow to test against multiple aws-cdk versions #26

Workflow file for this run

name: Dynamic CDK version testing
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
node-version:
required: false
default: '22.x'
python-version:
required: false
default: '3.12'
env:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_REGION: us-east-1
AWS_DEFAULT_REGION: us-east-1
jobs:
generate-cdk-version-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.env.MATRIX }}
steps:
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ inputs.node-version }}
- name: Obtain aws-cdk versions
id: set-matrix
run: |
VERSIONS_ARRAY=$(npm show aws-cdk time --json | jq 'del(.created, .modified) | keys' -c)
MATRIX="{\"cdk-version\":$VERSIONS_ARRAY}"
#echo "MATRIX=$MATRIX" >> $GITHUB_ENV
echo "MATRIX=$MATRIX" | tee -a $GITHUB_ENV
echo $MATRIX
version-testing:
runs-on: ubuntu-latest
needs: generate-cdk-version-matrix
strategy:
matrix: ${{fromJson(needs.generate-cdk-version-matrix.outputs.matrix || '{}')}}
steps:
- uses: actions/checkout@v2
with:
path: repo
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ inputs.node-version }}
- name: Setup Python ${{ inputs.python-version }}
uses: actions/setup-python@v2
with:
python-version: '${{ inputs.python-version }}'
- name: Install dependencies for aws-cdk-local
working-directory: repo
run: |
npm install
npm install aws-cdk
if [ -n "${{ matrix.cdk-version }}" ]; then
npm install aws-cdk@${{ matrix.cdk-version }}
fi
echo "$(pwd)/bin" >> $GITHUB_PATH
- name: Verify specific aws-cdk version is used by cdklocal
run: |
cdklocal --version
- name: Install localstack CLI
run: pip install localstack
- name: Set up unique folder
run: |
export WORK_DIR="cdk-test-$GITHUB_RUN_NUMBER"
export STACK_NAME="CdkTest${GITHUB_RUN_NUMBER}Stack"
mkdir -p $WORK_DIR
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_ENV
echo "STACK_NAME=$STACK_NAME" >> $GITHUB_ENV
- name: Initialize new CDK app
working-directory: ${{env.WORK_DIR}}
run: cdklocal init app --language=python
- name: Start and wait for localstack (Community)
timeout-minutes: 10
run: |
docker pull localstack/localstack:latest
localstack start -d
localstack wait -t 30
- name: Install python libs
working-directory: ${{env.WORK_DIR}}
run: |
source .venv/bin/activate
pip install -r requirements.txt
- name: Run bootstrap
timeout-minutes: 1
working-directory: ${{env.WORK_DIR}}
run: |
source .venv/bin/activate
cdklocal bootstrap
- name: Deploy
timeout-minutes: 1
working-directory: ${{env.WORK_DIR}}
run: |
source .venv/bin/activate
cdklocal deploy --require-approval=never
- name: Verify successful deployment
run: |
[ $(aws cloudformation describe-stacks --stack-name $STACK_NAME --endpoint-url http://localhost:4566 | jq '[ .Stacks[] | select(.StackStatus == "CREATE_COMPLETE") ] | length') -eq 1 ] || exit 1