Merge pull request #12 from CocoRoF/main #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to PyPI | |
| on: | |
| push: | |
| branches: | |
| - deploy | |
| paths: | |
| - "pyproject.toml" | |
| jobs: | |
| # --------------------------------------------------------------------------- | |
| # 1. Check if the version actually changed | |
| # --------------------------------------------------------------------------- | |
| check-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_changed: ${{ steps.check.outputs.changed }} | |
| new_version: ${{ steps.check.outputs.new_version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check version change | |
| id: check | |
| run: | | |
| # Extract version from pyproject.toml | |
| NEW_VERSION=$(grep -oP '^version\s*=\s*"\K[^"]+' pyproject.toml) | |
| echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| # Verify Cargo.toml version matches | |
| CARGO_VERSION=$(grep -oP '^version\s*=\s*"\K[^"]+' Cargo.toml) | |
| if [ "$NEW_VERSION" != "$CARGO_VERSION" ]; then | |
| echo "::error::Version mismatch! pyproject.toml=$NEW_VERSION vs Cargo.toml=$CARGO_VERSION" | |
| exit 1 | |
| fi | |
| # Compare with previous commit | |
| OLD_VERSION=$(git show HEAD~1:pyproject.toml 2>/dev/null | grep -oP '^version\s*=\s*"\K[^"]+' || echo "") | |
| echo "Old version: $OLD_VERSION" | |
| echo "New version: $NEW_VERSION" | |
| if [ -z "$OLD_VERSION" ] || [ "$OLD_VERSION" != "$NEW_VERSION" ]; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "Version changed: $OLD_VERSION -> $NEW_VERSION" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Version unchanged, skipping publish." | |
| fi | |
| # --------------------------------------------------------------------------- | |
| # 2. Run tests before building wheels | |
| # --------------------------------------------------------------------------- | |
| test: | |
| needs: check-version | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - name: Checkout code | |
| 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 toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install package and test deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install .[dev] | |
| - name: Run tests | |
| run: python -m pytest -v --tb=short | |
| # --------------------------------------------------------------------------- | |
| # 3. Build native wheels for all platforms | |
| # --------------------------------------------------------------------------- | |
| build-wheels: | |
| needs: [check-version, test] | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # ── Linux x86_64 ── | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| manylinux: auto | |
| # ── Linux aarch64 ── | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| manylinux: auto | |
| # ── macOS x86_64 (Intel) ── | |
| - os: macos-14 | |
| target: x86_64-apple-darwin | |
| manylinux: "off" | |
| # ── macOS aarch64 (Apple Silicon) ── | |
| - os: macos-14 | |
| target: aarch64-apple-darwin | |
| manylinux: "off" | |
| # ── Windows x86_64 ── | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| manylinux: "off" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.target }} | |
| args: --release --out dist --interpreter 3.10 3.11 3.12 3.13 | |
| manylinux: ${{ matrix.manylinux }} | |
| before-script-linux: | | |
| # Ensure OpenSSL dev headers are available for native-tls | |
| if command -v yum &> /dev/null; then | |
| yum install -y openssl-devel perl-IPC-Cmd | |
| elif command -v apk &> /dev/null; then | |
| apk add --no-cache openssl-dev perl | |
| fi | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.target }} | |
| path: dist/*.whl | |
| # --------------------------------------------------------------------------- | |
| # 4. Build sdist (source distribution) | |
| # --------------------------------------------------------------------------- | |
| build-sdist: | |
| needs: [check-version, test] | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: sdist | |
| args: --out dist | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist/*.tar.gz | |
| # --------------------------------------------------------------------------- | |
| # 5. Publish to PyPI | |
| # --------------------------------------------------------------------------- | |
| publish: | |
| needs: [check-version, build-wheels, build-sdist] | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| id-token: write # Required for trusted publishing (OIDC) | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: List artifacts | |
| run: ls -lh dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| # Uses trusted publishing (OIDC) — no API token needed | |
| # Configure at: https://pypi.org/manage/project/googer/settings/publishing/ | |
| # --------------------------------------------------------------------------- | |
| # 6. Create GitHub Release tag | |
| # --------------------------------------------------------------------------- | |
| release: | |
| needs: [check-version, publish] | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Create Git tag | |
| run: | | |
| VERSION="v${{ needs.check-version.outputs.new_version }}" | |
| git tag "$VERSION" | |
| git push origin "$VERSION" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.check-version.outputs.new_version }} | |
| name: v${{ needs.check-version.outputs.new_version }} | |
| body: | | |
| ## googer v${{ needs.check-version.outputs.new_version }} | |
| **Rust-powered release** — native compiled extensions for maximum performance. | |
| Published to [PyPI](https://pypi.org/project/googer/${{ needs.check-version.outputs.new_version }}/). | |
| ```bash | |
| pip install googer==${{ needs.check-version.outputs.new_version }} | |
| ``` | |
| ### Platforms | |
| - Linux (x86_64, aarch64) | |
| - macOS (Intel, Apple Silicon) | |
| - Windows (x86_64) | |
| files: dist/* | |
| generate_release_notes: true |