|
| 1 | +name: Build wheels |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build_wheels: |
| 7 | + name: Build wheel on ${{ matrix.os }} |
| 8 | + runs-on: ${{ matrix.os }} |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + os: [macos-latest, ubuntu-latest, windows-latest] |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Cancel previous runs on the same branch |
| 16 | + if: ${{ github.ref != 'refs/heads/master' }} |
| 17 | + |
| 18 | + with: |
| 19 | + access_token: ${{ github.token }} |
| 20 | + |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v2 |
| 23 | + with: |
| 24 | + submodules: 'recursive' |
| 25 | + |
| 26 | + - uses: actions/setup-python@v2 |
| 27 | + name: Install Python |
| 28 | + with: |
| 29 | + python-version: '3.9' |
| 30 | + |
| 31 | + - name: Prepare python |
| 32 | + run: | |
| 33 | + python -m pip install --upgrade pip |
| 34 | +
|
| 35 | + - name: Set up QEMU |
| 36 | + if: startsWith(matrix.os, 'ubuntu') |
| 37 | + uses: docker/setup-qemu-action@v1 |
| 38 | + with: |
| 39 | + platforms: 'arm64' |
| 40 | + |
| 41 | + - name: Build source distribution with Ubuntu |
| 42 | + if: startsWith(matrix.os, 'ubuntu') |
| 43 | + run: | |
| 44 | + pip install build |
| 45 | + python -m build --sdist --outdir dist . |
| 46 | +
|
| 47 | + - name: Build ${{ matrix.os }} wheels and test |
| 48 | + |
| 49 | + with: |
| 50 | + output-dir: dist |
| 51 | + env: |
| 52 | + # build just supported python versions at December 2021 |
| 53 | + CIBW_BUILD: 'cp36-* cp37-* cp38-* cp39-* cp310-*' |
| 54 | + # Skip 32-bit builds |
| 55 | + CIBW_SKIP: '*-win32 *_i686' |
| 56 | + CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010 |
| 57 | + CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 |
| 58 | + CIBW_MUSLLINUX_X86_64_IMAGE: musllinux_1_1 |
| 59 | + # Only build on x86 and arm64 for linux |
| 60 | + CIBW_ARCHS_LINUX: auto aarch64 |
| 61 | + CIBW_BEFORE_ALL_LINUX: > |
| 62 | + python -m pip install --upgrade pip |
| 63 | + # CIBW_ARCHS_MACOS: x86_64 arm64 universal2 |
| 64 | + # Building two wheels for MacOS and skipping Universal |
| 65 | + CIBW_ARCHS_MACOS: x86_64 arm64 |
| 66 | + # Skip testing Apple Silicon until there are GH runners |
| 67 | + CIBW_TEST_SKIP: '*_arm64 *_universal2:arm64' |
| 68 | + CIBW_BEFORE_ALL_MACOS: > |
| 69 | + python -m pip install --upgrade pip |
| 70 | + CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.14 |
| 71 | + CIBW_BUILD_VERBOSITY_MACOS: 0 |
| 72 | + CIBW_BEFORE_ALL_WINDOWS: > |
| 73 | + python -m pip install --upgrade pip |
| 74 | + CIBW_TEST_COMMAND: > |
| 75 | + python -m unittest discover -v -s {package} |
| 76 | +
|
| 77 | + - name: Upload artifacts |
| 78 | + uses: actions/upload-artifact@v2 |
| 79 | + with: |
| 80 | + name: wheels |
| 81 | + path: ./dist |
| 82 | + |
| 83 | + - name: Test for secrets access |
| 84 | + id: check_secrets |
| 85 | + # If a third party makes a pull request |
| 86 | + # this allows automated steps below to be skipped |
| 87 | + # and leave a clean PR CI run |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + unset HAS_SECRET |
| 91 | + if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi |
| 92 | + echo ::set-output name=HAS_SECRET::${HAS_SECRET} |
| 93 | + env: |
| 94 | + SECRET: "${{ secrets.test_pypi_password }}" |
| 95 | + |
| 96 | + - name: Install twine |
| 97 | + run: pip install twine |
| 98 | + |
| 99 | + - name: Publish distribution to PyPI |
| 100 | + if: > |
| 101 | + startsWith(github.event.ref, 'refs/tags') && |
| 102 | + steps.check_secrets.outputs.HAS_SECRET |
| 103 | + env: |
| 104 | + # If the PR/Push has secret access |
| 105 | + # and PYPI_PASSWORD is in GH Secrets for this repo |
| 106 | + # and this is a tag, publish to PyPI |
| 107 | + TWINE_USERNAME: __token__ |
| 108 | + TWINE_NON_INTERACTIVE: 1 |
| 109 | + TWINE_PASSWORD: ${{ secrets.pypi_password }} |
| 110 | + run: twine upload --non-interactive --skip-existing --verbose 'dist/*' |
| 111 | + |
| 112 | + - name: Publish distribution to Test PyPI |
| 113 | + if: steps.check_secrets.outputs.HAS_SECRET |
| 114 | + env: |
| 115 | + # If the PR/Push has secret access |
| 116 | + # and TEST_PYPI_PASSWORD is in GH Secrets for this repo |
| 117 | + # then publish each build to test PyPI |
| 118 | + TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ |
| 119 | + TWINE_USERNAME: __token__ |
| 120 | + TWINE_NON_INTERACTIVE: 1 |
| 121 | + TWINE_PASSWORD: ${{ secrets.test_pypi_password }} |
| 122 | + run: twine upload --non-interactive --skip-existing --verbose 'dist/*' |
0 commit comments