-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (156 loc) · 6.79 KB
/
run-samples.yml
File metadata and controls
182 lines (156 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Samples CI
# Tests Azure samples against the LocalStack emulator.
# Each test runs in its own job. Set DEFAULT_RUN_MODE to 'changed' to only run affected tests.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
run_mode:
description: "Test mode: 'all' runs every test, 'changed' runs only tests with modified files"
required: false
type: choice
options:
- all
- changed
default: changed
# Default run mode for pull_request events (change to 'changed' to only run affected tests)
env:
DEFAULT_RUN_MODE: changed
jobs:
# Lightweight job that builds the dynamic test matrix for the main test jobs
setup:
name: "Build Test Matrix"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
has_tests: ${{ steps.build-matrix.outputs.has_tests }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history needed for git diff in "changed" mode
- name: Build dynamic matrix
id: build-matrix
run: |
# Pick run mode: manual dispatch uses the dropdown, PRs use the env default
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
RUN_MODE="${{ github.event.inputs.run_mode }}"
else
RUN_MODE="${{ env.DEFAULT_RUN_MODE }}"
fi
# In "changed" mode, determine the base commit to diff against
BASE_SHA=""
if [[ "$RUN_MODE" == "changed" ]]; then
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
else
BASE_SHA=$(git rev-parse origin/main 2>/dev/null || git rev-parse HEAD~1)
fi
fi
.github/scripts/build-matrix.sh "$RUN_MODE" "$BASE_SHA"
# Each test runs in its own job — one matrix entry per test from the setup job
scripts:
name: "Test: ${{ matrix.name }}"
needs: setup
if: needs.setup.outputs.has_tests == 'true' # Skip entirely when no tests match
environment: AZURE
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
runs-on: github-ubuntu2204-amd64-4
env:
IMAGE_NAME: localstack/localstack-azure-alpha
DEFAULT_TAG: latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up environment
run: echo "AZURE_CONFIG_DIR=${{ runner.temp }}/azure-cli" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0'
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
- name: Install System Dependencies
# Essential tools for script execution, app packaging, and database connectivity.
# jq: for parsing JSON responses from Azure CLI.
# zip: for packaging function/web apps.
# unixodbc-dev & libsnappy-dev: required for Python database drivers (pyodbc, pymongo).
run: |
sudo apt-get update
sudo apt-get install -y jq zip unixodbc-dev libsnappy-dev
find . -name "*.sh" -exec chmod +x {} +
- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.5.0"
terraform_wrapper: false
- name: Install test dependencies
# Mirroring the localstack-pro approach: install all Python dependencies
# (including the localstack CLI) into a virtual environment to avoid system-level conflicts.
run: make install
- name: Login to Docker Hub
# Mandatory login to Docker Hub to benefit from higher rate limits for authenticated pulls.
# This prevents '429 Too Many Requests' errors during the pull of large emulator images.
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_PULL_USERNAME }}
password: ${{ secrets.DOCKERHUB_PULL_TOKEN }}
- name: Free up disk space
# Azure emulator images are large. Pruning unused Docker objects ensures enough
# disk space is available on the GitHub runner for image pulls and sidecar containers.
run: |
docker system prune -af --volumes
docker builder prune -af
- name: Pull LocalStack Azure Image
# Explicitly pull the image before starting. This mirrors the "Build Docker Image"
# step in localstack-pro and ensures the pull logic is separated from the start logic.
run: docker pull ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}
- name: Start LocalStack
# Run the emulator in detached mode using the virtual environment.
run: |
source .venv/bin/activate
python -m localstack_cli.cli.main start -d
python -m localstack_cli.cli.main wait -t 120
env:
IMAGE_NAME: ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
DOCKER_FLAGS: "-e MSSQL_ACCEPT_EULA=Y"
LS_LOG: "DEBUG"
DISABLE_EVENTS: "1"
ACTIVATE_PRO: "1"
DNS_ADDRESS: "0"
- name: Install Azure Functions Core Tools
# Required for publishing function app samples to the emulator.
run: npm install -g azure-functions-core-tools@4 --unsafe-perm true
- name: Install MSSQL ODBC and Tools
# Required for the 'web-app-sql-database' sample which uses 'sqlcmd' to
# initialize and verify the database schema in the local emulator.
run: |
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18
echo "/opt/mssql-tools18/bin" >> $GITHUB_PATH
- name: "Run: ${{ matrix.name }}"
# Each job runs exactly one test. SPLITS equals the total test count, and SHARD
# is the 1-based index of this specific test, so run-samples.sh executes only it.
run: make test SHARD=${{ matrix.shard }} SPLITS=${{ matrix.splits }}
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
- name: Get LocalStack Logs
# Captured on failure or success to provide a detailed audit trail of the emulator's activity.
if: always()
run: make logs