Skip to content

Commit ca817c0

Browse files
Action to publish package in pypi (#3)
1 parent e0dfa1f commit ca817c0

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/publish.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Publish package
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build-and-publish:
13+
name: Build and publish to PyPI
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Validate release tag
25+
id: release
26+
run: |
27+
TAG="${GITHUB_REF_NAME}"
28+
if [[ ! "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
29+
echo "::error::Tag '${TAG}' does not match the expected x.y.z pattern."
30+
exit 1
31+
fi
32+
echo "version=${TAG}" >> "${GITHUB_OUTPUT}"
33+
34+
- name: Update Python project version
35+
env:
36+
RELEASE_VERSION: ${{ steps.release.outputs.version }}
37+
run: |
38+
python - <<'PY'
39+
import os
40+
import pathlib
41+
import re
42+
43+
version = os.environ["RELEASE_VERSION"]
44+
pyproject = pathlib.Path("pyproject.toml")
45+
text = pyproject.read_text()
46+
text = re.sub(r'(?m)^version = ".*"$', f'version = "{version}"', text)
47+
text = re.sub(r'(?m)^dynamic = \["version"\]\n?', "", text)
48+
pyproject.write_text(text)
49+
PY
50+
51+
- name: Publish to PyPI
52+
uses: PyO3/maturin-action@v1
53+
with:
54+
command: publish
55+
args: --manifest-path rust/Cargo.toml --skip-existing
56+
env:
57+
MATURIN_USERNAME: __token__
58+
MATURIN_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)