Repository navigation
303 lines (254 loc) · 8.2 KB
/
Copy pathpython-publish.yml
File metadata and controls
303 lines (254 loc) · 8.2 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
name: CI/CD - Python Package
on:
push:
paths:
- "**.py"
- "**.toml"
- "**.yml"
- "**.xml"
pull_request:
paths:
- "**.py"
- "**.toml"
- "**.yml"
- "**.xml"
release:
types:
- published
workflow_dispatch:
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
# A new ruff release may format differently; move the pin on purpose.
- run: python -m pip install ruff==0.16.9
- run: ruff format --check src tests scripts
- run: ruff check src tests scripts
libxr-version:
name: Pin the LibXR commit
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.pin.outputs.commit }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
# The package and the STM32 target test share this one file, so the
# published default LibXR commit is the one that was tested.
- name: Write libxr_version.py
id: pin
run: |
commit=$(python ./scripts/gen_libxr_version.py)
echo "commit=${commit}" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: libxr-version
path: src/libxr/libxr_version.py
if-no-files-found: error
release-version:
name: Check release tag matches package version
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Compare tag and pyproject version
shell: bash
run: |
python - <<'PY'
import os
import sys
import tomllib
with open("pyproject.toml", "rb") as stream:
version = tomllib.load(stream)["project"]["version"]
tag = os.environ["GITHUB_REF_NAME"]
tag_version = tag[1:] if tag[:1] in ("v", "V") else tag
if tag_version != version:
sys.exit(f"Release tag {tag} does not match package version {version}")
print(f"Release tag {tag} matches package version {version}")
PY
discover-stm32-targets:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.targets.outputs.matrix }}
steps:
- name: Checkout STM32 Test Projects
uses: actions/checkout@v4
with:
repository: Jiu-xiao/libxr_stm32_test
path: test-project
- name: Discover STM32 targets
id: targets
run: |
python - <<'PY' >> "$GITHUB_OUTPUT"
import json
from pathlib import Path
root = Path("test-project")
targets = sorted(
path.name
for path in root.iterdir()
if path.is_dir() and not path.name.startswith(".")
and (path / "CMakeLists.txt").is_file()
)
if not targets:
raise SystemExit("No STM32 target directories found")
print("matrix=" + json.dumps({"target": targets}, separators=(",", ":")))
PY
stm32-target-test:
name: STM32 Target (${{ matrix.target }})
runs-on: ubuntu-latest
needs:
- discover-stm32-targets
- libxr-version
container:
image: ghcr.io/xrobot-org/docker-image-stm32:main
options: --user 0
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.discover-stm32-targets.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: libxr-version
path: src/libxr
- name: Install Python Package
run: pip install .
- name: Compiler Version Check
run: |
arm-none-eabi-gcc --version
starm-clang --version
- name: Get Test Projects
uses: actions/checkout@v4
with:
repository: Jiu-xiao/libxr_stm32_test
path: test-project
- name: Resolve matching LibXR ref
id: libxr-ref
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
# A release tests the LibXR commit that the package pins.
ref="${{ needs.libxr-version.outputs.commit }}"
else
ref="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
if ! git ls-remote --exit-code --heads https://github.com/xrobot-org/libxr.git "refs/heads/${ref}" >/dev/null; then
ref="dev"
fi
fi
echo "Using LibXR ref: ${ref}"
echo "ref=${ref}" >> "$GITHUB_OUTPUT"
- name: Run STM32 target test
run: |
cd test-project && ./test.sh "${{ steps.libxr-ref.outputs.ref }}" "${{ matrix.target }}"
build:
name: Build & Test (${{ matrix.os }} - Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
needs: libxr-version
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- uses: actions/download-artifact@v4
with:
name: libxr-version
path: src/libxr
- name: Build Package
run: python -m build
- name: Check Package Metadata
run: twine check dist/*
# Every matrix entry builds the same pure-Python distribution; publish
# exactly one of them so artifacts cannot replace each other.
- name: Upload Built Package
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
uses: actions/upload-artifact@v4
with:
name: python-package
path: dist/*
if-no-files-found: error
- name: Install built package (Linux)
if: runner.os != 'Windows'
run: |
pip install dist/*.whl || pip install dist/*.tar.gz
- name: Install built package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$pkg = Get-ChildItem dist\*.whl,dist\*.tar.gz | Select-Object -First 1
if ($pkg) {
pip install $pkg.FullName
}
# The formatting tests check the generated C++ against this clang-format and are
# skipped without it; another version may format differently, so move the pin on purpose.
- name: Install the pinned clang-format
run: python -m pip install clang-format==21.1.8
# The tests import every module of the installed package (src layout), so a module
# missing from the wheel fails them.
- name: Candidate source regression tests
run: python -m unittest discover -s tests -p "test_*.py" -v
- name: Checkout BSP Compatibility Test Repo
uses: actions/checkout@v4
with:
repository: xrobot-org/bsp_stm32f103
path: bsp_test
- name: Python Compatibility Check (Linux)
if: runner.os != 'Windows'
run: |
cd bsp_test
libxr stm32 setup -d .
- name: Python Compatibility Check (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Set-Location bsp_test
libxr stm32 setup -d .
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs:
- lint
- release-version
- build
- stm32-target-test
if: github.event_name == 'release'
permissions:
id-token: write
environment:
name: XRobot
url: https://pypi.org/project/libxr
steps:
- name: Download built packages
uses: actions/download-artifact@v4
with:
name: python-package
path: dist/
- name: List built packages
run: ls -lh dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
password: ${{ secrets.TOKEN }}