-
Notifications
You must be signed in to change notification settings - Fork 0
285 lines (246 loc) Β· 9.37 KB
/
Copy pathci-cd.yml
File metadata and controls
285 lines (246 loc) Β· 9.37 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
name: Python checks
on:
push:
branches: [ "main" ]
tags: [v*]
pull_request:
merge_group:
env:
FORCE_COLOR: 1
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
linting:
runs-on: ubuntu-latest
name: "Python linting"
permissions:
contents: read
env:
UV_FROZEN: true
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python π
id: python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
cache-dependency-glob: "uv.lock"
python-version: ${{ steps.python.outputs.python-path }}
activate-environment: true
- name: Check lock is up-to-date
run: |
uv lock --check
- name: Install dependencies
run: |
uv sync
- name: Check file formatting
uses: astral-sh/ruff-action@278981a28ce3188b1e39527901f38254bf3aac89 # v4.1.0
with:
args: "format --check"
- name: Lint with ruff
env:
RUFF_OUTPUT_FORMAT: github
run: |
ruff check
- name: Typecheck with pyright
uses: jakebailey/pyright-action@8ec14b5cfe41f26e5f41686a31eb6012758217ef # v3.0.2
with:
version: PATH
tests:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.11", "3.12", "3.13", "3.14"]
include:
- extras_best_effort: false # If True, try to install each extra separately and skip those that fail to install
skip_extras: '' # JSON array of extras not to install
- os: windows-latest
extras_best_effort: true
- os: ubuntu-latest
# cvxopt 1.3.3 wheels for Linux are bundled with GLPK 4.65, which
# has a known bug, see
# https://github.com/cvxopt/cvxopt-wheels/issues/8
skip_extras: '["glpk-mi"]'
name: Python tests (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write # needed for the codecov actions to obtain a OIDC token
env:
UV_FROZEN: true
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }} π
id: python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
cache-dependency-glob: "uv.lock"
python-version: ${{ steps.python.outputs.python-path }}
- name: Install dependencies
run: uv sync
- name: Install additional backends
if: ${{ ! matrix.extras_best_effort && matrix.skip_extras == '' }}
run: uv sync --all-extras
# Windows runners do not have yq installed, so we use the official yq action instead
- name: Enumerate backends
id: backends
uses: mikefarah/yq@1b9b4ac5187171d2e5e3129be0cfa827c7f9d53d # v4.53.3
if: ${{ matrix.extras_best_effort || matrix.skip_extras != '' }}
with:
cmd: |
# for each extra, output the extra name followed by the listed dependencies, space-separated
yq --output-format=yaml '
.project.optional-dependencies
| to_entries[]
| .value |= join(" ")
| "\(.key) \(.value)"
' pyproject.toml
- name: Install additional backends (best effort)
if: ${{ matrix.extras_best_effort || matrix.skip_extras != '' }}
env:
NO_COLOR: 1
SKIP_EXTRAS: ${{ matrix.skip_extras && matrix.skip_extras || '[]' }}
EXTRAS: ${{ steps.backends.outputs.result }}
shell: bash
run: |
set -eu -o pipefail
while read -r -a extra_deps; do
extra_name="${extra_deps[0]}"
if jq --exit-status --null-input --argjson skip_extras "${SKIP_EXTRAS}" --arg extra "${extra_name}" \
'$skip_extras | contains([$extra])' > /dev/null;
then
echo "NOT installing $extra_name backend"
continue
fi
deps=("${extra_deps[@]:1}")
echo "::group::Installing $extra_name backend"
uv pip install "${deps[@]}" \
|| IFS=' ' echo "::warning title=Could not install $extra_name solver backend::Failed to install ${deps[*]}"
echo "::endgroup::"
done <<< "$EXTRAS"
- name: Test with pytest
run: |
# codecov requires that the test results are shared in xunit1 / legacy format.
uv run pytest -v --junitxml=junit.xml -o junit_family=legacy
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
use_oidc: true
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
report_type: test_results
use_oidc: true
test-summary:
name: Test matrix status
runs-on: ubuntu-latest
needs:
- linting
- tests
if: always()
steps:
- name: Decide whether the needed jobs succeeded or failed
env:
SUCCEEDED: ${{ !(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')) }}
run: |
echo "All jobs passed: ${SUCCEEDED}"
if [ "${SUCCEEDED}" = 'false' ]; then exit 1; fi
build:
name: Build distribution π¦
runs-on: ubuntu-latest
permissions:
contents: read
env:
UV_FROZEN: true
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs:
- test-summary
outputs:
version: ${{ steps.note.outputs.version }}
prerelease: ${{ steps.note.outputs.prerelease }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python π
id: python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: false
cache-dependency-glob: "uv.lock"
python-version: ${{ steps.python.outputs.python-path }}
- name: Build the Python π binary wheel and source tarball π¦
id: build-dist
run: |
uv build
rm -f dist/.gitignore # get-releasenotes can't handle non-dist files here
echo "version=$(uvx uv-dynamic-versioning@0.14.0)" >> "$GITHUB_OUTPUT"
- name: Check build
run: uvx twine@7.0.0 check --strict dist/*
- name: Prepare Release Note
id: note
uses: aio-libs/get-releasenote@b0fcc7f3e5f5cc7c8b01e2f75516b1732f6bd8b2 # v1.4.5
with:
changes_file: CHANGELOG.md
output_file: release_notes.md
version: ${{ steps.build-dist.outputs.version }}
start_line: '<!-- changes go below this line -->'
head_line: '## \[{version}\] - {date}'
name: Rummikub Solver library
dist_dir: dist
- name: Store the Python π distribution π¦
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-package-distributions
path: |
dist/
release_notes.md
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs:
- build
environment:
name: pypi
url: https://pypi.org/p/rummikub-solver
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # required for creating GH releases
steps:
- name: Download Python π distribution π¦
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-package-distributions
- name: Publish Python π distribution π¦ to PyPI
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
- name: GitHub release
env:
RELEASE_TITLE: Rummikub Solver library ${{ needs.build.outputs.version }}
PRERELEASE_SWITCH: ${{ case(fromJSON(needs.build.outputs.prerelease), '--prerelease', '') }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release create --title "${RELEASE_TITLE}" --notes-file release_notes.md "${PRERELEASE_SWITCH}" "${GITHUB_REF_NAME}" dist/*