|
| 1 | +--- |
1 | 2 | name: Build and Optionally Publish to PyPi
|
2 | 3 |
|
3 | 4 | on:
|
4 |
| - workflow_call: |
5 |
| - inputs: |
6 |
| - publish: |
7 |
| - type: boolean |
8 |
| - default: false |
9 |
| - description: "Publish to PyPi" |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + push: |
| 9 | + # Pattern matched against refs/tags |
| 10 | + tags: |
| 11 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
10 | 12 |
|
11 | 13 | jobs:
|
12 |
| - build_for_pypi: |
| 14 | + build_src_for_pypi: |
13 | 15 | runs-on: ubuntu-latest
|
14 |
| - permissions: |
15 |
| - id-token: write # This is required for requesting the JWT |
16 |
| - contents: read # This is required for actions/checkout |
17 | 16 | steps:
|
18 | 17 | - uses: actions/checkout@v4
|
19 | 18 | with:
|
| 19 | + persist-credentials: false |
20 | 20 | submodules: true
|
21 |
| - - name: Set up Python 3.11 |
22 |
| - uses: actions/setup-python@v4 |
23 |
| - with: |
24 |
| - python-version: "3.11" |
25 | 21 | - name: Install dependencies
|
26 | 22 | run: |
|
27 |
| - pip install -r requirements.txt |
28 |
| - python setup.py build |
29 |
| - python setup.py develop |
30 |
| - - name: Build distributions for different platforms |
| 23 | + pip install build |
| 24 | + - name: Build src dist |
31 | 25 | run: |
|
32 |
| - pip install wheel |
33 |
| - python setup.py sdist bdist_wheel --plat-name=manylinux2014_x86_64 |
34 |
| - python setup.py bdist_wheel --plat-name=macosx-12.6-universal2 |
35 |
| - python setup.py bdist_wheel --plat-name=win_amd64 |
36 |
| - - name: Move src file to match PEP625 |
| 26 | + python -m build --sdist |
| 27 | + env: |
| 28 | + PIP_CONSTRAINT: requirements.txt |
| 29 | + - name: Store the distribution packages |
| 30 | + uses: actions/upload-artifact@v4 |
| 31 | + with: |
| 32 | + name: cibw-sdist |
| 33 | + path: ./**/*.tar.gz |
| 34 | + |
| 35 | + build_dist_for_pypi: |
| 36 | + needs: |
| 37 | + - build_src_for_pypi |
| 38 | + runs-on: ${{ matrix.os }} |
| 39 | + strategy: |
| 40 | + matrix: |
| 41 | + os: |
| 42 | + - macos-13 |
| 43 | + - macos-latest |
| 44 | + - ubuntu-24.04-arm |
| 45 | + - ubuntu-latest |
| 46 | + - windows-latest |
| 47 | + steps: |
| 48 | + - name: Download the sdist |
| 49 | + uses: actions/download-artifact@v4 |
| 50 | + with: |
| 51 | + name: cibw-sdist |
| 52 | + - name: Get sdist filename |
| 53 | + id: get-sdist |
37 | 54 | run: |
|
38 |
| - cd dist |
39 |
| - ls | grep *.tar.gz | xargs -I x mv -- x "$(ls | grep *.tar.gz | sed 's/codecov-cli/codecov_cli/')" |
40 |
| - ls -al |
41 |
| - cd .. |
| 55 | + echo "sdist_filename=$(ls dist/)" >> "${GITHUB_OUTPUT}" |
| 56 | + shell: bash |
| 57 | + - name: Build wheels |
| 58 | + |
| 59 | + with: |
| 60 | + package-dir: dist/${{ steps.get-sdist.outputs.sdist_filename }} |
| 61 | + - name: Store the distribution packages |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: cibw-wheels-${{ matrix.os }} |
| 65 | + path: ./wheelhouse/*.whl |
| 66 | + |
| 67 | + |
| 68 | + publish_to_pypi: |
| 69 | + if: github.ref_type == 'tag' |
| 70 | + needs: |
| 71 | + - build_dist_for_pypi |
| 72 | + - build_src_for_pypi |
| 73 | + permissions: |
| 74 | + id-token: write # This is required for OIDC |
| 75 | + runs-on: ubuntu-latest |
| 76 | + environment: |
| 77 | + name: pypi |
| 78 | + url: https://pypi.org/p/codecov-cli |
| 79 | + steps: |
| 80 | + - name: Download artifacts |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + pattern: cibw-* |
42 | 84 | - name: Publish package to PyPi
|
43 |
| - if: inputs.publish == true |
44 | 85 | uses: pypa/gh-action-pypi-publish@release/v1
|
45 | 86 | with:
|
46 |
| - attestations: false |
47 | 87 | verbose: true
|
0 commit comments