diff options
| author | Árni Dagur <arni@dagur.eu> | 2021-04-13 00:01:44 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-13 00:01:44 +0000 |
| commit | bf23b21e41c169c25d088a97d06d43b5595e02b1 (patch) | |
| tree | 702e6f45ce4ddcc4ed23b19175481008d671b4c4 /.github/workflows/ci.yml | |
| parent | ccb00e70cd098d6500f422702a8a2e96a233f835 (diff) | |
Improve GitHub actions workflow (#41)
* MacOS wheels should now support both x86_64 and ARM64.
* We now build ARM wheels for Linux.
* `abi3` is used to support multiple Python versions in a single wheel.
Diffstat (limited to '.github/workflows/ci.yml')
| -rw-r--r-- | .github/workflows/ci.yml | 334 |
1 files changed, 237 insertions, 97 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 806059d..dd8d8de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml | |||
| @@ -4,12 +4,7 @@ on: | |||
| 4 | release: | 4 | release: |
| 5 | types: [created] | 5 | types: [created] |
| 6 | push: | 6 | push: |
| 7 | branches: | ||
| 8 | - master | ||
| 9 | pull_request: | 7 | pull_request: |
| 10 | schedule: | ||
| 11 | # Runs every Thursday at 20:23 GMT to avoid bit rot | ||
| 12 | - cron: "20 23 * * 4" | ||
| 13 | 8 | ||
| 14 | jobs: | 9 | jobs: |
| 15 | lint: | 10 | lint: |
| @@ -37,137 +32,282 @@ jobs: | |||
| 37 | command: clippy | 32 | command: clippy |
| 38 | args: --all-targets --all-features | 33 | args: --all-targets --all-features |
| 39 | 34 | ||
| 40 | build: | 35 | macos: |
| 41 | runs-on: ${{ matrix.os }} | 36 | runs-on: macos-latest |
| 42 | needs: lint | 37 | needs: lint |
| 43 | strategy: | ||
| 44 | fail-fast: false | ||
| 45 | matrix: | ||
| 46 | rust-toolchain: [1.45, nightly] | ||
| 47 | python-version: [3.6, 3.7, 3.8, 3.9] | ||
| 48 | os: [ubuntu-latest, macos-latest, windows-latest] | ||
| 49 | architecture: [x86, x64] | ||
| 50 | exclude: | ||
| 51 | # Only build 32-bit for Windows | ||
| 52 | - os: macos-latest | ||
| 53 | architecture: x86 | ||
| 54 | - os: ubuntu-latest | ||
| 55 | architecture: x86 | ||
| 56 | # Only build on Rust 1.45 on Linux | ||
| 57 | - os: macos-latest | ||
| 58 | rust-toolchain: 1.45 | ||
| 59 | - os: windows-latest | ||
| 60 | rust-toolchain: 1.45 | ||
| 61 | |||
| 62 | steps: | 38 | steps: |
| 63 | - name: Checkout | 39 | - uses: actions/checkout@v2 |
| 64 | uses: actions/checkout@v1 | ||
| 65 | 40 | ||
| 66 | - uses: actions/setup-python@v2 | 41 | - uses: actions/setup-python@v2 |
| 67 | with: | 42 | with: |
| 68 | python-version: ${{ matrix.python-version }} | 43 | python-version: 3.6 |
| 69 | architecture: ${{ matrix.architecture }} | 44 | |
| 45 | - name: Install Rust toolchain | ||
| 46 | uses: actions-rs/toolchain@v1 | ||
| 47 | with: | ||
| 48 | toolchain: stable | ||
| 49 | target: aarch64-apple-darwin | ||
| 50 | profile: minimal | ||
| 51 | default: true | ||
| 52 | |||
| 53 | - name: Install maturin | ||
| 54 | run: pip install maturin | ||
| 55 | |||
| 56 | - name: Build wheels - x86_64 | ||
| 57 | run: | | ||
| 58 | maturin build -i python --target x86_64-apple-darwin --release --out dist | ||
| 59 | pip install adblock --no-index --find-links dist --force-reinstall | ||
| 60 | |||
| 61 | - name: Build wheels - universal2 | ||
| 62 | env: | ||
| 63 | DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer | ||
| 64 | MACOSX_DEPLOYMENT_TARGET: "10.9" | ||
| 65 | PYO3_CROSS_LIB_DIR: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib | ||
| 66 | run: | | ||
| 67 | # Build wheels | ||
| 68 | maturin build -i python --release --universal2 --out dist --no-sdist | ||
| 69 | pip install adblock --no-index --find-links dist --force-reinstall | ||
| 70 | 70 | ||
| 71 | - name: Install dependencies | 71 | - name: Run PyTest |
| 72 | run: | | 72 | run: | |
| 73 | python -m pip install --upgrade pip | 73 | pip install pytest toml |
| 74 | pip install poetry twine | 74 | pytest -vv --color=yes |
| 75 | poetry install | ||
| 76 | 75 | ||
| 77 | - name: Set Rust target environment variable | 76 | - name: Check wheels with Twine |
| 78 | run: bash ci/set-target.sh ${{ matrix.os }} ${{ matrix.architecture }} | 77 | run: pip install twine && twine check dist/* |
| 79 | shell: bash | 78 | shell: bash |
| 80 | 79 | ||
| 81 | - name: Install Rust | 80 | - name: Upload wheels |
| 81 | uses: actions/upload-artifact@v2 | ||
| 82 | with: | ||
| 83 | name: wheels | ||
| 84 | path: dist | ||
| 85 | |||
| 86 | windows: | ||
| 87 | runs-on: windows-latest | ||
| 88 | needs: lint | ||
| 89 | strategy: | ||
| 90 | matrix: | ||
| 91 | platform: | ||
| 92 | [ | ||
| 93 | { python-architecture: "x64", target: "x86_64-pc-windows-msvc" }, | ||
| 94 | { python-architecture: "x86", target: "i686-pc-windows-msvc" }, | ||
| 95 | ] | ||
| 96 | steps: | ||
| 97 | - uses: actions/checkout@v2 | ||
| 98 | |||
| 99 | - uses: actions/setup-python@v2 | ||
| 100 | with: | ||
| 101 | python-version: 3.6 | ||
| 102 | architecture: ${{ matrix.platform.python-architecture }} | ||
| 103 | |||
| 104 | - name: Install Rust toolchain | ||
| 82 | uses: actions-rs/toolchain@v1 | 105 | uses: actions-rs/toolchain@v1 |
| 83 | with: | 106 | with: |
| 84 | toolchain: ${{ matrix.rust-toolchain }} | 107 | toolchain: stable |
| 85 | target: ${{ env.ACTIONS_RUST_TARGET }} | 108 | target: ${{ matrix.platform.target }} |
| 86 | override: true | 109 | profile: minimal |
| 110 | default: true | ||
| 87 | 111 | ||
| 88 | - name: Build Python package | 112 | - name: Install maturin |
| 89 | run: poetry run maturin build --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }} | 113 | run: pip install maturin |
| 114 | |||
| 115 | - name: Build wheels | ||
| 116 | run: | | ||
| 117 | maturin build -i python --release --out dist --no-sdist --target ${{ matrix.platform.target }} | ||
| 118 | pip install adblock --no-index --find-links dist --force-reinstall | ||
| 119 | |||
| 120 | - name: Run PyTest | ||
| 121 | run: | | ||
| 122 | pip install pytest toml | ||
| 123 | pytest -vv --color=yes | ||
| 90 | 124 | ||
| 91 | - name: Check wheels with Twine | 125 | - name: Check wheels with Twine |
| 92 | run: twine check target/wheels/* | 126 | run: pip install twine && twine check dist/* |
| 93 | shell: bash | 127 | shell: bash |
| 94 | 128 | ||
| 95 | - name: Install Python package | 129 | - name: Upload wheels |
| 96 | run: poetry run pip install target/wheels/adblock*.whl | 130 | uses: actions/upload-artifact@v2 |
| 131 | with: | ||
| 132 | name: wheels | ||
| 133 | path: dist | ||
| 134 | |||
| 135 | linux: | ||
| 136 | runs-on: ubuntu-latest | ||
| 137 | needs: lint | ||
| 138 | strategy: | ||
| 139 | matrix: | ||
| 140 | platform: | ||
| 141 | [ | ||
| 142 | { | ||
| 143 | toolchain: "1.45", | ||
| 144 | manylinux: "2010", | ||
| 145 | target: "x86_64-unknown-linux-gnu", | ||
| 146 | arch: "x86_64", | ||
| 147 | }, | ||
| 148 | { | ||
| 149 | toolchain: "nightly", | ||
| 150 | manylinux: "2010", | ||
| 151 | target: "x86_64-unknown-linux-gnu", | ||
| 152 | arch: "x86_64", | ||
| 153 | }, | ||
| 154 | { | ||
| 155 | toolchain: "stable", | ||
| 156 | manylinux: "2010", | ||
| 157 | target: "x86_64-unknown-linux-gnu", | ||
| 158 | arch: "x86_64", | ||
| 159 | }, | ||
| 160 | # FIXME: GitHub actions runs out of memory when this build is | ||
| 161 | # attempted. | ||
| 162 | # { | ||
| 163 | # toolchain: "stable", | ||
| 164 | # manylinux: "2010", | ||
| 165 | # target: "i686-unknown-linux-gnu", | ||
| 166 | # arch: "i686" | ||
| 167 | # }, | ||
| 168 | ] | ||
| 169 | steps: | ||
| 170 | - uses: actions/checkout@v2 | ||
| 171 | |||
| 172 | - uses: actions/setup-python@v2 | ||
| 173 | with: | ||
| 174 | python-version: 3.6 | ||
| 175 | |||
| 176 | - name: Build Wheels | ||
| 177 | run: | | ||
| 178 | echo 'curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ matrix.platform.toolchain }} | ||
| 179 | source ~/.cargo/env | ||
| 180 | export PATH=/opt/python/cp38-cp38/bin:$PATH | ||
| 181 | pip install maturin | ||
| 182 | maturin build -i python --release --out dist --no-sdist --target ${{ matrix.platform.target }} --manylinux ${{ matrix.platform.manylinux }} | ||
| 183 | ' > build-wheel.sh | ||
| 184 | chmod +x build-wheel.sh | ||
| 185 | docker run --rm -v "$PWD":/io -w /io quay.io/pypa/manylinux${{ matrix.platform.manylinux }}_${{ matrix.platform.arch }} bash build-wheel.sh | ||
| 186 | |||
| 187 | - name: Run PyTest | ||
| 188 | run: | | ||
| 189 | pip install adblock --no-index --find-links dist --force-reinstall | ||
| 190 | pip install pytest toml | ||
| 191 | pytest -vv --color=yes | ||
| 192 | |||
| 193 | - name: Auditwheel Symbols | ||
| 194 | run: | | ||
| 195 | pip install auditwheel-symbols | ||
| 196 | auditwheel-symbols dist/*.whl | ||
| 197 | |||
| 198 | - name: Check wheels with Twine | ||
| 199 | run: pip install twine && twine check dist/* | ||
| 97 | shell: bash | 200 | shell: bash |
| 98 | 201 | ||
| 99 | - name: Run Python tests | 202 | - name: Upload wheels |
| 100 | run: poetry run pytest -vv --color=yes | 203 | if: matrix.platform.toolchain == 'stable' |
| 204 | uses: actions/upload-artifact@v2 | ||
| 205 | with: | ||
| 206 | name: wheels | ||
| 207 | path: dist | ||
| 101 | 208 | ||
| 102 | python-publish: | 209 | linux-cross: |
| 103 | needs: build | 210 | runs-on: ubuntu-latest |
| 104 | runs-on: ${{ matrix.os }} | 211 | needs: lint |
| 105 | strategy: | 212 | strategy: |
| 106 | fail-fast: false | ||
| 107 | matrix: | 213 | matrix: |
| 108 | python-version: [3.6, 3.7, 3.8, 3.9] | 214 | platform: |
| 109 | os: [ubuntu-latest, macos-latest, windows-latest] | 215 | [ |
| 110 | architecture: [x86, x64] | 216 | { |
| 111 | exclude: | 217 | manylinux: "2014", |
| 112 | # Only build 32-bit for Windows | 218 | target: "aarch64-unknown-linux-gnu", |
| 113 | - os: macos-latest | 219 | arch: "aarch64", |
| 114 | architecture: x86 | 220 | }, |
| 115 | - os: ubuntu-latest | 221 | { |
| 116 | architecture: x86 | 222 | manylinux: "2014", |
| 117 | 223 | target: "armv7-unknown-linux-gnueabihf", | |
| 224 | arch: "armv7", | ||
| 225 | }, | ||
| 226 | ] | ||
| 118 | steps: | 227 | steps: |
| 119 | - uses: actions/checkout@v1 | 228 | - uses: actions/checkout@v2 |
| 120 | 229 | ||
| 121 | - uses: actions/setup-python@v2 | 230 | - uses: actions/setup-python@v2 |
| 122 | with: | 231 | with: |
| 123 | python-version: ${{ matrix.python-version }} | 232 | python-version: 3.6 |
| 124 | architecture: ${{ matrix.architecture }} | ||
| 125 | 233 | ||
| 126 | - name: Set Rust target environment variable | 234 | - name: Build Wheels |
| 127 | run: bash ci/set-target.sh ${{ matrix.os }} ${{ matrix.architecture }} | 235 | run: | |
| 128 | shell: bash | 236 | echo 'curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable |
| 237 | source ~/.cargo/env | ||
| 238 | rustup target add ${{ matrix.platform.target }} | ||
| 239 | maturin build -i python --release --out dist --no-sdist --target ${{ matrix.platform.target }} --manylinux ${{ matrix.platform.manylinux }} | ||
| 240 | ' > build-wheel.sh | ||
| 241 | chmod +x build-wheel.sh | ||
| 242 | docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheel.sh | ||
| 129 | 243 | ||
| 130 | - name: Install latest nightly | 244 | - uses: uraimo/run-on-arch-action@v2.0.5 |
| 131 | uses: actions-rs/toolchain@v1 | 245 | name: Install built wheel |
| 132 | with: | 246 | with: |
| 133 | toolchain: nightly | 247 | arch: ${{ matrix.platform.arch }} |
| 134 | target: ${{ env.ACTIONS_RUST_TARGET }} | 248 | distro: ubuntu18.04 |
| 135 | override: true | 249 | # Mount the dist directory as /artifacts in the container |
| 250 | dockerRunArgs: | | ||
| 251 | --volume "${PWD}/dist:/artifacts" | ||
| 252 | install: | | ||
| 253 | apt-get update | ||
| 254 | apt-get install -y --no-install-recommends python3 python3-pip | ||
| 255 | pip3 install -U pip | ||
| 256 | run: | | ||
| 257 | ls -lrth /artifacts | ||
| 258 | pip3 install adblock --no-index --find-links /artifacts --force-reinstall | ||
| 259 | cd ~ && python3 -c "import adblock" | ||
| 136 | 260 | ||
| 137 | - name: Install dependencies | 261 | - name: Auditwheel Symbols |
| 138 | run: | | 262 | run: | |
| 139 | python -m pip install --upgrade pip | 263 | pip install auditwheel-symbols |
| 140 | pip install poetry twine | 264 | auditwheel-symbols dist/*.whl |
| 141 | poetry install | 265 | |
| 142 | - name: Build Python package | 266 | - name: Check wheels with Twine |
| 143 | run: poetry run maturin build --release --strip --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }} | 267 | run: pip install twine && twine check dist/* |
| 144 | |||
| 145 | - name: List wheels | ||
| 146 | if: matrix.os == 'windows-latest' | ||
| 147 | run: dir target\wheels\ | ||
| 148 | |||
| 149 | - name: List wheels | ||
| 150 | if: matrix.os != 'windows-latest' | ||
| 151 | run: find ./target/wheels/ | ||
| 152 | |||
| 153 | - name: Install wheels | ||
| 154 | run: pip install target/wheels/adblock*.whl | ||
| 155 | shell: bash | 268 | shell: bash |
| 156 | 269 | ||
| 157 | - name: Release | 270 | - name: Upload wheels |
| 158 | uses: softprops/action-gh-release@v1 | 271 | uses: actions/upload-artifact@v2 |
| 159 | if: startsWith(github.ref, 'refs/tags/') | ||
| 160 | with: | 272 | with: |
| 161 | files: target/wheels/adblock*.whl | 273 | name: wheels |
| 162 | env: | 274 | path: dist |
| 163 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 275 | |
| 276 | python-publish: | ||
| 277 | runs-on: ubuntu-latest | ||
| 278 | needs: [ macos, windows, linux, linux-cross ] | ||
| 279 | steps: | ||
| 280 | - uses: actions/download-artifact@v2 | ||
| 281 | with: | ||
| 282 | name: wheels | ||
| 283 | |||
| 284 | - uses: actions/setup-python@v2 | ||
| 285 | with: | ||
| 286 | python-version: 3.9 | ||
| 287 | |||
| 288 | - name: Wheel filename sanity checks | ||
| 289 | run: | | ||
| 290 | num_abi3_whl=$(find | grep "\./adblock.*-abi3.*\.whl" | wc -l) | ||
| 291 | num_whl=$(find | grep "\./adblock.*\.whl" | wc -l) | ||
| 292 | test $num_abi3_whl -eq $num_whl | ||
| 293 | test $num_whl -ge 1 | ||
| 294 | find | grep "\./adblock-.*\.tar\.gz" | ||
| 164 | 295 | ||
| 165 | - name: PyPi publish | 296 | - name: PyPi publish |
| 166 | if: github.event_name == 'release' && github.event.action == 'created' | 297 | if: github.event_name == 'release' && github.event.action == 'created' |
| 167 | env: | 298 | env: |
| 168 | TWINE_PASSWORD: ${{ secrets.PYPI }} | 299 | TWINE_PASSWORD: ${{ secrets.PYPI }} |
| 169 | run: twine upload --non-interactive --skip-existing --username __token__ target/wheels/* | 300 | run: | |
| 170 | shell: bash | 301 | pip install --upgrade wheel pip setuptools twine |
| 302 | twine upload --non-interactive --skip-existing --username __token__ ./* | ||
| 303 | |||
| 304 | - name: GitHub release | ||
| 305 | uses: softprops/action-gh-release@v1 | ||
| 306 | if: startsWith(github.ref, 'refs/tags/') | ||
| 307 | with: | ||
| 308 | files: ./* | ||
| 309 | env: | ||
| 310 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| 171 | 311 | ||
| 172 | docs-publish: | 312 | docs-publish: |
| 173 | runs-on: ubuntu-latest | 313 | runs-on: ubuntu-latest |
