Skip to content

Commit fa8e769

Browse files
committed
reform the cloud pods action
1 parent 2645fee commit fa8e769

File tree

1 file changed

+93
-48
lines changed

1 file changed

+93
-48
lines changed
Lines changed: 93 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,109 @@
1-
name: Test Released Cloud Pods
1+
name: Create and Test LocalStack Cloud Pod
22

33
on:
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

915
permissions:
1016
contents: write
17+
actions: read
1118

1219
jobs:
13-
get-releases:
14-
name: Retrieve Released Cloud Pods
20+
create-pod:
21+
name: Create Cloud Pod
1522
runs-on: ubuntu-latest
1623
outputs:
17-
matrix: ${{ steps.set-matrix.outputs.matrix }}
24+
pod_artifact_name: cloud-pod-${{ github.run_id }}
1825
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
26+
- name: Checkout Code
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.11'
33+
34+
- name: Install Dependencies
35+
run: |
36+
pip install -r requirements-dev.txt --upgrade
37+
38+
- name: Start LocalStack
39+
uses: LocalStack/setup-localstack@main
40+
with:
41+
use-pro: 'true'
42+
install-awslocal: 'true'
43+
env:
44+
DEBUG: 1
45+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
46+
47+
- name: Deploy Infrastructure (Example)
48+
run: |
49+
bin/build_lambdas.sh && deployment/awslocal/deploy.sh
3850
39-
# Loading it manually as we're storing the state as a release and not an artifact
40-
- name: Retrieve Pod
51+
- name: Export LocalStack State (Cloud Pod)
52+
id: export_state
4153
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
4355
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
56+
echo "Exporting LocalStack state..."
57+
localstack state export cloud-pod.zip
58+
ls -la cloud-pod.zip # Verify the file exists
59+
echo "pod_artifact_name=cloud-pod-${{ github.run_id }}" >> $GITHUB_OUTPUT
60+
61+
- name: Upload Cloud Pod Artifact
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: ${{ steps.export_state.outputs.pod_artifact_name }}
65+
path: cloud-pod.zip
66+
retention-days: 1
67+
68+
test-pod:
69+
name: Test Cloud Pod
70+
needs: create-pod
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout Code
74+
uses: actions/checkout@v4
5175

5276
- name: Setup Python
53-
uses: actions/setup-python@v4
77+
uses: actions/setup-python@v5
5478
with:
5579
python-version: '3.11'
5680

81+
- name: Install Test Dependencies
82+
run: |
83+
pip install -r requirements-dev.txt --upgrade
84+
5785
- name: Start LocalStack
58-
uses: LocalStack/setup-localstack@v0.2.2
86+
uses: LocalStack/setup-localstack@main
5987
with:
60-
image-tag: ${{ matrix.tag }}
6188
use-pro: 'true'
6289
install-awslocal: 'true'
6390
env:
6491
DEBUG: 1
6592
POD_LOAD_CLI_TIMEOUT: 300
66-
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
93+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
94+
95+
- name: Download Cloud Pod Artifact
96+
uses: actions/download-artifact@v4
97+
with:
98+
name: ${{ needs.create-pod.outputs.pod_artifact_name }}
6799

68-
- name: Inject Pod
100+
- name: Inject Pod (Import State)
69101
env:
70-
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
102+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
71103
run: |
72-
localstack state import release-pod.zip
104+
echo "Importing LocalStack state from cloud-pod.zip..."
105+
ls -la # Check if download was successful
106+
localstack state import cloud-pod.zip
73107
74108
- name: Run Tests
75109
env:
@@ -78,12 +112,12 @@ jobs:
78112
AWS_ACCESS_KEY_ID: test
79113
AWS_SECRET_ACCESS_KEY: test
80114
run: |
81-
pip install -r requirements-dev.txt
82115
pytest tests
83116
84-
- name: Show Logs
85-
if: failure()
117+
- name: Show LocalStack Logs
118+
if: always()
86119
run: |
120+
echo "::error::Tests failed. Dumping LocalStack logs:"
87121
localstack logs
88122
89123
- name: Send a Slack notification
@@ -99,10 +133,21 @@ jobs:
99133
env:
100134
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
101135

102-
- name: Prevent Workflows from getting Stale
103-
if: always()
136+
- name: Generate a Diagnostic Report
137+
if: failure()
138+
run: |
139+
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
140+
141+
- name: Upload the Diagnostic Report
142+
if: failure()
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: diagnose.json.gz
146+
path: ./diagnose.json.gz
147+
148+
- name: Prevent Workflow from becoming Stale
149+
if: always() && github.ref == 'refs/heads/main'
104150
uses: gautamkrishnar/keepalive-workflow@v1
105151
with:
106-
# this message should prevent automatic triggering of workflows
107-
# see https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
108152
commit_message: "[skip ci] Automated commit by Keepalive Workflow to keep the repository active"
153+
gh_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)