add workflow to test against multiple aws-cdk versions #14
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Dynamic CDK version testing | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: '0 5 * * *' # once daily at 5AM | |
workflow_dispatch: | |
inputs: | |
cdk-version: | |
description: Upstream aws-cdk version to use in tests | |
required: false | |
env: | |
AWS_ACCESS_KEY_ID: test | |
AWS_SECRET_ACCESS_KEY: test | |
AWS_REGION: us-east-1 | |
AWS_DEFAULT_REGION: us-east-1 | |
jobs: | |
dynamic-cdk-version-testing: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: ['22.x'] | |
python-version: ['3.12'] | |
cdk-version: ${{ fromJson(inputs.cdk-version || '[""]') }} | |
fail-fast: False | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
path: repo | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v2 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '${{ matrix.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: | | |
if [ -n "${{ matrix.cdk-version }}" ]; then | |
[[ $(cdklocal --version) =~ ^${{ matrix.cdk-version }}.* ]] || exit 1 | |
else | |
echo "Latest version installed, skipping version verification." | |
fi | |
- 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: | | |
# Check if the localstack-main container is already running | |
if ! docker ps --filter "name=localstack-main" --filter "status=running" -q; then | |
echo "LocalStack container is not running. Starting LocalStack..." | |
docker pull localstack/localstack:latest | |
localstack start -d | |
localstack wait -t 30 | |
else | |
echo "LocalStack container is already running. Skipping start." | |
fi | |
- 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 AppTest --endpoint-url http://localhost:4566 | jq '[ .Stacks[] | select(.StackStatus == "CREATE_COMPLETE") ] | length') -eq 1 ] || exit 1 |