|
| 1 | +name: Build wheels and publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + configure: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: Read Python versions from pyproject.toml |
| 17 | + id: read-versions |
| 18 | + # produces output like: python_versions=39,310,311,312,313 |
| 19 | + run: >- |
| 20 | + echo "python_versions=$( |
| 21 | + grep -oP '(?<=Language :: Python :: )\d.\d+' pyproject.toml |
| 22 | + | sed 's/\.//' |
| 23 | + | tr '\n' ',' |
| 24 | + | sed 's/,$//' |
| 25 | + )" >> $GITHUB_OUTPUT |
| 26 | + outputs: |
| 27 | + python_versions: ${{ steps.read-versions.outputs.python_versions }} |
| 28 | + |
| 29 | + build_sdist: |
| 30 | + name: Build source distribution |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + - name: Check version |
| 35 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 36 | + run: python version.py check "${{ github.ref }}" |
| 37 | + - name: Add untagged version suffix |
| 38 | + if: ${{ ! startsWith(github.ref, 'refs/tags/v') }} |
| 39 | + run: python version.py update |
| 40 | + - name: Build sdist |
| 41 | + run: pipx run build --sdist |
| 42 | + - uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: sdist |
| 45 | + path: dist |
| 46 | + |
| 47 | + choose_linux_wheel_types: |
| 48 | + name: Decide which wheel types to build |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - id: manylinux_x86_64 |
| 52 | + run: echo "wheel_types=manylinux_x86_64" >> $GITHUB_OUTPUT |
| 53 | + - id: musllinux_x86_64 |
| 54 | + run: echo "wheel_types=musllinux_x86_64" >> $GITHUB_OUTPUT |
| 55 | + outputs: |
| 56 | + wheel_types: ${{ toJSON(steps.*.outputs.wheel_types) }} |
| 57 | + |
| 58 | + build_linux_wheels: |
| 59 | + needs: [configure, choose_linux_wheel_types, build_sdist] |
| 60 | + name: ${{ matrix.wheel_type }} wheels |
| 61 | + runs-on: ubuntu-latest |
| 62 | + strategy: |
| 63 | + matrix: |
| 64 | + wheel_type: ${{ fromJSON(needs.choose_linux_wheel_types.outputs.wheel_types) }} |
| 65 | + steps: |
| 66 | + - uses: actions/download-artifact@v4 |
| 67 | + with: |
| 68 | + name: sdist |
| 69 | + path: dist |
| 70 | + - name: Extract sdist |
| 71 | + run: | |
| 72 | + tar zxvf dist/*.tar.gz --strip-components=1 |
| 73 | + - uses: docker/setup-qemu-action@v3 |
| 74 | + if: runner.os == 'Linux' |
| 75 | + name: Set up QEMU |
| 76 | + - name: Build wheels |
| 77 | + uses: pypa/cibuildwheel@v2.22.0 |
| 78 | + env: |
| 79 | + CIBW_BUILD: cp{${{ needs.configure.outputs.python_versions }}}-${{ matrix.wheel_type }} |
| 80 | + CIBW_ARCHS_LINUX: auto |
| 81 | + CIBW_BEFORE_BUILD: cd {project}; pip install -e . # is there a better way to build the .so files? |
| 82 | + CIBW_TEST_COMMAND: cd {project}; python -m unittest |
| 83 | + - uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: ${{ matrix.wheel_type }}-wheels |
| 86 | + path: ./wheelhouse/*.whl |
| 87 | + |
| 88 | + pypi-publish: |
| 89 | + name: Upload release to PyPI |
| 90 | + needs: [build_sdist, build_linux_wheels] |
| 91 | + runs-on: ubuntu-latest |
| 92 | + #if: startsWith(github.ref, 'refs/tags/v') # removed until pypi-test-publish is working |
| 93 | + environment: |
| 94 | + name: pypi |
| 95 | + url: https://pypi.org/p/jsonobject |
| 96 | + permissions: |
| 97 | + id-token: write |
| 98 | + steps: |
| 99 | + - name: Download all the dists |
| 100 | + uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + # with no name set, it downloads all of the artifacts |
| 103 | + path: dist/ |
| 104 | + - run: | |
| 105 | + mv dist/sdist/*.tar.gz dist/ |
| 106 | + mv dist/*-wheels/*.whl dist/ |
| 107 | + rmdir dist/{sdist,*-wheels} |
| 108 | + ls -R dist |
| 109 | + - name: Publish package distributions to PyPI |
| 110 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 111 | + |
| 112 | + # https://github.com/finpassbr/json-object/issues/1 |
| 113 | + #pypi-test-publish: |
| 114 | + # name: Upload release to test PyPI |
| 115 | + # needs: [build_sdist, build_linux_wheels] |
| 116 | + # runs-on: ubuntu-latest |
| 117 | + # environment: |
| 118 | + # name: testpypi |
| 119 | + # url: https://test.pypi.org/p/jsonobject |
| 120 | + # permissions: |
| 121 | + # id-token: write |
| 122 | + # steps: |
| 123 | + # - name: Download all the dists |
| 124 | + # uses: actions/download-artifact@v4 |
| 125 | + # with: |
| 126 | + # # with no name set, it downloads all of the artifacts |
| 127 | + # path: dist/ |
| 128 | + # - run: | |
| 129 | + # mv dist/sdist/*.tar.gz dist/ |
| 130 | + # mv dist/*-wheels/*.whl dist/ |
| 131 | + # rmdir dist/{sdist,*-wheels} |
| 132 | + # ls -R dist |
| 133 | + # - name: Publish package distributions to PyPI |
| 134 | + # uses: pypa/gh-action-pypi-publish@release/v1 |
| 135 | + # with: |
| 136 | + # repository-url: https://test.pypi.org/legacy/ |
0 commit comments