Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions .github/actions/overwrite-package-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,24 @@
# under the License.

name: 'Update Package Version'
description: 'Updates pyproject.toml version with a provided timestamp'
description: 'Sets a PEP 440 version in pyproject.toml for Python builds'
inputs:
timestamp:
description: 'Timestamp to override to the package version'
version:
description: 'PEP 440 version to set in pyproject.toml'
required: true
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.12'

- name: Install toml
run: pip install toml
- name: Install toml-cli
run: cargo install toml-cli
shell: bash

- name: Get and update version
- name: Set pyproject version
shell: bash
env:
TIMESTAMP: ${{ inputs.timestamp }}
VERSION: ${{ inputs.version }}
run: |
# Read the current version from the Rust crate's Cargo.toml
CURRENT_VERSION=$(python -c "import toml; print(toml.load('bindings/python/Cargo.toml')['package']['version'])")
export NEW_VERSION="${CURRENT_VERSION}.dev${TIMESTAMP}"
echo "Current version: ${CURRENT_VERSION}"
echo "New dev version: ${NEW_VERSION}"

# Update bindings/python/pyproject.toml:
# - Set project.version = NEW_VERSION
# - Ensure 'version' is not listed in project.dynamic
python -c "
import toml
import os
config = toml.load('bindings/python/pyproject.toml')
new_version = os.environ['NEW_VERSION']
config['project']['version'] = new_version
if 'dynamic' in config['project']:
config['project']['dynamic'] = [v for v in config['project']['dynamic'] if v != 'version']
with open('bindings/python/pyproject.toml', 'w') as f:
toml.dump(config, f)
print(f'Updated version to: {new_version}')
"
echo "Setting pyproject version to: ${VERSION}"
PYPROJECT="bindings/python/pyproject.toml"
toml set "$PYPROJECT" project.version "${VERSION}" > tmp.toml && mv tmp.toml "$PYPROJECT"
sed 's/dynamic = \["version"\]/dynamic = []/' "$PYPROJECT" > tmp.toml && mv tmp.toml "$PYPROJECT"
13 changes: 0 additions & 13 deletions .github/workflows/bindings_python_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ permissions:
contents: read

jobs:
check-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Check format
working-directory: "bindings/python"
run: cargo fmt --all -- --check
- name: Check clippy
working-directory: "bindings/python"
run: cargo clippy --all-targets --all-features -- -D warnings

check-python:
runs-on: ubuntu-slim
steps:
Expand Down
56 changes: 26 additions & 30 deletions .github/workflows/release_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ jobs:
BASE_VERSION="${CARGO_VERSION%-rc.*}"
echo "Base version (for Cargo.toml comparison): $BASE_VERSION"

