11name : Build and Publish to PyPI
22
3- permissions :
4- id-token : write
5-
63on :
74 release :
85 types :
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+
1822jobs :
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/
0 commit comments