|
1 | | -name: Publish to PyPI |
| 1 | +name: Build and Publish to PyPI |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: [published] |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
6 | 7 | workflow_dispatch: |
7 | 8 | inputs: |
8 | 9 | publish_to: |
|
15 | 16 | - pypi |
16 | 17 |
|
17 | 18 | jobs: |
18 | | - publish: |
19 | | - name: Build and Publish Package |
| 19 | + build_wheels: |
| 20 | + name: Build wheels on ${{ matrix.os }} |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + os: [ubuntu-latest, windows-latest, macos-13, macos-14] |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Build wheels |
| 30 | + uses: pypa/cibuildwheel@v2.16.5 |
| 31 | + env: |
| 32 | + CIBW_BUILD: cp310-* cp311-* cp312-* |
| 33 | + CIBW_SKIP: "*-musllinux_*" |
| 34 | + CIBW_ARCHS_MACOS: x86_64 arm64 |
| 35 | + CIBW_ARCHS_LINUX: x86_64 aarch64 |
| 36 | + CIBW_ARCHS_WINDOWS: AMD64 |
| 37 | + |
| 38 | + - uses: actions/upload-artifact@v4 |
| 39 | + with: |
| 40 | + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} |
| 41 | + path: ./wheelhouse/*.whl |
| 42 | + |
| 43 | + build_sdist: |
| 44 | + name: Build source distribution |
20 | 45 | runs-on: ubuntu-latest |
21 | | - |
22 | 46 | steps: |
23 | | - - name: Checkout code |
24 | | - uses: actions/checkout@v4 |
25 | | - |
26 | | - - name: Set up Python |
27 | | - uses: actions/setup-python@v5 |
28 | | - with: |
29 | | - python-version: '3.10' |
30 | | - |
31 | | - - name: Install dependencies |
32 | | - run: | |
33 | | - python -m pip install --upgrade pip |
34 | | - pip install build twine setuptools wheel |
35 | | - |
36 | | - - name: Build package (source distribution only) |
37 | | - run: python -m build --sdist |
38 | | - |
39 | | - # Note: Binary wheels require proper manylinux/macosx tags |
40 | | - # Users will build locally from source distribution |
41 | | - |
42 | | - - name: Check package |
43 | | - run: twine check dist/* |
44 | | - |
45 | | - - name: List built files |
46 | | - run: | |
47 | | - echo "::group::Built packages" |
48 | | - ls -lh dist/ |
49 | | - echo "::endgroup::" |
50 | | - |
51 | | - - name: Publish to Test PyPI |
52 | | - if: github.event.inputs.publish_to == 'testpypi' || github.event_name != 'release' |
53 | | - env: |
54 | | - TWINE_USERNAME: __token__ |
55 | | - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} |
56 | | - run: | |
57 | | - twine upload --repository testpypi dist/* --verbose |
58 | | - |
59 | | - - name: Publish to PyPI |
60 | | - if: github.event.inputs.publish_to == 'pypi' || (github.event_name == 'release' && !github.event.release.prerelease) |
61 | | - env: |
62 | | - TWINE_USERNAME: __token__ |
63 | | - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
64 | | - run: | |
65 | | - twine upload dist/* --verbose |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Build sdist |
| 50 | + run: pipx run build --sdist |
| 51 | + |
| 52 | + - uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: cibw-sdist |
| 55 | + path: dist/*.tar.gz |
| 56 | + |
| 57 | + upload_pypi: |
| 58 | + needs: [build_wheels, build_sdist] |
| 59 | + runs-on: ubuntu-latest |
| 60 | + environment: |
| 61 | + name: pypi |
| 62 | + url: https://pypi.org/p/tree-sitter-toon |
| 63 | + permissions: |
| 64 | + id-token: write |
66 | 65 |
|
67 | | - - name: Upload build artifacts |
68 | | - uses: actions/upload-artifact@v4 |
69 | | - with: |
70 | | - name: dist-packages |
71 | | - path: dist/ |
72 | | - retention-days: 30 |
| 66 | + steps: |
| 67 | + - uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + pattern: cibw-* |
| 70 | + path: dist |
| 71 | + merge-multiple: true |
| 72 | + |
| 73 | + - name: List all files |
| 74 | + run: ls -lh dist/ |
| 75 | + |
| 76 | + - name: Publish to Test PyPI |
| 77 | + if: github.event.inputs.publish_to == 'testpypi' |
| 78 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 79 | + with: |
| 80 | + repository-url: https://test.pypi.org/legacy/ |
| 81 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 82 | + skip-existing: true |
| 83 | + |
| 84 | + - name: Publish to PyPI |
| 85 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish_to == 'pypi' |
| 86 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 87 | + with: |
| 88 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 89 | + skip-existing: true |
0 commit comments