|
| 1 | +name: Build and test Python wheels and make PyPI release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - '.github/workflows/build-and-test-wheels.yml' |
| 8 | + - 'include/**' |
| 9 | + - 'scripts/**' |
| 10 | + - 'src/**' |
| 11 | + - 'CMakeLists.txt' |
| 12 | + - 'setup.py' |
| 13 | + - 'pyproject.toml' |
| 14 | + branches: [master] |
| 15 | + release: |
| 16 | + types: [published] |
| 17 | + |
| 18 | +jobs: |
| 19 | + build_wheels: |
| 20 | + name: Build wheels on ${{ matrix.os }} |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + os: [ubuntu-22.04, macos-12, macos-14] |
| 25 | + fail-fast: false |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + submodules: recursive |
| 31 | + |
| 32 | + - name: Report OS |
| 33 | + run: | |
| 34 | + echo ${{ matrix.os }} |
| 35 | + echo ${{ runner.os }} |
| 36 | + uname -p |
| 37 | +
|
| 38 | + - name: Set up QEMU |
| 39 | + if: runner.os == 'Linux' |
| 40 | + uses: docker/setup-qemu-action@v2 |
| 41 | + with: |
| 42 | + platforms: all |
| 43 | + |
| 44 | + - name: Build manylinux wheels |
| 45 | + if: matrix.os == 'ubuntu-22.04' |
| 46 | + |
| 47 | + env: |
| 48 | + # Configure cibuildwheel to build native archs, and some emulated ones |
| 49 | + CIBW_ARCHS_LINUX: x86_64 aarch64 |
| 50 | + CIBW_BUILD_VERBOSITY: 1 |
| 51 | + |
| 52 | + - name: Build macOS Intel wheels |
| 53 | + if: matrix.os == 'macos-12' |
| 54 | + |
| 55 | + env: |
| 56 | + CIBW_ARCHS_MACOS: x86_64 |
| 57 | + CIBW_ENVIRONMENT_MACOS: VIZDOOM_MACOS_ARCH=x86_64 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 MACOSX_DEPLOYMENT_TARGET=12.0 |
| 58 | + CIBW_BUILD_VERBOSITY: 1 |
| 59 | + |
| 60 | + - name: Build macOS Apple Silicon wheels |
| 61 | + if: matrix.os == 'macos-14' |
| 62 | + |
| 63 | + env: |
| 64 | + CIBW_ARCHS_MACOS: arm64 |
| 65 | + CIBW_ENVIRONMENT_MACOS: VIZDOOM_MACOS_ARCH=arm64 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 MACOSX_DEPLOYMENT_TARGET=14.0 |
| 66 | + CIBW_BUILD_VERBOSITY: 1 |
| 67 | + |
| 68 | + - name: Report built wheels |
| 69 | + run: | |
| 70 | + ls -l ./wheelhouse/*.whl |
| 71 | +
|
| 72 | + - name: Upload artifacts |
| 73 | + uses: actions/upload-artifact@v3 |
| 74 | + with: |
| 75 | + path: ./wheelhouse/*.whl |
| 76 | + |
| 77 | + test_wheels: |
| 78 | + name: Test wheels on ${{ matrix.os }} |
| 79 | + needs: [build_wheels] |
| 80 | + runs-on: ${{ matrix.os }} |
| 81 | + strategy: |
| 82 | + matrix: |
| 83 | + os: [ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14] |
| 84 | + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] |
| 85 | + fail-fast: false |
| 86 | + |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + submodules: recursive |
| 91 | + |
| 92 | + - name: Set up Python ${{ matrix.python-version }} environment |
| 93 | + uses: actions/setup-python@v4 |
| 94 | + with: |
| 95 | + python-version: ${{ matrix.python-version }} |
| 96 | + |
| 97 | + - name: Download all dists |
| 98 | + uses: actions/download-artifact@v3 |
| 99 | + with: |
| 100 | + # Unpacks default artifact into dist/ |
| 101 | + # If `name: artifact` is omitted, the action will create extra parent dir |
| 102 | + name: artifact |
| 103 | + path: dist |
| 104 | + |
| 105 | + - name: Report dist directory |
| 106 | + run: ls -l dist |
| 107 | + |
| 108 | + - name: Report environment |
| 109 | + run: | |
| 110 | + echo ${{ matrix.os }} |
| 111 | + echo ${{ runner.os }} |
| 112 | + uname -p |
| 113 | + python -c "import sys; print(sys.version)" |
| 114 | +
|
| 115 | + - name: Install macOS Intel wheel on ${{ matrix.os }} |
| 116 | + if: matrix.os == 'macos-12' || matrix.os == 'macos-13' |
| 117 | + run: | |
| 118 | + export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')") |
| 119 | + export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*macosx*x86_64.whl) |
| 120 | + python -m pip install ${WHEEL}[test] |
| 121 | +
|
| 122 | + - name: Install macOS Apple Silicon wheel on ${{ matrix.os }} |
| 123 | + if: matrix.os == 'macos-14' |
| 124 | + run: | |
| 125 | + export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')") |
| 126 | + export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*macosx*arm64.whl) |
| 127 | + python -m pip install ${WHEEL}[test] |
| 128 | +
|
| 129 | + - name: Install manylinux wheel on ${{ matrix.os }} |
| 130 | + if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-24.04' |
| 131 | + run: | |
| 132 | + export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')") |
| 133 | + export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*manylinux*x86_64.whl) |
| 134 | + python -m pip install ${WHEEL}[test] |
| 135 | +
|
| 136 | + - name: Import check |
| 137 | + run: python -c "import vizdoom" |
| 138 | + |
| 139 | + - name: Run tests |
| 140 | + # Skip tests on macOS with Apple Silicon, because they are slow (TODO: investigate) |
| 141 | + if: matrix.os != 'macos-14' |
| 142 | + run: pytest tests |
| 143 | + |
| 144 | + build_sdist: |
| 145 | + name: Build source distribution |
| 146 | + runs-on: ubuntu-latest |
| 147 | + steps: |
| 148 | + - uses: actions/checkout@v4 |
| 149 | + with: |
| 150 | + submodules: recursive |
| 151 | + |
| 152 | + - name: Build sdist |
| 153 | + run: pipx run build --sdist |
| 154 | + |
| 155 | + - name: Upload sdist |
| 156 | + uses: actions/upload-artifact@v3 |
| 157 | + with: |
| 158 | + path: dist/*.tar.gz |
| 159 | + |
| 160 | + upload_pypi: |
| 161 | + name: Upload to PyPI |
| 162 | + needs: [build_wheels, build_sdist, test_wheels] |
| 163 | + runs-on: ubuntu-latest |
| 164 | + environment: pypi |
| 165 | + permissions: |
| 166 | + id-token: write |
| 167 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 168 | + steps: |
| 169 | + - name: Download all dists |
| 170 | + uses: actions/download-artifact@v3 |
| 171 | + with: |
| 172 | + # Unpacks default artifact into dist/ |
| 173 | + # If `name: artifact` is omitted, the action will create extra parent dir |
| 174 | + name: artifact |
| 175 | + path: dist |
| 176 | + |
| 177 | + - name: Publish to PyPI |
| 178 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 179 | + with: |
| 180 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 181 | + # To test: |
| 182 | + # with: |
| 183 | + # repository_url: https://test.pypi.org/legacy/ |
0 commit comments