From 5847c0826f70411fc2460d7b63b613626de3b190 Mon Sep 17 00:00:00 2001 From: Mathias Vanden Auweele Date: Mon, 25 May 2026 15:57:54 +0200 Subject: [PATCH] ci: update pypi version from git tag before building Maturin reads the version from pyproject.toml and the workspace Cargo.toml. Without updating these files the built wheel always carries the placeholder version (0.0.1) and the upload to PyPI fails with '400 File already exists'. Add an 'Update release version' step (shell: bash for cross-platform compatibility) to both build-wheels and build-sdist jobs that patches: - tp-py/pyproject.toml [project] version - Cargo.toml workspace version (inherited via version.workspace) - tp-py/Cargo.toml tp-lib-core path-dependency version pin This mirrors the approach already used in publish-crates.yml. The NuGet workflow already handles versioning correctly via -p:PackageVersion and required no changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/publish-pypi.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 6dcef48..94bb476 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -34,7 +34,18 @@ jobs: - name: Install maturin run: pip install maturin - + + - name: Update release version + shell: bash + run: | + TAG_VERSION="${GITHUB_REF#refs/tags/v}" + + python -c "import re, pathlib; p = pathlib.Path('tp-py/pyproject.toml'); p.write_text(re.sub(r'^version = \".*\"', f'version = \"${TAG_VERSION}\"', p.read_text(), count=1, flags=re.M))" + + python -c "import re, pathlib; p = pathlib.Path('Cargo.toml'); p.write_text(re.sub(r'^version = \".*\"', f'version = \"${TAG_VERSION}\"', p.read_text(), count=1, flags=re.M))" + + python -c "import re, pathlib; p = pathlib.Path('tp-py/Cargo.toml'); p.write_text(re.sub(r'(tp-lib-core = \{[^}]*version = \")[^\"]+(\"[^}]*\})', lambda m: m.group(1) + '${TAG_VERSION}' + m.group(2), p.read_text()))" + - name: Build wheels run: | cd tp-py @@ -63,7 +74,18 @@ jobs: - name: Install maturin run: pip install maturin - + + - name: Update release version + shell: bash + run: | + TAG_VERSION="${GITHUB_REF#refs/tags/v}" + + python -c "import re, pathlib; p = pathlib.Path('tp-py/pyproject.toml'); p.write_text(re.sub(r'^version = \".*\"', f'version = \"${TAG_VERSION}\"', p.read_text(), count=1, flags=re.M))" + + python -c "import re, pathlib; p = pathlib.Path('Cargo.toml'); p.write_text(re.sub(r'^version = \".*\"', f'version = \"${TAG_VERSION}\"', p.read_text(), count=1, flags=re.M))" + + python -c "import re, pathlib; p = pathlib.Path('tp-py/Cargo.toml'); p.write_text(re.sub(r'(tp-lib-core = \{[^}]*version = \")[^\"]+(\"[^}]*\})', lambda m: m.group(1) + '${TAG_VERSION}' + m.group(2), p.read_text()))" + - name: Build sdist run: | cd tp-py