Skip to content

Commit e062529

Browse files
authored
Migrate to prek (#73)
* Migrate to prek * Set up zizimor * Apply zizmor fixes * Autoupdate * Validate and format YAML and TOML * Add `no-commit-to-branch` * Use tomlkit for toml operations * Update pre-commit reference in development docs * Typo
1 parent e06a19d commit e062529

9 files changed

Lines changed: 467 additions & 408 deletions

File tree

.github/workflows/ci.yml

Lines changed: 103 additions & 99 deletions
Large diffs are not rendered by default.

.github/workflows/docs.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,45 @@ on:
44
push:
55
branches:
66
- dev
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
11+
712
permissions:
813
contents: read
9-
pages: write
10-
id-token: write
14+
1115
jobs:
1216
build:
17+
name: Build documentation
1318
runs-on: ubuntu-latest
1419
steps:
15-
- uses: actions/checkout@v5
16-
- uses: actions/setup-python@v5
20+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
21+
with:
22+
persist-credentials: false
23+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
1724
with:
1825
python-version: "3.14"
19-
- uses: astral-sh/setup-uv@v8.0.0
26+
- uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
2027
with:
2128
enable-cache: true
2229
- run: uv run --extra docs sphinx-build -b html docs site
23-
- uses: actions/upload-pages-artifact@v4
30+
- uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4
2431
with:
2532
path: site
33+
2634
deploy:
35+
name: Deploy to GitHub Pages
2736
if: github.event_name != 'pull_request'
2837
needs: build
38+
permissions:
39+
pages: write # required by actions/deploy-pages to publish the artifact
40+
id-token: write # required by actions/deploy-pages for OIDC verification
2941
environment:
3042
name: github-pages
3143
url: ${{ steps.deployment.outputs.page_url }}
3244
runs-on: ubuntu-latest
3345
steps:
34-
- uses: actions/configure-pages@v5
35-
- uses: actions/deploy-pages@v4
46+
- uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
47+
- uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4
3648
id: deployment

.github/workflows/publish-to-pypi.yml

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Build and Publish to PyPI
22

3-
permissions:
4-
id-token: write
5-
63
on:
74
release:
85
types:
@@ -15,6 +12,13 @@ on:
1512
paths:
1613
- ".github/workflows/publish-to-pypi.yml"
1714

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
18+
19+
permissions:
20+
contents: read
21+
1822
jobs:
1923
build-wheels:
2024
name: Build wheels (${{ matrix.name }})
@@ -37,15 +41,16 @@ jobs:
3741
cibw_before_all: "rustup target add x86_64-apple-darwin aarch64-apple-darwin"
3842

3943
steps:
40-
- uses: actions/checkout@v6
44+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
4145
with:
4246
fetch-depth: 0
47+
persist-credentials: false
4348

4449
- name: Set up Rust
45-
uses: dtolnay/rust-toolchain@stable
50+
run: rustup default stable && rustup update stable
4651

4752
- name: Build wheels
48-
uses: pypa/cibuildwheel@v3.4
53+
uses: pypa/cibuildwheel@8d2b08b68458a16aeb24b64e68a09ab1c8e82084 # v3.4
4954
env:
5055
CIBW_BUILD: "cp310-*"
5156
CIBW_ARCHS: "${{ matrix.cibw_archs }}"
@@ -54,12 +59,12 @@ jobs:
5459
# Validate abi3 compliance and repair wheels
5560
CIBW_BEFORE_BUILD: "pip install abi3audit"
5661
# Ensure wheels include a loadable Rust extension on supported test platforms
57-
CIBW_TEST_COMMAND: 'python -m serialx.tools.list_ports'
62+
CIBW_TEST_COMMAND: "python -m serialx.tools.list_ports"
5863
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "abi3audit {wheel} && delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}"
5964
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "abi3audit {wheel} && cp {wheel} {dest_dir}"
6065

6166
- name: Upload wheels
62-
uses: actions/upload-artifact@v4
67+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
6368
with:
6469
name: wheels-${{ matrix.name }}
6570
path: ./wheelhouse/*.whl
@@ -68,12 +73,13 @@ jobs:
6873
name: Build sdist and pure Python wheel
6974
runs-on: ubuntu-latest
7075
steps:
71-
- uses: actions/checkout@v6
76+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
7277
with:
7378
fetch-depth: 0
79+
persist-credentials: false
7480

7581
- name: Set up Python
76-
uses: actions/setup-python@v6
82+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
7783
with:
7884
python-version: "3.10"
7985

@@ -93,13 +99,13 @@ jobs:
9399
rm dist/*-cp*-*.whl
94100
95101
- name: Upload sdist
96-
uses: actions/upload-artifact@v4
102+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
97103
with:
98104
name: sdist
99105
path: dist/*.tar.gz
100106

101107
- name: Upload wheel
102-
uses: actions/upload-artifact@v4
108+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
103109
with:
104110
name: wheels-ubuntu
105111
path: dist/*.whl
@@ -109,33 +115,36 @@ jobs:
109115
needs: [build-wheels, build-sdist]
110116
runs-on: ubuntu-latest
111117
if: github.event_name == 'release'
118+
permissions:
119+
id-token: write # required for PyPI trusted publishing (OIDC)
112120
steps:
113121
- name: Download all artifacts
114-
uses: actions/download-artifact@v4
122+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
115123
with:
116124
path: dist
117125
merge-multiple: true
118126

119127
- name: Publish serialx to PyPI
120-
uses: pypa/gh-action-pypi-publish@release/v1
128+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1
121129

122130
build-serialx-compat:
123131
name: Build serialx-compat
124132
needs: [build-wheels, build-sdist, publish-pypi]
125133
runs-on: ubuntu-latest
126134
if: ${{ always() && (github.event_name != 'release' || needs['publish-pypi'].result == 'success') }}
127135
steps:
128-
- uses: actions/checkout@v6
136+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
129137
with:
130138
fetch-depth: 0
139+
persist-credentials: false
131140

132141
- name: Set up Python
133-
uses: actions/setup-python@v6
142+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
134143
with:
135-
python-version: "3.10"
144+
python-version: "3.11"
136145

137146
- name: Install build tools
138-
run: pip install build pkginfo
147+
run: pip install build pkginfo tomlkit
139148

140149
- name: Resolve version context for release
141150
if: github.event_name == 'release'
@@ -178,19 +187,20 @@ jobs:
178187
shell: python
179188
run: |
180189
import os
190+
import tomlkit
181191
from pathlib import Path
182192
183193
version = os.environ["SERIALX_PIN_VERSION"]
184194
path = Path("serialx_compat/pyproject.toml")
185-
text = path.read_text()
195+
doc = tomlkit.parse(path.read_text())
196+
197+
assert doc["project"]["version"] == "0.0.0"
198+
assert list(doc["project"]["dependencies"]) == ["serialx"]
186199
187-
assert 'version = "0.0.0"' in text
188-
assert 'dependencies = ["serialx"]' in text
200+
doc["project"]["version"] = version
201+
doc["project"]["dependencies"] = [f"serialx=={version}"]
189202
190-
path.write_text(
191-
text.replace('version = "0.0.0"', f'version = "{version}"')
192-
.replace('dependencies = ["serialx"]', f'dependencies = ["serialx=={version}"]')
193-
)
203+
path.write_text(tomlkit.dumps(doc))
194204
195205
- name: Build serialx-compat
196206
run: python -m build --sdist --wheel --outdir dist-serialx-compat serialx_compat
@@ -223,7 +233,7 @@ jobs:
223233
print(f"{wheel}: {metadata.name} version {version}")
224234
225235
- name: Upload serialx-compat artifacts
226-
uses: actions/upload-artifact@v4
236+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
227237
with:
228238
name: serialx-compat-dist
229239
path: dist-serialx-compat/*
@@ -233,14 +243,16 @@ jobs:
233243
needs: [build-serialx-compat]
234244
runs-on: ubuntu-latest
235245
if: github.event_name == 'release'
246+
permissions:
247+
id-token: write # required for PyPI trusted publishing (OIDC)
236248
steps:
237249
- name: Download serialx-compat artifacts
238-
uses: actions/download-artifact@v4
250+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
239251
with:
240252
name: serialx-compat-dist
241253
path: dist-serialx-compat
242254

243255
- name: Publish serialx-compat to PyPI
244-
uses: pypa/gh-action-pypi-publish@release/v1
256+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1
245257
with:
246258
packages-dir: dist-serialx-compat/

.pre-commit-config.yaml

Lines changed: 0 additions & 46 deletions
This file was deleted.

docs/development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ uv pip install '.[dev,docs]'
1212
On macOS and Windows, a Rust toolchain is required to build the native serial port
1313
enumeration extension. Install Rust via [rustup](https://rustup.rs/).
1414

15-
Set up pre-commit hooks with `pre-commit install`. Your code will then be type checked
15+
Set up pre-commit hooks with `prek install`. Your code will then be type checked
1616
and auto-formatted when you run `git commit`. You can do this on-demand with
17-
`pre-commit run`.
17+
`prek run`.
1818

1919
Serialx relies on automated testing. CI runs tests using both `socat` virtual PTYs
2020
(Linux/macOS) and socket-based serial pairs. To also test with physical adapter pairs,

prek.toml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Configuration file for `prek`, a git hook framework written in Rust.
2+
# See https://prek.j178.dev for more information.
3+
#:schema https://www.schemastore.org/prek.json
4+
5+
[[repos]]
6+
repo = "builtin"
7+
8+
[[repos.hooks]]
9+
id = "no-commit-to-branch"
10+
args = ["--branch", "dev"]
11+
12+
[[repos]]
13+
repo = "https://github.com/codespell-project/codespell"
14+
rev = "v2.4.2"
15+
16+
[[repos.hooks]]
17+
id = "codespell"
18+
additional_dependencies = ["tomli"]
19+
args = ["--toml", "pyproject.toml"]
20+
21+
[[repos]]
22+
repo = "https://github.com/pre-commit/mirrors-mypy"
23+
rev = "v1.20.2"
24+
25+
[[repos.hooks]]
26+
id = "mypy"
27+
additional_dependencies = ["types-pywin32"]
28+
29+
[[repos]]
30+
repo = "https://github.com/astral-sh/ruff-pre-commit"
31+
rev = "v0.15.12"
32+
33+
[[repos.hooks]]
34+
id = "ruff-check"
35+
args = ["--fix"]
36+
37+
[[repos.hooks]]
38+
id = "ruff-format"
39+
40+
[[repos]]
41+
repo = "https://github.com/rbubley/mirrors-prettier"
42+
rev = "v3.8.3"
43+
44+
[[repos.hooks]]
45+
id = "prettier"
46+
files = '^tests/data/pyodide/.*\.(ts|json)$'
47+
48+
[[repos]]
49+
repo = "https://github.com/google/yamlfmt"
50+
rev = "v0.21.0"
51+
52+
[[repos.hooks]]
53+
id = "yamlfmt"
54+
args = ["-formatter", "retain_line_breaks=true"]
55+
56+
[[repos]]
57+
repo = "https://github.com/ComPWA/taplo-pre-commit"
58+
rev = "v0.9.3"
59+
60+
[[repos.hooks]]
61+
id = "taplo-format"
62+
63+
[[repos]]
64+
repo = "local"
65+
66+
[[repos.hooks]]
67+
id = "cargo-fmt"
68+
name = "Cargo fmt"
69+
entry = "cargo fmt --all"
70+
language = "system"
71+
pass_filenames = false
72+
73+
[[repos.hooks]]
74+
id = "cargo-check"
75+
name = "Cargo check"
76+
entry = "cargo check --workspace"
77+
language = "system"
78+
pass_filenames = false
79+
80+
[[repos.hooks]]
81+
id = "rust-clippy"
82+
name = "Cargo clippy"
83+
entry = "cargo clippy --all-targets --all-features -- -Dclippy::all -Dclippy::nursery"
84+
language = "system"
85+
pass_filenames = false
86+
87+
[[repos]]
88+
repo = "https://github.com/zizmorcore/zizmor-pre-commit"
89+
rev = "v1.24.1"
90+
91+
[[repos.hooks]]
92+
id = "zizmor"
93+
args = ["--pedantic"]

0 commit comments

Comments
 (0)