-
Notifications
You must be signed in to change notification settings - Fork 0
305 lines (268 loc) · 10.3 KB
/
Copy pathpython-package.yml
File metadata and controls
305 lines (268 loc) · 10.3 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Python package test
on:
schedule:
- cron: '0 8 * * 1,4'
push:
branches: [main]
tags: ['*']
pull_request:
branches: ['**']
workflow_call:
inputs:
override-deps-artifact:
description: "Name of artifact containing updated lockfiles"
required: false
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: "📝 Pre-commit / Code Quality"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: ⚡ Setup uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-suffix: ${{ github.job }}
- name: 🏃 Run Pre-commit
run: |
uv tool install pre-commit
uv tool run pre-commit run --show-diff-on-failure --all-files
- name: 🧹 Cache Prune
run: uv cache prune --ci
setup:
name: "🏗️ Build Py${{ matrix.python-version }}"
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v6
- name: 📥 Apply Dependency Overrides
if: "${{ inputs.override-deps-artifact != '' && inputs.override-deps-artifact != 'null' }}"
uses: actions/download-artifact@v8
with:
name: ${{ inputs.override-deps-artifact }}
- name: ⚡ Setup uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-suffix: setup-${{ matrix.python-version }}
- name: 📝 Export Locked Requirements
run: |
uv export --frozen --all-extras --format requirements-txt > requirements.txt
- name: 📤 Upload Requirements
uses: actions/upload-artifact@v7
with:
name: frozen-reqs-${{ matrix.python-version }}
path: requirements.txt
retention-days: 1
test:
needs: setup
name: "🧪 py${{ matrix.python-version }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v6
- name: 📥 Download Requirements
uses: actions/download-artifact@v8
with:
name: frozen-reqs-${{ matrix.python-version }}
- name: ⚡ Install git & GIS Dependencies
run: |
sudo apt-add-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y curl git gpg gdal-bin libgdal-dev libproj-dev libgeos-dev g++
- name: ⚡ Setup uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-suffix: test-${{ matrix.python-version }}
- name: 🏗️ Restore Native Env
run: |
uv venv --python ${{ matrix.python-version }}
uv pip install -r requirements.txt
uv pip install -e ".[test]" --no-deps
- name: 🧪 Run Tests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REQUEST_PAYER: ${{ vars.AWS_REQUEST_PAYER }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CURL_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
COVERAGE_FILE: .coverage.python.${{ matrix.python-version }}
run: |
uv run pytest -v --log-cli-level=DEBUG \
--cov=mapchete_hub \
--cov-report=xml:coverage.xml \
--junitxml="pytest-${{ matrix.python-version }}.xml"
- name: 📊 Upload to Codecov
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: py${{ matrix.python-version }}
fail_ci_if_error: true
- name: 📤 Upload Coverage Chunk (Latest Only)
if: matrix.python-version == '3.13'
uses: actions/upload-artifact@v7
with:
name: coverage-python-${{ matrix.python-version }}
path: .coverage.python.${{ matrix.python-version }}
include-hidden-files: true
retention-days: 1
- name: 📤 Archive JUnit Results
if: always()
uses: actions/upload-artifact@v7
with:
name: results-${{ matrix.python-version }}
path: pytest-${{ matrix.python-version }}.xml
retention-days: 1
- name: 🧹 Cache Prune
run: uv cache prune --ci
integration-tests:
name: "🚀 Integration Tests"
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: ⚡ Setup uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-suffix: ${{ github.job }}
- name: 🏗️ Sync Environment
run: uv sync --all-extras
- name: 🏃 Run Integration Tests
run: |
chmod +x ./run_integration_tests.sh
./run_integration_tests.sh
- name: 🧹 Cache Prune
run: uv cache prune --ci
build-docker-image:
name: "🐳 Docker Build & CLI Check"
if: github.event_name == 'pull_request'
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: ⚡ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🏗️ Build image for validation
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: mapchete-hub:test
- name: 🏃 Run CLI checks
run: |
docker run --rm mapchete-hub:test mhub-server --help
docker run --rm mapchete-hub:test mhub-manager --help
docker run --rm mapchete-hub:test mhub-worker --help
summary:
name: "📊 Final Summary & Coverage"
needs: [test, integration-tests, build-docker-image]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6 # Needed for coverage to see source files
- name: ⚡ Setup uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-suffix: ${{ github.job }}
- name: 📥 Download Results
uses: actions/download-artifact@v8
with:
path: all-results
pattern: results-*
merge-multiple: true
- name: 📥 Download Coverage
uses: actions/download-artifact@v8
with:
path: all-results
pattern: coverage-*
merge-multiple: true
- name: 📊 Check Tests & Coverage
run: |
echo "### 🧪 Test & Coverage Summary" >> $GITHUB_STEP_SUMMARY
# 1. STATUS REPORT
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.test.result }}" == "success" ]]; then
echo "| Unit Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Unit Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ needs.integration-tests.result }}" == "success" ]]; then
echo "| Integration Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Integration Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${{ needs.build-docker-image.result }}" == "success" ]]; then
echo "| Docker Build | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Docker Build | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
fi
# 2. PREPARE COVERAGE DATA (Fetch from Python 3.13 tests only)
uv tool install coverage
if [ -d all-results ]; then
echo "DEBUG: Content of all-results (including hidden):"
ls -Ra all-results
find all-results -name ".coverage*" -exec mv {} . \;
else
echo "⚠️ **Warning:** all-results directory not found. Artifacts might have failed to download." >> $GITHUB_STEP_SUMMARY
fi
# Rename the specific 3.13 file to .coverage if it exists
if [ -f .coverage.python.3.13 ]; then
echo "Found Python 3.13 coverage data, renaming to .coverage"
mv .coverage.python.3.13 .coverage
else
# Fallback: if there's only one coverage file, rename it
FILES=$(ls -a .coverage.* 2>/dev/null | grep -v '^\.$' | grep -v '^\.\.$' | wc -l)
if [ "$FILES" -eq 1 ]; then
mv .coverage.* .coverage
elif [ "$FILES" -gt 1 ]; then
uv tool run coverage combine --append
fi
fi
# 3. ENFORCE 70%
if [ -f .coverage ]; then
echo "Generating coverage report..."
REPORT_OUTPUT=$(uv tool run coverage report --show-missing --fail-under=70 2>&1)
EXIT_CODE=$?
echo "$REPORT_OUTPUT"
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$REPORT_OUTPUT" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# 🔗 GENERATE DYNAMIC CODECOV LINK
CODECOV_URL="https://app.codecov.io/github/${{ github.repository }}/commit/${{ github.sha }}"
echo "🔗 **[View full line-by-line report on Codecov]($CODECOV_URL)**" >> $GITHUB_STEP_SUMMARY
if [ $EXIT_CODE -ne 0 ]; then
echo "❌ **Coverage Failed:** Python 3.13 coverage is below 70%." >> $GITHUB_STEP_SUMMARY
exit $EXIT_CODE
else
echo "✅ **Coverage Passed:** 70% coverage achieved (Py3.13)." >> $GITHUB_STEP_SUMMARY
fi
else
echo "⚠️ **Warning:** No coverage data found for Python 3.13." >> $GITHUB_STEP_SUMMARY
fi
# Fail overall if unit tests failed
if [[ "${{ needs.test.result }}" != "success" ]]; then
exit 1
fi