11name : Samples CI
22
3- # Theory of Operation:
4- # This workflow automates the testing of Azure sample applications against the LocalStack Azure emulator.
5- # It follows the best practices from the localstack-pro repository:
6- # 1. Parallel Testing: Splits the sample suite into shards to reduce execution time.
7- # 2. Standardized Tooling: Uses a Makefile for environment setup and test orchestration.
8- # 3. Cloud Emulation: Configures the Azure CLI to target the LocalStack emulator.
9- # 4. IaC Coverage: Tests bash scripts, Terraform deployments, and Bicep deployments.
3+ # Tests Azure samples against the LocalStack emulator.
4+ # Each test runs in its own job. Set DEFAULT_RUN_MODE to 'changed' to only run affected tests.
105
116concurrency :
127 group : ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1611 pull_request :
1712 branches : [ main ]
1813 workflow_dispatch :
14+ inputs :
15+ run_mode :
16+ description : " Test mode: 'all' runs every test, 'changed' runs only tests with modified files"
17+ required : false
18+ type : choice
19+ options :
20+ - all
21+ - changed
22+ default : changed
23+
24+ # Default run mode for pull_request events (change to 'changed' to only run affected tests)
25+ env :
26+ DEFAULT_RUN_MODE : changed
1927
2028jobs :
29+ # Lightweight job that builds the dynamic test matrix for the main test jobs
30+ setup :
31+ name : " Build Test Matrix"
32+ runs-on : ubuntu-latest
33+ outputs :
34+ matrix : ${{ steps.build-matrix.outputs.matrix }}
35+ has_tests : ${{ steps.build-matrix.outputs.has_tests }}
36+ steps :
37+ - name : Checkout repo
38+ uses : actions/checkout@v4
39+ with :
40+ fetch-depth : 0 # Full history needed for git diff in "changed" mode
41+
42+ - name : Build dynamic matrix
43+ id : build-matrix
44+ run : |
45+ # Pick run mode: manual dispatch uses the dropdown, PRs use the env default
46+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
47+ RUN_MODE="${{ github.event.inputs.run_mode }}"
48+ else
49+ RUN_MODE="${{ env.DEFAULT_RUN_MODE }}"
50+ fi
51+
52+ # In "changed" mode, determine the base commit to diff against
53+ BASE_SHA=""
54+ if [[ "$RUN_MODE" == "changed" ]]; then
55+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
56+ BASE_SHA="${{ github.event.pull_request.base.sha }}"
57+ else
58+ BASE_SHA=$(git rev-parse origin/main 2>/dev/null || git rev-parse HEAD~1)
59+ fi
60+ fi
61+
62+ .github/scripts/build-matrix.sh "$RUN_MODE" "$BASE_SHA"
63+
64+ # Each test runs in its own job — one matrix entry per test from the setup job
2165 scripts :
22- name : " Run Test Scripts (amd64) — Part ${{ matrix.shard }} of ${{ matrix.splits }}"
66+ name : " Test: ${{ matrix.name }}"
67+ needs : setup
68+ if : needs.setup.outputs.has_tests == 'true' # Skip entirely when no tests match
2369 environment : AZURE
2470 strategy :
2571 fail-fast : false
26- matrix :
27- shard : [1, 2, 3, 4]
28- splits : [4]
29- runs-on : github-ubuntu2204-amd64-4
30-
72+ matrix : ${{ fromJSON(needs.setup.outputs.matrix) }}
73+ runs-on : ubuntu-22.04
74+
3175 env :
3276 IMAGE_NAME : localstack/localstack-azure-alpha
3377 DEFAULT_TAG : latest
4892 - name : Set up .NET
4993 uses : actions/setup-dotnet@v4
5094 with :
51- dotnet-version : ' 9.0'
95+ dotnet-version : ' 10.0'
96+
97+ - uses : actions/setup-java@v5
98+ with :
99+ distribution : ' temurin'
100+ java-version : ' 25'
52101
53102 - name : Install System Dependencies
54103 # Essential tools for script execution, app packaging, and database connectivity.
67116 terraform_wrapper : false
68117
69118 - name : Install test dependencies
70- # Mirroring the localstack-pro approach: install all Python dependencies
119+ # Mirroring the localstack-pro approach: install all Python dependencies
71120 # (including the localstack CLI) into a virtual environment to avoid system-level conflicts.
72121 run : make install
73122
@@ -80,24 +129,23 @@ jobs:
80129 password : ${{ secrets.DOCKERHUB_PULL_TOKEN }}
81130
82131 - name : Free up disk space
83- # Azure emulator images are large. Pruning unused Docker objects ensures enough
132+ # Azure emulator images are large. Pruning unused Docker objects ensures enough
84133 # disk space is available on the GitHub runner for image pulls and sidecar containers.
85134 run : |
86135 docker system prune -af --volumes
87136 docker builder prune -af
88137
89138 - name : Pull LocalStack Azure Image
90- # Explicitly pull the image before starting. This mirrors the "Build Docker Image"
139+ # Explicitly pull the image before starting. This mirrors the "Build Docker Image"
91140 # step in localstack-pro and ensures the pull logic is separated from the start logic.
92141 run : docker pull ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}
93142
94143 - name : Start LocalStack
95144 # Run the emulator in detached mode using the virtual environment.
96- # We use 'python -m localstack.cli.main' to ensure the correct CLI version from the venv is used.
97145 run : |
98146 source .venv/bin/activate
99- python -m localstack .cli.main start -d
100- python -m localstack .cli.main wait -t 120
147+ python -m localstack_cli .cli.main start -d
148+ python -m localstack_cli .cli.main wait -t 120
101149 env :
102150 IMAGE_NAME : ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}
103151 LOCALSTACK_AUTH_TOKEN : ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
@@ -109,21 +157,35 @@ jobs:
109157
110158 - name : Install Azure Functions Core Tools
111159 # Required for publishing function app samples to the emulator.
112- run : npm install -g azure-functions-core-tools@4 --unsafe-perm true
160+ run : |
161+ MAX_RETRIES=3
162+ DELAY=15
163+ for i in $(seq 1 $MAX_RETRIES); do
164+ echo "Attempt $i/$MAX_RETRIES..."
165+ npm install -g azure-functions-core-tools@4 --unsafe-perm true && break
166+ if [ "$i" -eq "$MAX_RETRIES" ]; then
167+ echo "All $MAX_RETRIES attempts failed"
168+ exit 1
169+ fi
170+ echo "Retrying in ${DELAY}s..."
171+ sleep $DELAY
172+ DELAY=$((DELAY * 2))
173+ done
113174
114175 - name : Install MSSQL ODBC and Tools
115- # Required for the 'web-app-sql-database' sample which uses 'sqlcmd' to
176+ # Required for the 'web-app-sql-database' sample which uses 'sqlcmd' to
116177 # initialize and verify the database schema in the local emulator.
117178 run : |
179+ sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
118180 curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
119181 curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
120182 sudo apt-get update
121183 sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18
122184 echo "/opt/mssql-tools18/bin" >> $GITHUB_PATH
123185
124- - name : Run Test Scripts
125- # Executes the sharded test suite. Each shard runs a subset of samples in parallel.
126- # This includes bash scripts, Terraform deployments, and Bicep deployments .
186+ - name : " Run: ${{ matrix.name }} "
187+ # Each job runs exactly one test. SPLITS equals the total test count, and SHARD
188+ # is the 1-based index of this specific test, so run-samples.sh executes only it .
127189 run : make test SHARD=${{ matrix.shard }} SPLITS=${{ matrix.splits }}
128190 env :
129191 LOCALSTACK_AUTH_TOKEN : ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
0 commit comments