From ee546cd788e8ca57f79723729bfc94bb9dd35869 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 19 Feb 2025 17:22:53 +0000 Subject: [PATCH] A version that works on windows --- .github/workflows/build_wheels.yml | 10 +++++----- .github/workflows/update_version.py | 30 +++++++++++++++++++++++++++++ .github/workflows/update_version.sh | 2 -- 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100755 .github/workflows/update_version.py delete mode 100755 .github/workflows/update_version.sh diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index b9ce0df..428dd22 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -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: diff --git a/.github/workflows/update_version.py b/.github/workflows/update_version.py new file mode 100755 index 0000000..6b897f4 --- /dev/null +++ b/.github/workflows/update_version.py @@ -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}") \ No newline at end of file diff --git a/.github/workflows/update_version.sh b/.github/workflows/update_version.sh deleted file mode 100755 index b12be4a..0000000 --- a/.github/workflows/update_version.sh +++ /dev/null @@ -1,2 +0,0 @@ -VERSION=$(git describe --tags --always | awk '{gsub(/^v/, ""); print}') -perl -pi -e "s/^version = \"[^\"]+\"/version = \"$VERSION\"/" Cargo.toml