1- name : Test Released Cloud Pods
1+ name : Create and Test LocalStack Cloud Pod
22
33on :
44 schedule :
5- # “ At 00:00 on Saturday.”
5+ # At 00:00 on Saturday.
66 - cron : " 0 0 * * 6"
7+ push :
8+ branches :
9+ - main
10+ pull_request :
11+ branches :
12+ - main
713 workflow_dispatch :
814
915permissions :
1016 contents : write
17+ actions : read
1118
1219jobs :
13- get-releases :
14- name : Retrieve Released Cloud Pods
20+ create-pod :
21+ name : Create Cloud Pod
1522 runs-on : ubuntu-latest
23+ permissions :
24+ actions : write
1625 outputs :
17- matrix : ${{ steps.set-matrix.outputs.matrix }}
26+ pod_artifact_name : cloud-pod- ${{ github.run_id }}
1827 steps :
19- - id : set-matrix
20- env :
21- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22- run : |
23- output=$(gh api repos/$GITHUB_REPOSITORY/releases | jq -r '[.[] | select(.tag_name|startswith("v")|not) | .tag_name]')
24- output=$(echo $output | tr '\n' ' ')
25- echo "matrix=$output" >> $GITHUB_OUTPUT
26-
27- test-pod-release :
28- needs : get-releases
29- runs-on : ubuntu-latest
30- strategy :
31- fail-fast : false
32- matrix :
33- tag : ${{ fromJson(needs.get-releases.outputs.matrix) }}
34- steps :
35- # checkout to run the tests later on
36- - name : Checkout
37- uses : actions/checkout@v3
28+ - name : Checkout Code
29+ uses : actions/checkout@v4
30+
31+ - name : Setup Python
32+ uses : actions/setup-python@v5
33+ with :
34+ python-version : ' 3.11'
35+
36+ - name : Install Dependencies
37+ run : |
38+ pip install -r requirements-dev.txt --upgrade
39+
40+ - name : Start LocalStack
41+ uses : LocalStack/setup-localstack@main
42+ with :
43+ use-pro : ' true'
44+ install-awslocal : ' true'
45+ env :
46+ DEBUG : 1
47+ LOCALSTACK_AUTH_TOKEN : ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
48+
49+ - name : Deploy Infrastructure (Example)
50+ run : |
51+ bin/build_lambdas.sh && deployment/awslocal/deploy.sh
3852
39- # Loading it manually as we're storing the state as a release and not an artifact
40- - name : Retrieve Pod
53+ - name : Export LocalStack State (Cloud Pod)
54+ id : export_state
4155 env :
42- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
56+ LOCALSTACK_AUTH_TOKEN : ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
4357 run : |
44- # TODO the download url seems to follow the pattern $GITHUB_REPOSITORY/releases/download/{TAG}/{ASSET_NAME}
45- # alternatively we can query the asset-id, and browser_download_url, but it seems like an overhead
46- # asset_id=$(gh api repos/$GITHUB_REPOSITORY/releases/tags/latest | jq -r '.assets[]' | jq --arg DB $DB -c 'select(.name=="release-pod-\( $DB ).zip") | .id)
47- # download_url=$(gh api repos/$GITHUB_REPOSITORY/releases/assets/$asset_id | jq -r ".browser_download_url")
48- download_url="https://github.com/$GITHUB_REPOSITORY/releases/download/${{ matrix.tag }}/release-pod.zip"
49- curl -L $download_url --output release-pod.zip
50- ls -la
58+ echo "Exporting LocalStack state..."
59+ localstack state export cloud-pod.zip
60+ ls -la cloud-pod.zip # Verify the file exists
61+ echo "pod_artifact_name=cloud-pod-${{ github.run_id }}" >> $GITHUB_OUTPUT
62+
63+ - name : Upload Cloud Pod Artifact
64+ uses : actions/upload-artifact@v4
65+ with :
66+ name : ${{ steps.export_state.outputs.pod_artifact_name }}
67+ path : cloud-pod.zip
68+ retention-days : 1
69+
70+ test-pod :
71+ name : Test Cloud Pod
72+ needs : create-pod
73+ runs-on : ubuntu-latest
74+ steps :
75+ - name : Checkout Code
76+ uses : actions/checkout@v4
5177
5278 - name : Setup Python
53- uses : actions/setup-python@v4
79+ uses : actions/setup-python@v5
5480 with :
5581 python-version : ' 3.11'
5682
83+ - name : Install Test Dependencies
84+ run : |
85+ pip install -r requirements-dev.txt --upgrade
86+
5787 - name : Start LocalStack
58- uses : LocalStack/setup-localstack@v0.2.2
88+ uses : LocalStack/setup-localstack@main
5989 with :
60- image-tag : ${{ matrix.tag }}
6190 use-pro : ' true'
6291 install-awslocal : ' true'
6392 env :
6493 DEBUG : 1
6594 POD_LOAD_CLI_TIMEOUT : 300
66- LOCALSTACK_API_KEY : ${{ secrets.LOCALSTACK_API_KEY }}
95+ LOCALSTACK_AUTH_TOKEN : ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
96+
97+ - name : Download Cloud Pod Artifact
98+ uses : actions/download-artifact@v4
99+ with :
100+ name : ${{ needs.create-pod.outputs.pod_artifact_name }}
67101
68- - name : Inject Pod
102+ - name : Inject Pod (Import State)
69103 env :
70- LOCALSTACK_API_KEY : ${{ secrets.LOCALSTACK_API_KEY }}
104+ LOCALSTACK_AUTH_TOKEN : ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
71105 run : |
72- localstack state import release-pod.zip
106+ echo "Importing LocalStack state from cloud-pod.zip..."
107+ ls -la # Check if download was successful
108+ localstack state import cloud-pod.zip
73109
74110 - name : Run Tests
75111 env :
@@ -78,11 +114,10 @@ jobs:
78114 AWS_ACCESS_KEY_ID : test
79115 AWS_SECRET_ACCESS_KEY : test
80116 run : |
81- pip install -r requirements-dev.txt
82117 pytest tests
83118
84- - name : Show Logs
85- if : failure ()
119+ - name : Show LocalStack Logs
120+ if : always ()
86121 run : |
87122 localstack logs
88123
@@ -99,10 +134,18 @@ jobs:
99134 env :
100135 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
101136
102- - name : Prevent Workflows from getting Stale
103- if : always()
104- uses : gautamkrishnar/keepalive-workflow@v1
137+ - name : Generate a Diagnostic Report
138+ if : failure()
139+ run : |
140+ curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
141+
142+ - name : Upload the Diagnostic Report
143+ if : failure()
144+ uses : actions/upload-artifact@v4
105145 with :
106- # this message should prevent automatic triggering of workflows
107- # see https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
108- commit_message : " [skip ci] Automated commit by Keepalive Workflow to keep the repository active"
146+ name : diagnose.json.gz
147+ path : ./diagnose.json.gz
148+
149+ - name : Prevent Workflow from becoming Stale
150+ if : always() && github.ref == 'refs/heads/main'
151+ uses : liskin/gh-workflow-keepalive@v1
0 commit comments