-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (173 loc) Β· 6.38 KB
/
python-package.yml
File metadata and controls
200 lines (173 loc) Β· 6.38 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
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
test:
needs: lint
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: π₯ 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: ${{ matrix.python-version }}
- name: ποΈ Sync Environment
run: |
uv sync --frozen --all-extras --python ${{ matrix.python-version }}
- name: π§ͺ Run Tests
env:
CURL_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
COVERAGE_FILE: .coverage.python.${{ matrix.python-version }}
run: |
uv run pytest -v \
--cov=mapchete_hub_cli \
--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-chunk-all
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
summary:
name: "π Final Summary & Coverage"
needs: test
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 Artifacts
uses: actions/download-artifact@v8
with:
path: all-results
pattern: "*-*"
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
# 2. PREPARE COVERAGE DATA
uv tool install coverage
echo "DEBUG: Content of all-results:"
ls -R all-results || echo "all-results not found"
# Move files from download path
if ls all-results/.coverage* 1> /dev/null 2>&1; then
mv all-results/.coverage* .
fi
# π§Ή Delete empty files
find . -maxdepth 1 -name ".coverage*" -size 0 -print -delete
echo "Processing coverage files..."
FILES=$(ls .coverage.* 2>/dev/null | wc -l)
if [ "$FILES" -gt 0 ]; then
if [ "$FILES" -eq 1 ]; then
echo "Single coverage file found, renaming to .coverage"
mv .coverage.* .coverage
else
echo "Multiple coverage files found, combining..."
uv tool run coverage combine
fi
else
echo "β οΈ No coverage files found to process."
fi
# 3. ENFORCE 70%
if [ -f .coverage ]; then
echo "Generating coverage report..."
set +e
REPORT_OUTPUT=$(uv tool run coverage report --show-missing --fail-under=70 2>&1)
EXIT_CODE=$?
set -e
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:** Coverage is below 70%." >> $GITHUB_STEP_SUMMARY
exit $EXIT_CODE
else
echo "β
**Coverage Passed:** 70% coverage achieved." >> $GITHUB_STEP_SUMMARY
fi
else
echo "β **Error:** No coverage data (.coverage) produced." >> $GITHUB_STEP_SUMMARY
fi
# Fail overall if test failed
if [[ "${{ needs.test.result }}" != "success" ]]; then
exit 1
fi