|
| 1 | +# Workflow to build and test wheels |
| 2 | +# ================================= |
| 3 | +# This github action gets triggered whenever there |
| 4 | +# is a push to the master branch or a release is created. |
| 5 | +# It generates both wheels and distributions files, |
| 6 | +# making sure their contents are correct via unit-testing. |
| 7 | +# |
| 8 | +# However, only in the case of a github release, the assets |
| 9 | +# are uploaded and attached to a release. In other words, we |
| 10 | +# expect the following workflow: |
| 11 | +# 1- users adds new features to the master branch via PRs. Every |
| 12 | +# time a new feature gets merged to the master branch, this github |
| 13 | +# action gets triggered, and wheels/distribution files are generated |
| 14 | +# to make sure this new change did not break the distribution files. |
| 15 | +# 2- Whenever there is enough PRs in the master branch, we expect the user |
| 16 | +# to create a release following github guidelines from here: |
| 17 | +# https://docs.github.com/en/github/administering-a-repository/releasing-projects-on-github/managing-releases-in-a-repository |
| 18 | +# During a github release, you create a tagged-version (something like v2.3.4.), |
| 19 | +# add a title to the release and a description. Then you publish the release via the |
| 20 | +# publish-button. This effectively creates a github release, triggering this action. |
| 21 | +# When this triggered action finished, the release files are automatically uploaded |
| 22 | +# to your github release page. Check for example: |
| 23 | +# https://github.com/automl/ConfigSpace/releases |
| 24 | +# |
| 25 | +# Please note that creating a git tag and pushing it (git tag <>; git push --tags) is not |
| 26 | +# sufficient to append the wheels and distribution files to your release. |
| 27 | +# You need to generate a new release using github, not git. |
| 28 | +# |
| 29 | +# Guides |
| 30 | +# ------ |
| 31 | +# Ref: |
| 32 | +# * https://github.com/scikit-hep/iminuit/blob/develop/.github/workflows/wheels.yml |
| 33 | +# cibuildwheel docs: |
| 34 | +# * https://cibuildwheel.readthedocs.io/en/stable/options/ |
| 35 | + |
| 36 | +name: Wheel builder |
| 37 | + |
| 38 | +on: |
| 39 | + workflow_dispatch: |
| 40 | + |
| 41 | + push: |
| 42 | + branches: |
| 43 | + - master |
| 44 | + # Release branches |
| 45 | + - "[0-9]+.[0-9]+.X" |
| 46 | + |
| 47 | + create: |
| 48 | + tags: |
| 49 | + - v* |
| 50 | + |
| 51 | +env: |
| 52 | + package-name: ConfigSpace |
| 53 | + |
| 54 | + test-dir: test |
| 55 | + test-reqs: "pytest" |
| 56 | + test-cmd: "pytest -v" |
| 57 | + extra-requires: "[test]" |
| 58 | + |
| 59 | +jobs: |
| 60 | + |
| 61 | + build_linux_wheels: |
| 62 | + name: ${{ matrix.py }}-linux-${{ matrix.system }}-${{ matrix.arch }} |
| 63 | + runs-on: ubuntu-latest |
| 64 | + |
| 65 | + strategy: |
| 66 | + fail-fast: false |
| 67 | + matrix: |
| 68 | + py: [cp37, cp38, cp39, cp310] |
| 69 | + arch: ["x86_64", "i686", "aarch64"] |
| 70 | + system: ["manylinux", "musllinux"] |
| 71 | + |
| 72 | + exclude: |
| 73 | + |
| 74 | + # Not supported by numpy |
| 75 | + - system: "musllinux" |
| 76 | + |
| 77 | + # Scipy doesn't have a wheel for cp310 i686 |
| 78 | + - py: cp310 |
| 79 | + arch: "i686" |
| 80 | + |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Checkout ${{ env.package-name }} |
| 84 | + uses: actions/checkout@v2 |
| 85 | + |
| 86 | + # This allows us to build for 'aarch64' on linux |
| 87 | + - if: ${{ matrix.arch == 'aarch64' }} |
| 88 | + uses: docker/setup-qemu-action@v1 |
| 89 | + |
| 90 | + - name: Build wheels with cibuildwheel to wheelhouse/*.whl |
| 91 | + uses: pypa/cibuildwheel@v2.3.1 |
| 92 | + env: |
| 93 | + CIBW_BUILD: ${{ matrix.py }}-${{ matrix.system }}_* |
| 94 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 95 | + CIBW_TEST_REQUIRES: ${{ env.test-reqs }} |
| 96 | + CIBW_TEST_COMMAND: ${{ env.test-cmd }} {project}/${{ env.test-dir }} |
| 97 | + |
| 98 | + - name: Upload artifacts |
| 99 | + uses: actions/upload-artifact@v2 |
| 100 | + with: |
| 101 | + path: wheelhouse/*.whl |
| 102 | + |
| 103 | + build_macos_wheels: |
| 104 | + name: ${{ matrix.py }}-macos-${{ matrix.arch }} |
| 105 | + runs-on: macos-latest |
| 106 | + strategy: |
| 107 | + fail-fast: false |
| 108 | + matrix: |
| 109 | + py: [cp37, cp38, cp39, cp310] |
| 110 | + arch: ["x86_64", "universal2", "arm64"] |
| 111 | + exclude: |
| 112 | + |
| 113 | + # cp37 doesn't allow a univeral2 build |
| 114 | + - py: cp37 |
| 115 | + arch: "universal2" |
| 116 | + |
| 117 | + # arm64 isn't supported on macos github workers |
| 118 | + - arch: "arm64" |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: Checkout ${{ env.package-name }} |
| 122 | + uses: actions/checkout@v2 |
| 123 | + |
| 124 | + - name: Build wheels with cibuildwheel to wheelhouse/*.whl |
| 125 | + uses: pypa/cibuildwheel@v2.3.1 |
| 126 | + env: |
| 127 | + CIBW_BUILD: ${{ matrix.py }}-* |
| 128 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 129 | + CIBW_TEST_REQUIRES: ${{ env.test-reqs }} |
| 130 | + CIBW_TEST_COMMAND: ${{ env.test-cmd }} {project}/${{ env.test-dir }} |
| 131 | + |
| 132 | + - name: Upload artifacts |
| 133 | + uses: actions/upload-artifact@v2 |
| 134 | + with: |
| 135 | + path: wheelhouse/*.whl |
| 136 | + |
| 137 | + build_windows_wheels: |
| 138 | + name: ${{ matrix.py }}-windows-${{ matrix.arch }} |
| 139 | + runs-on: windows-latest |
| 140 | + strategy: |
| 141 | + fail-fast: false |
| 142 | + matrix: |
| 143 | + py: [cp37, cp38, cp39, cp310] |
| 144 | + arch: ["AMD64", "x86"] |
| 145 | + exclude: |
| 146 | + |
| 147 | + # We can't build win32 (x86) with cp310 because numpy doesn't have a win32 wheel |
| 148 | + - py: cp310 |
| 149 | + arch: "x86" |
| 150 | + |
| 151 | + |
| 152 | + steps: |
| 153 | + - name: Checkout ${{ env.package-name }} |
| 154 | + uses: actions/checkout@v2 |
| 155 | + |
| 156 | + - name: Build wheels with cibuildwheel to wheelhouse/*.whl |
| 157 | + uses: pypa/cibuildwheel@v2.3.1 |
| 158 | + env: |
| 159 | + CIBW_BUILD: ${{ matrix.py }}-* |
| 160 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 161 | + CIBW_TEST_REQUIRES: ${{ env.test-reqs }} |
| 162 | + CIBW_TEST_COMMAND: ${{ env.test-reqs }} {project}/${{ env.test-dir }} |
| 163 | + |
| 164 | + - name: Upload artifacts |
| 165 | + uses: actions/upload-artifact@v2 |
| 166 | + with: |
| 167 | + path: wheelhouse/*.whl |
| 168 | + |
| 169 | + build_sdist: |
| 170 | + name: sdist-${{ matrix.py }} |
| 171 | + runs-on: ubuntu-latest |
| 172 | + strategy: |
| 173 | + fail-fast: false |
| 174 | + matrix: |
| 175 | + py: ["3.7", "3.8", "3.9", "3.10"] |
| 176 | + |
| 177 | + steps: |
| 178 | + - name: Checkout ${{ env.package-name }} |
| 179 | + uses: actions/checkout@v2 |
| 180 | + |
| 181 | + - name: Setup Python |
| 182 | + uses: actions/setup-python@v2 |
| 183 | + with: |
| 184 | + python-version: ${{ matrix.py }} |
| 185 | + |
| 186 | + - name: Build source distribution |
| 187 | + run: | |
| 188 | + python -m pip install --upgrade pip |
| 189 | + python setup.py sdist |
| 190 | + echo "sdist_name=$(ls -t dist/${{ env.package-name }}-*.tar.gz | head -n 1)" >> $GITHUB_ENV |
| 191 | +
|
| 192 | + - name: Twine check ${{ env.package-name }} |
| 193 | + run: | |
| 194 | + python -m pip install twine |
| 195 | + twine_output=`twine check ${{ env.sdist_name }}` |
| 196 | + if [[ "$twine_output" != "Checking ${{ env.sdist_name }}: PASSED" ]]; then |
| 197 | + echo $twine_output && exit 1; |
| 198 | + fi |
| 199 | +
|
| 200 | + - name: Install dist |
| 201 | + run: | |
| 202 | + python -m pip install ${{ env.sdist_name }}${{ env.extra-requires }} |
| 203 | +
|
| 204 | + - name: PEP 561 Compliance |
| 205 | + run: | |
| 206 | + pip install mypy |
| 207 | + cd .. # required to use the installed version |
| 208 | + if ! python -c "import ${{ env.package-name }}"; then exit 1; fi |
| 209 | +
|
| 210 | + - name: Tests |
| 211 | + timeout-minutes: 45 |
| 212 | + run: | |
| 213 | + ${{ env.test-cmd }} ${{env.test-dir}} |
| 214 | +
|
| 215 | +
|
| 216 | + - name: Store artifacts |
| 217 | + uses: actions/upload-artifact@v2 |
| 218 | + with: |
| 219 | + path: dist/*.tar.gz |
| 220 | + |
| 221 | + |
| 222 | + # Upload the wheels |
| 223 | + release_assets: |
| 224 | + name: Upload Release |
| 225 | + runs-on: ubuntu-latest |
| 226 | + needs: [build_linux_wheels, build_macos_wheels, build_windows_wheels, build_sdist] |
| 227 | + |
| 228 | + # Only on a tagged release, push |
| 229 | + if: startsWith(github.ref, 'refs/tags/v') && github.event_name != 'pull_request' |
| 230 | + |
| 231 | + steps: |
| 232 | + - name: Checkout ${{ env.package-name }} |
| 233 | + uses: actions/checkout@v2 |
| 234 | + |
| 235 | + - name: Download artifacts |
| 236 | + uses: actions/download-artifact@v2 |
| 237 | + with: |
| 238 | + path: dist |
| 239 | + |
| 240 | + - name: Setup Python |
| 241 | + uses: actions/setup-python@v2 |
| 242 | + |
| 243 | + - name: Install dependencies |
| 244 | + run: | |
| 245 | + python -m pip install --upgrade pip |
| 246 | + python -m pip install setuptools wheel twine |
| 247 | +
|
| 248 | + - name: Upload Release Asset |
| 249 | + id: upload-release-asset |
| 250 | + env: |
| 251 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 252 | + run: | |
| 253 | + tag_name="${GITHUB_REF##*/}" |
| 254 | + echo Uploading `(find ./dist -type f -printf "-a %p ")` |
| 255 | + hub release edit $(find ./dist -type f -printf "-a %p ") -m "" "$tag_name" |
0 commit comments