A version that works on windows

This commit is contained in:
Tom 2025-02-19 17:22:53 +00:00
parent 9873241eab
commit ee546cd788
3 changed files with 35 additions and 7 deletions

View File

@ -36,7 +36,7 @@ jobs:
with:
python-version: 3.x
- name: Set cargo version from tag
run: .github/workflows/update_version.sh
run: python .github/workflows/update_version.py
- name: Build wheels
uses: PyO3/maturin-action@v1
@ -70,7 +70,7 @@ jobs:
with:
python-version: 3.x
- name: Set cargo version from tag
run: .github/workflows/update_version.sh
run: python .github/workflows/update_version.py
- name: Build wheels
uses: PyO3/maturin-action@v1
@ -101,7 +101,7 @@ jobs:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Set cargo version from tag
run: .github/workflows/update_version.sh
run: python .github/workflows/update_version.py
- name: Build wheels
uses: PyO3/maturin-action@v1
@ -130,7 +130,7 @@ jobs:
with:
python-version: 3.x
- name: Set cargo version from tag
run: .github/workflows/update_version.sh
run: python .github/workflows/update_version.py
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
@ -148,7 +148,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set cargo version from tag
run: .github/workflows/update_version.sh
run: python .github/workflows/update_version.py
- name: Build sdist
uses: PyO3/maturin-action@v1
with:

30
.github/workflows/update_version.py vendored Executable file
View File

@ -0,0 +1,30 @@
import re
import subprocess
from pathlib import Path
CARGO_TOML_PATH = Path("Cargo.toml")
# Get the latest Git tag and strip the leading 'v' if present
def get_git_version():
try:
version = subprocess.check_output(["git", "describe", "--tags", "--always"], text=True).strip()
version = re.sub(r"^v", "", version) # Remove leading 'v'
return version
except subprocess.CalledProcessError:
raise RuntimeError("Failed to get Git tag. Make sure you have at least one tag in the repository.")
# Update version in Cargo.toml
def update_cargo_version(new_version):
cargo_toml = CARGO_TOML_PATH.read_text()
# Replace version in [package] section
updated_toml = re.sub(r'^version = "[^"]+"', f'version = "{new_version}"', cargo_toml, flags=re.MULTILINE)
CARGO_TOML_PATH.write_text(updated_toml)
if __name__ == "__main__":
version = get_git_version()
print(f"Parsed version: {version}")
update_cargo_version(version)
print(f"Updated Cargo.toml with version: {version}")

View File

@ -1,2 +0,0 @@
VERSION=$(git describe --tags --always | awk '{gsub(/^v/, ""); print}')
perl -pi -e "s/^version = \"[^\"]+\"/version = \"$VERSION\"/" Cargo.toml