-
Notifications
You must be signed in to change notification settings - Fork 435
152 lines (144 loc) · 5.15 KB
/
python.yml
File metadata and controls
152 lines (144 loc) · 5.15 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
# Runs pre-commit linting hooks, builds the Python wheel package, and tests across multiple Python versions.
# Uploads the wheel artifact for use by downstream workflows.
name: Python CI
on:
pull_request: # Run on every pull request
push: # Run on pushes that affect the python code
paths:
- '.github/workflows/python.yml'
- '**/*.py'
# Cancel a currently running workflow from the same PR, branch, or tag when a new workflow is triggered:
# Taken from https://stackoverflow.com/a/72408109
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
pre-commit:
name: Pre-commit hooks
runs-on: ubuntu-latest
env:
UV_LOCKED: true
UV_COMPILE_BYTECODE: true
UV_NO_EDITABLE: true
UV_NO_PROGRESS: true
UV_NO_SYNC: true
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v7
with:
# https://docs.astral.sh/uv/guides/integration/github/#using-uv-in-github-actions
# It is considered best practice to pin to a specific uv version
version: "0.9.26"
# https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching
enable-cache: true
prune-cache: false
cache-python: true
cache-dependency-glob: uv.lock
tool-dir: /home/runner/.cache/uv
- name: setup-uv cache indicator
if: steps.setup-uv.outputs.cache-hit == 'true'
run: echo "setup uv cache was restored"
- name: Restore cache
uses: actions/cache@v5
id: cache-pre-commit
with:
# This covers the tool installed by uvx as well as the pre-commit environment
path: /home/runner/.cache
key: pre-commit-${{ github.head_ref || github.ref_name }}-${{ hashFiles('uv.lock') }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Cache indicator
if: steps.cache-pre-commit.outputs.cache-hit == 'true'
run: echo "cache was restored"
- name: Install pre-commit
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: uv tool install pre-commit
- name: Run pre-commit hooks
run: >
uv tool run
pre-commit run
--verbose
--all-files
--show-diff-on-failure
--color=always
# The Python package is required in the subsequent Docker image build
build_package:
name: Build Python wheel
needs: pre-commit
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
UV_LOCKED: true
UV_COMPILE_BYTECODE: true
UV_NO_EDITABLE: true
UV_NO_PROGRESS: true
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install uv and set the python version
id: setup-uv
uses: astral-sh/setup-uv@v7
with:
# https://docs.astral.sh/uv/guides/integration/github/#using-uv-in-github-actions
# It is considered best practice to pin to a specific uv version
version: "0.9.26"
# https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching
enable-cache: true
cache-dependency-glob: uv.lock
cache-python: true
- name: Cache indicator
if: steps.setup-uv.outputs.cache-hit == 'true'
run: echo "uv cache was restored"
- name: Build Python package
run: uv build --wheel --refresh
- name: Upload Python package
uses: actions/upload-artifact@v6
with:
name: python-package
path: dist/
retention-days: 1
test:
name: Python tests
needs: [pre-commit, build_package]
runs-on: ubuntu-latest
env:
UV_LOCKED: true
UV_COMPILE_BYTECODE: true
UV_NO_EDITABLE: true
UV_NO_PROGRESS: true
UV_NO_SYNC: true
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install uv and set the python version
id: setup-uv
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}
# https://docs.astral.sh/uv/guides/integration/github/#using-uv-in-github-actions
# It is considered best practice to pin to a specific uv version
version: "0.9.26"
# https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching
enable-cache: true
cache-dependency-glob: uv.lock
- name: Cache indicator
if: steps.setup-uv.outputs.cache-hit == 'true'
run: echo "uv cache was restored"
- name: Download Python package artifact
uses: actions/download-artifact@v7
with:
name: python-package
path: dist/
- name: Install python dependencies
run: uv sync --locked --no-install-project --no-editable --no-dev --group test
- name: Install python package from wheel
run: uv pip install dist/*.whl
- name: Run tests
run: uv run --verbose pytest -m ci