update workflows #78
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
| # This workflows will upload a Python Package using Twine when a release is created | ||
|
Check failure on line 1 in .github/workflows/python-publish.yml
|
||
| # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
| name: Upload Python Package | ||
| on: | ||
| release: | ||
| types: [ created ] | ||
| jobs: | ||
| setup: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| python-version: ${{ steps.set-python-version.outputs.version }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Setup python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.13" | ||
| - name: Extract min required python version | ||
| id: set-python-version | ||
| run: | | ||
| # Use tomllib for robust parsing (Python 3.11+) | ||
| VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['requires-python'].replace('>=', '').strip())") | ||
| echo "Extracted version: $VERSION" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| update_version: | ||
| needs: setup | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| - name: Set Release version | ||
| run: uv version ${{ github.event.release.tag_name }} | ||
| - name: Commit and push changes | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add pyproject.toml | ||
| git commit -m "chore: bump version to ${{ github.event.release.tag_name }}" | ||
| git push | ||
| build_sdist: | ||
| needs: [ setup, update_version ] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| - name: Build sdist | ||
| run: uv build --sdist | ||
| - name: Upload sdist | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: sdist | ||
| path: dist/*.tar.gz | ||
| build_wheels: | ||
| needs: [ setup, update_version ] | ||
| name: Build wheels on ${{ matrix.os }} for Python ${{ matrix.python-version }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ ubuntu-latest, macos-latest, windows-latest ] | ||
| python-version: [ "${{ needs.setup.outputs.python-version }}" ] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| - name: Build wheels via cibuildwheel | ||
| uses: pypa/cibuildwheel@v2.22.0 | ||
| env: | ||
| CIBW_BUILD_FRONTEND: "uv" | ||
| # Only build for the specific Python version extracted earlier | ||
| CIBW_BUILD: "cp${{ matrix.python-version | replace('.', '') }}-*" | ||
| CIBW_BEFORE_BUILD: "uv pip install mypy[mypyc] librt" | ||
| - name: Upload wheels | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: wheels-${{ matrix.os }}-${{ matrix.python-version }} | ||
| path: ./wheelhouse/*.whl | ||
| publish: | ||
| name: Publish to PyPI | ||
| needs: [ build_wheels, build_sdist ] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| steps: | ||
| - name: Download sdist and wheels | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: dist | ||
| merge-multiple: true | ||
| - name: Publish package distributions to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| user: ${{ secrets.PYPI_USERNAME }} | ||
| password: ${{ secrets.PYPI_PASSWORD }} | ||