|
1 | | -# This workflow will upload a Python package using Twine when a release is |
2 | | -# created. For more information see the following link: |
3 | | -# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries |
4 | | - |
5 | | -name: Publish to PyPI |
| 1 | +name: Build and Publish |
6 | 2 |
|
7 | 3 | on: |
8 | | - release: |
9 | | - types: [published] |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + publish: |
| 9 | + description: "Publish to PyPI (only for releases)" |
| 10 | + required: false |
| 11 | + default: false |
| 12 | + type: boolean |
| 13 | + |
| 14 | +# Cancel any in-progress build when a new commit is pushed |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 17 | + cancel-in-progress: true |
10 | 18 |
|
11 | 19 | jobs: |
12 | | - deploy: |
13 | | - runs-on: ubuntu-latest |
14 | | - |
15 | | - steps: |
16 | | - - uses: actions/checkout@v2 |
17 | | - |
18 | | - # Make sure tags are fetched, so we can get a version. |
19 | | - - run: | |
20 | | - git fetch --prune --unshallow --tags |
21 | | -
|
22 | | - - name: Set up Python |
23 | | - uses: actions/setup-python@v2 |
24 | | - with: |
25 | | - python-version: '3.x' |
26 | | - |
27 | | - - name: Install dependencies |
28 | | - run: | |
29 | | - python -m pip install --upgrade pip |
30 | | - python -m pip install --upgrade build twine |
31 | | -
|
32 | | - - name: Build and publish |
33 | | - env: |
34 | | - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} |
35 | | - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
36 | | - |
37 | | - run: | |
38 | | - python -m build |
39 | | - twine upload dist/* |
| 20 | + # Build the sdist and pure Python wheel |
| 21 | + sdist-and-wheel: |
| 22 | + name: Build sdist and pure wheel |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 # Needed for hatch-vcs versioning |
| 28 | + |
| 29 | + - name: Set up uv |
| 30 | + uses: astral-sh/setup-uv@v5 |
| 31 | + with: |
| 32 | + python-version: "3.12" |
| 33 | + |
| 34 | + - name: Build sdist and wheel |
| 35 | + run: uv build |
| 36 | + |
| 37 | + - name: Upload sdist |
| 38 | + uses: actions/upload-artifact@v4 |
| 39 | + with: |
| 40 | + name: sdist |
| 41 | + path: dist/*.tar.gz |
| 42 | + |
| 43 | + - name: Upload wheel |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: wheel-pure |
| 47 | + path: dist/*.whl |
| 48 | + |
| 49 | + # Generate the wheel build matrix dynamically |
| 50 | + generate-wheels-matrix: |
| 51 | + name: Generate wheels matrix |
| 52 | + runs-on: ubuntu-latest |
| 53 | + outputs: |
| 54 | + include: ${{ steps.set-matrix.outputs.include }} |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + - name: Set up uv |
| 58 | + uses: astral-sh/setup-uv@v5 |
| 59 | + - name: Install cibuildwheel and generate matrix |
| 60 | + run: | |
| 61 | + uvx cibuildwheel==2.22.0 --print-build-identifiers --platform linux \ |
| 62 | + | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' > /tmp/linux_builds.json |
| 63 | + uvx cibuildwheel==2.22.0 --print-build-identifiers --platform macos \ |
| 64 | + | jq -nRc '{"only": inputs, "os": "macos-14"}' > /tmp/macos_builds.json |
| 65 | + uvx cibuildwheel==2.22.0 --print-build-identifiers --platform windows \ |
| 66 | + | jq -nRc '{"only": inputs, "os": "windows-latest"}' > /tmp/windows_builds.json |
| 67 | + - name: Merge matrices |
| 68 | + id: set-matrix |
| 69 | + run: | |
| 70 | + jq -sc 'add' /tmp/*_builds.json > /tmp/matrix.json |
| 71 | + MATRIX=$(cat /tmp/matrix.json) |
| 72 | + echo "include=$MATRIX" >> "$GITHUB_OUTPUT" |
| 73 | +
|
| 74 | + # Build mypyc-compiled wheels using cibuildwheel |
| 75 | + mypyc-wheels: |
| 76 | + name: Build ${{ matrix.only }} |
| 77 | + needs: generate-wheels-matrix |
| 78 | + runs-on: ${{ matrix.os }} |
| 79 | + strategy: |
| 80 | + fail-fast: false |
| 81 | + matrix: |
| 82 | + include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }} |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v4 |
| 85 | + with: |
| 86 | + fetch-depth: 0 |
| 87 | + |
| 88 | + - name: Build wheels |
| 89 | + uses: pypa/cibuildwheel@v2.22.0 |
| 90 | + with: |
| 91 | + only: ${{ matrix.only }} |
| 92 | + env: |
| 93 | + CIBW_BUILD_VERBOSITY: 1 |
| 94 | + |
| 95 | + - name: Upload wheels |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: wheel-${{ matrix.only }} |
| 99 | + path: wheelhouse/*.whl |
| 100 | + |
| 101 | + # Publish to PyPI using trusted publishing |
| 102 | + publish: |
| 103 | + name: Publish to PyPI |
| 104 | + needs: [sdist-and-wheel, mypyc-wheels] |
| 105 | + runs-on: ubuntu-latest |
| 106 | + # Only publish on release events or manual trigger with publish=true |
| 107 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish) |
| 108 | + environment: |
| 109 | + name: pypi |
| 110 | + url: https://pypi.org/p/plum-dispatch |
| 111 | + permissions: |
| 112 | + id-token: write # Required for trusted publishing |
| 113 | + steps: |
| 114 | + - name: Download all artifacts |
| 115 | + uses: actions/download-artifact@v4 |
| 116 | + with: |
| 117 | + path: dist |
| 118 | + merge-multiple: true |
| 119 | + |
| 120 | + - name: List artifacts |
| 121 | + run: ls -la dist/ |
| 122 | + |
| 123 | + - name: Publish to PyPI |
| 124 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 125 | + with: |
| 126 | + packages-dir: dist/ |
0 commit comments