From b449cafc46592807aa091c6b441eed5087c9dd38 Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Sun, 7 Jun 2026 08:45:16 -0700 Subject: [PATCH 1/2] Add dedicated release workflow; split CI from deploy Replace the deploy jobs that were bolted onto the CI workflow with a purpose-built release pipeline, and slim the CI workflow to test + lint. release.yml (new): - Verifies the git tag matches the pyproject.toml and Cargo.toml versions before anything is published. - Native Linux test gate so a broken build never reaches an index. - Broader wheel coverage: manylinux + musllinux for x86_64 and aarch64, Windows x64, macOS x86_64 + arm64 (abi3, one wheel per platform/arch). - Collects all artifacts and runs twine check (now fatal) before publishing. - Publishes to PyPI on a v* tag via trusted publishing (OIDC) with PEP 740 attestations; TestPyPI is available on demand via workflow_dispatch. - Creates a GitHub Release with notes extracted from CHANGELOG.md and the built artifacts attached. ci.yml (renamed from test_and_deploy.yml): - Test matrix (Linux/macOS/Windows x Python 3.10-3.13) plus the fmt/clippy lint job. No longer triggers on tags or carries deploy jobs. Remove test_pypi.yml; TestPyPI publishing now lives in release.yml and uses trusted publishing instead of a long-lived API token. --- .github/workflows/ci.yml | 67 ++++++++ .github/workflows/release.yml | 217 +++++++++++++++++++++++++ .github/workflows/test_and_deploy.yml | 218 -------------------------- .github/workflows/test_pypi.yml | 36 ----- 4 files changed, 284 insertions(+), 254 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/test_and_deploy.yml delete mode 100644 .github/workflows/test_pypi.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3147275 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: ["**"] + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Test ${{ matrix.os }} / py${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ["3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - name: Build and install + run: | + python -m pip install --upgrade pip + pip install maturin pytest numpy + maturin develop --release + + - name: Run tests + run: pytest python/tests -v + + rust-lint: + name: Rust fmt & clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Check formatting + run: cargo fmt --check + # --lib avoids linking a test executable, which fails for an + # extension-module cdylib (no libpython to link against). + - name: Clippy + run: cargo clippy --release --lib -- -D warnings diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..be77b3d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,217 @@ +name: Release + +# Publish to PyPI on a version tag (e.g. `v0.1.0`), or to TestPyPI on demand. +# +# Tag flow: +# 1. Bump the version in pyproject.toml + Cargo.toml and update CHANGELOG.md. +# 2. git tag v0.1.0 && git push --tags +# 3. This workflow verifies the tag matches the version, runs the tests, +# builds wheels + sdist, publishes to PyPI via trusted publishing, and +# creates a GitHub Release with notes from the changelog. +# +# TestPyPI flow: +# Actions -> Release -> Run workflow -> target = testpypi. + +on: + push: + tags: ["v*"] + workflow_dispatch: + inputs: + target: + description: "Where to publish" + required: true + default: testpypi + type: choice + options: [testpypi, pypi] + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + # Fail fast if the tag doesn't match the packaged version. + check-version: + name: Check version matches tag + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Verify tag == pyproject == Cargo version + if: startsWith(github.ref, 'refs/tags/v') + run: | + tag="${GITHUB_REF_NAME#v}" + pyproject=$(grep -m1 '^version = ' pyproject.toml | sed -E 's/.*"(.*)".*/\1/') + cargo=$(grep -m1 '^version = ' Cargo.toml | sed -E 's/.*"(.*)".*/\1/') + echo "tag=$tag pyproject=$pyproject cargo=$cargo" + if [ "$tag" != "$pyproject" ] || [ "$tag" != "$cargo" ]; then + echo "::error::Tag ($tag) must match pyproject.toml ($pyproject) and Cargo.toml ($cargo)" + exit 1 + fi + + # Native test gate so we never publish broken code. + test: + name: Test (Linux) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: dtolnay/rust-toolchain@stable + - name: Build and test + run: | + python -m pip install --upgrade pip + pip install maturin pytest numpy + maturin develop --release + pytest python/tests -v + + build-wheels: + name: Wheel ${{ matrix.platform }} ${{ matrix.target }} ${{ matrix.manylinux }} + needs: [test] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - { os: ubuntu-latest, platform: linux, target: x86_64, manylinux: auto } + - { os: ubuntu-latest, platform: linux, target: aarch64, manylinux: auto } + - { os: ubuntu-latest, platform: linux, target: x86_64, manylinux: musllinux_1_2 } + - { os: ubuntu-latest, platform: linux, target: aarch64, manylinux: musllinux_1_2 } + - { os: windows-latest, platform: windows, target: x64 } + - { os: macos-13, platform: macos, target: x86_64 } + - { os: macos-14, platform: macos, target: aarch64 } + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + manylinux: ${{ matrix.manylinux }} + args: --release --out dist + sccache: "true" + - uses: actions/upload-artifact@v4 + with: + name: wheels-${{ matrix.platform }}-${{ matrix.target }}-${{ matrix.manylinux || 'native' }} + path: dist/*.whl + + build-sdist: + name: Source distribution + needs: [test] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist + - uses: actions/upload-artifact@v4 + with: + name: sdist + path: dist/*.tar.gz + + # Gather everything and validate before any publish step touches an index. + collect: + name: Collect and check artifacts + needs: [build-wheels, build-sdist] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + pattern: "wheels-*" + path: dist + merge-multiple: true + - uses: actions/download-artifact@v4 + with: + name: sdist + path: dist + - name: List and check + run: | + ls -la dist/ + echo "wheels: $(ls dist/*.whl | wc -l), sdists: $(ls dist/*.tar.gz | wc -l)" + pip install twine + twine check dist/* + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/* + + publish-testpypi: + name: Publish to TestPyPI + needs: [collect] + if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi' + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/rstar-python + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist + - name: Publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + packages-dir: dist/ + # TestPyPI rejects PEP 740 attestations; disable for it. + attestations: false + skip-existing: true + verbose: true + + publish-pypi: + name: Publish to PyPI + needs: [check-version, collect] + if: >- + startsWith(github.ref, 'refs/tags/v') || + (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi') + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/rstar-python + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist + - name: Publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ + attestations: true + verbose: true + + github-release: + name: GitHub Release + needs: [publish-pypi] + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist + - name: Extract changelog section + id: notes + run: | + version="${GITHUB_REF_NAME#v}" + # Pull the section for this version out of CHANGELOG.md. + awk -v v="$version" ' + $0 ~ "^## \\[" v "\\]" {grab=1; next} + grab && /^## \[/ {exit} + grab {print} + ' CHANGELOG.md > notes.md + if [ ! -s notes.md ]; then echo "See CHANGELOG.md for details." > notes.md; fi + echo "Release notes:"; cat notes.md + - name: Create release + uses: softprops/action-gh-release@v2 + with: + body_path: notes.md + files: dist/* + fail_on_unmatched_files: true diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml deleted file mode 100644 index 69df3dd..0000000 --- a/.github/workflows/test_and_deploy.yml +++ /dev/null @@ -1,218 +0,0 @@ -name: CI - -on: - push: - branches: [ main ] - tags: ["v*"] - pull_request: - branches: [ "**" ] - workflow_dispatch: # Allow manual trigger - -concurrency: - group: wheel-${{ github.ref }} - cancel-in-progress: true - -env: - MACOSX_DEPLOYMENT_TARGET: "10.12" - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.10", "3.11", "3.12", "3.13"] - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Create virtual environment - run: | - python -m venv .venv - - - name: Install dependencies (Unix) - if: runner.os != 'Windows' - run: | - source .venv/bin/activate - python -m pip install --upgrade pip - pip install maturin pytest numpy - - - name: Install dependencies (Windows) - if: runner.os == 'Windows' - run: | - .venv\Scripts\activate - python -m pip install --upgrade pip - pip install maturin pytest numpy - - - name: Build and install (Unix) - if: runner.os != 'Windows' - run: | - source .venv/bin/activate - maturin develop --release - - - name: Build and install (Windows) - if: runner.os == 'Windows' - run: | - .venv\Scripts\activate - maturin develop --release - - - name: Run tests (Unix) - if: runner.os != 'Windows' - run: | - source .venv/bin/activate - pytest python/tests -v - - - name: Run tests (Windows) - if: runner.os == 'Windows' - run: | - .venv\Scripts\activate - pytest python/tests -v - - rust-lint: - name: Rust fmt & clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy - - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Check formatting - run: cargo fmt --check - # --lib avoids linking a test executable, which fails for an - # extension-module cdylib (no libpython to link against). - - name: Clippy - run: cargo clippy --release --lib -- -D warnings - - make_sdist: - needs: [test, rust-lint] - name: Make SDist - runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: true - - - name: Build sdist - uses: PyO3/maturin-action@v1 - with: - command: sdist - args: --out dist - - - name: Check sdist - run: | - ls -la dist/ - # Make twine check non-fatal for now - pip install twine - twine check dist/* || echo "Twine check failed but continuing" - - - uses: actions/upload-artifact@v4 - with: - name: pypi-sdist - path: dist/*.tar.gz - - build_wheels: - name: Build wheels on ${{ matrix.os }} - needs: [test, rust-lint] - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-13, macos-14] - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: true - - - name: Build wheels - Linux - if: runner.os == 'Linux' - uses: PyO3/maturin-action@v1 - with: - target: x86_64 - args: --release --out dist - sccache: 'true' - manylinux: auto - - - name: Build wheels - Windows - if: runner.os == 'Windows' - uses: PyO3/maturin-action@v1 - with: - target: x64 - args: --release --out dist - sccache: 'true' - - - name: Build wheels - macOS (Intel) - if: matrix.os == 'macos-13' - uses: PyO3/maturin-action@v1 - with: - target: x86_64 - args: --release --out dist - sccache: 'true' - - - name: Build wheels - macOS (Apple Silicon) - if: matrix.os == 'macos-14' - uses: PyO3/maturin-action@v1 - with: - target: aarch64 - args: --release --out dist - sccache: 'true' - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: pypi-wheels-${{ matrix.os }} - path: dist/*.whl - - upload_pypi: - name: Upload to PyPI - needs: [build_wheels, make_sdist] - environment: - name: pypi - url: https://pypi.org/p/rstar-python - permissions: - id-token: write - runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - - steps: - - uses: actions/download-artifact@v4 - with: - pattern: pypi-* - path: dist - merge-multiple: true - - - name: List artifacts - run: | - ls -la dist/ - echo "Found $(ls dist/*.whl | wc -l) wheel files" - echo "Found $(ls dist/*.tar.gz | wc -l) source distributions" - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages-dir: dist/ - verify-metadata: true - skip-existing: false - verbose: true \ No newline at end of file diff --git a/.github/workflows/test_pypi.yml b/.github/workflows/test_pypi.yml deleted file mode 100644 index 4a1f11e..0000000 --- a/.github/workflows/test_pypi.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Test PyPI Release - -on: - workflow_dispatch: - inputs: - version: - description: 'Version to release (e.g., 0.1.0rc1)' - required: true - -jobs: - build_and_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Update version - run: | - sed -i 's/version = ".*"/version = "${{ github.event.inputs.version }}"/' pyproject.toml - sed -i 's/version = ".*"/version = "${{ github.event.inputs.version }}"/' Cargo.toml - - - name: Build with maturin - uses: PyO3/maturin-action@v1 - with: - command: build - args: --release --sdist - - - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ - password: ${{ secrets.TEST_PYPI_API_TOKEN }} \ No newline at end of file From 637a7387fb425a72a04e5487ba2e38c24b04bde5 Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Sun, 7 Jun 2026 08:54:11 -0700 Subject: [PATCH 2/2] Fix CI: build+install wheel instead of maturin develop maturin develop requires an activated virtualenv, which the runners don't have. Build a wheel and pip-install it instead, which works uniformly on Linux/macOS/Windows without venv activation. --- .github/workflows/ci.yml | 5 ++++- .github/workflows/release.yml | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3147275..5a5aa35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,11 +32,14 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable + # maturin develop needs an activated virtualenv; building a wheel and + # installing it works uniformly across OSes without one. - name: Build and install run: | python -m pip install --upgrade pip pip install maturin pytest numpy - maturin develop --release + maturin build --release --out dist + pip install --no-index --find-links dist rstar-python - name: Run tests run: pytest python/tests -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be77b3d..7715ba6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,8 @@ jobs: run: | python -m pip install --upgrade pip pip install maturin pytest numpy - maturin develop --release + maturin build --release --out dist + pip install --no-index --find-links dist rstar-python pytest python/tests -v build-wheels: