Skip to content

Commit 1befa15

Browse files
authoredJan 17, 2025··
add workflow to test against multiple aws-cdk versions (#98)
1 parent 7f784aa commit 1befa15

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
 

‎.github/workflows/test.yml

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Dynamic CDK version testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
inputs:
12+
node-version:
13+
required: false
14+
default: "22.x"
15+
python-version:
16+
required: false
17+
default: "3.12"
18+
run-all-latest-cdk-versions:
19+
required: false
20+
type: boolean
21+
default: false
22+
23+
env:
24+
AWS_ACCESS_KEY_ID: test
25+
AWS_SECRET_ACCESS_KEY: test
26+
AWS_REGION: us-east-1
27+
AWS_DEFAULT_REGION: us-east-1
28+
29+
jobs:
30+
generate-cdk-version-matrix:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
matrix: ${{ steps.set-matrix.outputs.MATRIX }}
34+
steps:
35+
- name: Use Node.js ${{ inputs.node-version }}
36+
uses: actions/setup-node@v2
37+
with:
38+
node-version: ${{ inputs.node-version }}
39+
- name: Obtain all aws-cdk latest versions
40+
id: heavy-matrix
41+
if: ${{ inputs.run-all-latest-cdk-versions == true }}
42+
run: |
43+
export VERSIONS_ARRAY=$(npm view aws-cdk versions --json | jq -c '.[-256:]' )
44+
echo "VERSIONS_ARRAY=$VERSIONS_ARRAY" >> $GITHUB_ENV
45+
46+
- name: Obtain default list of aws-cdk versions
47+
id: simple-matrix
48+
if: ${{ inputs.run-all-latest-cdk-versions == false }}
49+
run: |
50+
export VERSIONS_ARRAY='["2.30.0", "2.50.0", "2.75.0", "2.120.0", "2.166.0", "2.167.0", ""]'
51+
echo "VERSIONS_ARRAY=$VERSIONS_ARRAY" >> $GITHUB_ENV
52+
53+
- name: Generate matrix
54+
id: set-matrix
55+
run: |
56+
export MATRIX="{\"cdk-version\":$VERSIONS_ARRAY}"
57+
echo "MATRIX=$MATRIX" >> $GITHUB_OUTPUT
58+
59+
version-testing:
60+
runs-on: ubuntu-latest
61+
needs: generate-cdk-version-matrix
62+
strategy:
63+
matrix: ${{fromJson(needs.generate-cdk-version-matrix.outputs.matrix)}}
64+
65+
steps:
66+
- uses: actions/checkout@v2
67+
with:
68+
path: repo
69+
70+
- name: Use Node.js ${{ inputs.node-version }}
71+
uses: actions/setup-node@v2
72+
with:
73+
node-version: ${{ inputs.node-version }}
74+
75+
- name: Setup Python ${{ inputs.python-version }}
76+
uses: actions/setup-python@v2
77+
with:
78+
python-version: "${{ inputs.python-version }}"
79+
80+
- name: Install dependencies for aws-cdk-local
81+
working-directory: repo
82+
run: |
83+
npm install
84+
if [ -n "${{ matrix.cdk-version }}" ]; then
85+
npm install aws-cdk@${{ matrix.cdk-version }}
86+
else
87+
npm install aws-cdk
88+
fi
89+
echo "$(pwd)/bin" >> $GITHUB_PATH
90+
91+
- name: Verify specific aws-cdk version is used by cdklocal
92+
run: |
93+
cdklocal --version
94+
95+
- name: Install localstack CLI
96+
run: pip install localstack
97+
98+
- name: Set up unique folder
99+
run: |
100+
export WORK_DIR="cdk-test-$GITHUB_RUN_NUMBER"
101+
export STACK_NAME="CdkTest${GITHUB_RUN_NUMBER}Stack"
102+
mkdir -p $WORK_DIR
103+
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_ENV
104+
echo "STACK_NAME=$STACK_NAME" >> $GITHUB_ENV
105+
106+
- name: Initialize new CDK app
107+
working-directory: ${{env.WORK_DIR}}
108+
run: cdklocal init app --language=python
109+
110+
- name: Start and wait for localstack (Community)
111+
timeout-minutes: 10
112+
run: |
113+
docker pull localstack/localstack:latest
114+
localstack start -d
115+
localstack wait -t 30
116+
117+
- name: Install python libs
118+
working-directory: ${{env.WORK_DIR}}
119+
run: |
120+
source .venv/bin/activate
121+
pip install -r requirements.txt
122+
123+
- name: Run bootstrap
124+
timeout-minutes: 1
125+
working-directory: ${{env.WORK_DIR}}
126+
run: |
127+
source .venv/bin/activate
128+
if [ "${{ matrix.cdk-version }}" = "1.150.0" ]; then
129+
cdklocal acknowledge 19836
130+
fi
131+
cdklocal bootstrap
132+
133+
- name: Deploy
134+
timeout-minutes: 1
135+
working-directory: ${{env.WORK_DIR}}
136+
run: |
137+
source .venv/bin/activate
138+
cdklocal deploy --require-approval=never
139+
140+
- name: Verify successful deployment
141+
run: |
142+
[ $(aws cloudformation describe-stacks --stack-name $STACK_NAME --endpoint-url http://localhost:4566 | jq '[ .Stacks[] | select(.StackStatus == "CREATE_COMPLETE") ] | length') -eq 1 ] || exit 1

0 commit comments

Comments
 (0)
Please sign in to comment.