-
Notifications
You must be signed in to change notification settings - Fork 1
202 lines (165 loc) · 5.53 KB
/
ci.yml
File metadata and controls
202 lines (165 loc) · 5.53 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
name: CI
on:
push:
branches:
- main
# Uncomment to enable Git Flow workflow
# - develop
workflow_dispatch: {}
permissions:
actions: read
pull-requests: read
contents: read
statuses: write
env:
PYTHON_VERSION: "3.12"
jobs:
verify-version:
name: Verify Project Version Integrity
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check if version already exists
id: version_check
run: |
CURRENT_VERSION=$(grep '^version =' pyproject.toml | cut -d '"' -f 2)
TAG_NAME="v$CURRENT_VERSION"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "::error title=Version Conflict::Version $CURRENT_VERSION already exists as a Git tag ($TAG_NAME).%0A🚨 Action required: Alter 'version' in pyproject.toml before pushing."
exit 1
fi
echo "✅ Version $CURRENT_VERSION is new. Proceeding..."
test:
name: Run Full Test Suite
runs-on: ubuntu-latest
needs: verify-version
strategy:
matrix:
python-version: ['3.12', '3.13', '3.14']
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv and cache dependencies
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install project dependencies
run: |
uv lock
uv sync
- name: Run mypy
run: uv run mypy src/
- name: Run tests with coverage
run: |
mkdir -p .log/coverage
uv run pytest
- name: Upload coverage report as artifact
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION }}
uses: actions/upload-artifact@v6
with:
name: coverage-report-${{ matrix.python-version }}-${{ matrix.os }}-${{ github.run_id }}
path: |
.log/coverage/htmlcov
.log/coverage/coverage.xml
- name: Upload coverage reports to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
build-distribution:
name: Build Package Distribution
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Build sdist and wheel
run: |
uv build
- name: Upload distribution as artifact
uses: actions/upload-artifact@v6
with:
name: python-package-distributions-${{ github.sha }}
path: dist/
build-docker:
name: Build Docker Image & Smoke Test
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Build Docker image
run: |
docker build -t ${{ github.repository }}:${{ github.sha }} -f docker/Dockerfile .
- name: Smoke Test Container
run: |
docker run --rm ${{ github.repository }}:${{ github.sha }}
smoke-test:
name: Smoke Test Distribution
runs-on: ubuntu-latest
needs: build-distribution
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: python-package-distributions-${{ github.sha }}
path: dist/
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install the Wheel
run: |
pip install dist/*.whl
- name: Discover and verify Package
run: |
PKG_NAME=$(ls src | head -n 1)
echo "Detected package: $PKG_NAME"
python -c "import $PKG_NAME; print(f'Successfully imported $PKG_NAME version {$PKG_NAME.__version__}')"
- name: Verify CLI
run: |
WHEEL_FILE=$(ls dist/*.whl | head -n 1)
DIST_NAME=$(basename "$WHEEL_FILE" | cut -d'-' -f1)
echo "Searching for CLI entry points in distribution: $DIST_NAME"
CLI_COMMAND=$(python3 <<EOF
import importlib.metadata
import sys
try:
dist = importlib.metadata.distribution('$DIST_NAME')
scripts = [ep.name for ep in dist.entry_points if ep.group == 'console_scripts']
if scripts:
print(scripts[0])
except importlib.metadata.PackageNotFoundError:
pass
EOF
)
if [ -n "$CLI_COMMAND" ]; then
echo "Found CLI command for $DIST_NAME: $CLI_COMMAND"
$CLI_COMMAND
else
echo "No console_scripts found for $DIST_NAME. Skipping CLI smoke test."
fi