# Read version from Cargo.toml and validate it matches
CARGO_TOML_VERSION=$(grep '^version = ' bindings/python/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Version in bindings/python/Cargo.toml: $CARGO_TOML_VERSION"
# Read workspace version via cargo metadata
CARGO_TOML_VERSION=$(cargo metadata --format-version 1 --no-deps -q | jq -r '.packages[0].version')
echo "Workspace version: $CARGO_TOML_VERSION"

if [ "$BASE_VERSION" != "$CARGO_TOML_VERSION" ]; then
echo "❌ Version mismatch!"
echo " Release tag base version: $BASE_VERSION"
echo " bindings/python/Cargo.toml version: $CARGO_TOML_VERSION"
echo " Cargo.toml (workspace) version: $CARGO_TOML_VERSION"
echo "Please ensure the release tag matches the version in Cargo.toml"
exit 1
fi
echo "✅ Version matches bindings/python/Cargo.toml"
echo "✅ Version matches workspace Cargo.toml"
fi

# Check if this is a release candidate
Expand All @@ -107,22 +107,20 @@ jobs:
with:
persist-credentials: false

- name: Install toml-cli
- name: Compute RC version
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
run: cargo install toml-cli

- name: Set cargo version for RC
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
working-directory: "bindings/python"
run: |
echo "Setting cargo version to: ${NEEDS_VALIDATE_RELEASE_TAG_OUTPUTS_CARGO_VERSION}"
toml set Cargo.toml package.version "${NEEDS_VALIDATE_RELEASE_TAG_OUTPUTS_CARGO_VERSION}" > Cargo.toml.tmp
# doing this explicitly to avoid issue in Windows where `mv` does not overwrite existing file
rm Cargo.toml
mv Cargo.toml.tmp Cargo.toml
id: version
shell: bash
env:
NEEDS_VALIDATE_RELEASE_TAG_OUTPUTS_CARGO_VERSION: ${{ needs.validate-release-tag.outputs.cargo-version }}
CARGO_VERSION: ${{ needs.validate-release-tag.outputs.cargo-version }}
run: |
# Convert semver RC (0.9.0-rc.1) to PEP 440 (0.9.0rc1)
echo "pep440=$(echo "$CARGO_VERSION" | sed 's/-rc\.\([0-9]*\)/rc\1/')" >> $GITHUB_OUTPUT

- uses: ./.github/actions/overwrite-package-version
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
with:
version: ${{ steps.version.outputs.pep440 }}

- uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
Expand Down Expand Up @@ -156,22 +154,20 @@ jobs:
with:
persist-credentials: false

- name: Install toml-cli
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
run: cargo install toml-cli

- name: Set cargo version for RC
- name: Compute RC version
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
working-directory: "bindings/python"
id: version
shell: bash
env:
CARGO_VERSION: ${{ needs.validate-release-tag.outputs.cargo-version }}
run: |
echo "Setting cargo version to: $CARGO_VERSION"
toml set Cargo.toml package.version "$CARGO_VERSION" > Cargo.toml.tmp
# doing this explicitly to avoid issue in Windows where `mv` does not overwrite existing file
rm Cargo.toml
mv Cargo.toml.tmp Cargo.toml
# Convert semver RC (0.9.0-rc.1) to PEP 440 (0.9.0rc1)
echo "pep440=$(echo "$CARGO_VERSION" | sed 's/-rc\.\([0-9]*\)/rc\1/')" >> $GITHUB_OUTPUT

- uses: ./.github/actions/overwrite-package-version
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
with:
version: ${{ steps.version.outputs.pep440 }}

- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
Expand All @@ -190,7 +186,7 @@ jobs:
manylinux: ${{ matrix.manylinux || 'auto' }}
working-directory: "bindings/python"
command: build
args: --release -o dist -i python3.12 # Explicitly set interpreter; manylinux containers have multiple Pythons and maturin may pick an older one
args: --profile py-release -o dist -i python3.12 # Explicitly set interpreter; manylinux containers have multiple Pythons and maturin may pick an older one
- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
version: "0.9.3"
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/release_python_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ jobs:
with:
persist-credentials: false

- uses: ./.github/actions/overwrite-package-version # Overwrite package version with timestamp
- name: Compute dev version
id: version
shell: bash
env:
TIMESTAMP: ${{ needs.set-version.outputs.timestamp }}
run: |
CURRENT=$(cargo metadata --format-version 1 --no-deps -q | jq -r '.packages[0].version')
echo "pep440=${CURRENT}.dev${TIMESTAMP}" >> $GITHUB_OUTPUT

- uses: ./.github/actions/overwrite-package-version
with:
timestamp: ${{ needs.set-version.outputs.TIMESTAMP }}
version: ${{ steps.version.outputs.pep440 }}

- uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
Expand Down Expand Up @@ -81,9 +90,18 @@ jobs:
with:
persist-credentials: false

- uses: ./.github/actions/overwrite-package-version # Overwrite package version with timestamp
- name: Compute dev version
id: version
shell: bash
env:
TIMESTAMP: ${{ needs.set-version.outputs.timestamp }}
run: |
CURRENT=$(cargo metadata --format-version 1 --no-deps -q | jq -r '.packages[0].version')
echo "pep440=${CURRENT}.dev${TIMESTAMP}" >> $GITHUB_OUTPUT

- uses: ./.github/actions/overwrite-package-version
with:
timestamp: ${{ needs.set-version.outputs.TIMESTAMP }}
version: ${{ steps.version.outputs.pep440 }}

- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
Expand All @@ -104,7 +122,7 @@ jobs:
manylinux: ${{ matrix.manylinux || 'auto' }}
working-directory: "bindings/python"
command: build
args: --release -o dist -i python3.12 # Explicitly set interpreter; manylinux containers have multiple Pythons and maturin may pick an older one
args: --profile py-release -o dist -i python3.12 # Explicitly set interpreter; manylinux containers have multiple Pythons and maturin may pick an older one

- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
Expand Down
Loading
Loading