|
| 1 | +# some code from https://github.com/pydantic/pydantic-core/blob/d6e7890b36ef21cb28180a7f5b1479da2319012d/.github/workflows/ci.yml |
| 2 | +# MIT License, see author list by link |
| 3 | + |
| 4 | +name: CI |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + tags: |
| 11 | + - "**" |
| 12 | + pull_request: {} |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + name: test ${{ matrix.python-version }} rust stable |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + python-version: |
| 21 | + - "3.7" |
| 22 | + - "3.8" |
| 23 | + - "3.9" |
| 24 | + - "3.10" |
| 25 | + - "3.11" |
| 26 | + - "pypy3.7" |
| 27 | + - "pypy3.8" |
| 28 | + - "pypy3.9" |
| 29 | + |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + env: |
| 33 | + PYTHON: ${{ matrix.python-version }} |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: install rust stable |
| 39 | + uses: dtolnay/rust-toolchain@master |
| 40 | + with: |
| 41 | + toolchain: stable |
| 42 | + |
| 43 | + - id: cache-rust |
| 44 | + name: cache rust |
| 45 | + uses: Swatinem/rust-cache@v2 |
| 46 | + with: |
| 47 | + key: v3 |
| 48 | + |
| 49 | + - name: set up python |
| 50 | + uses: actions/setup-python@v4 |
| 51 | + with: |
| 52 | + python-version: ${{ matrix.python-version }} |
| 53 | + |
| 54 | + - id: cache-py |
| 55 | + name: cache python |
| 56 | + uses: actions/cache@v2 |
| 57 | + with: |
| 58 | + path: ${{ env.pythonLocation }} |
| 59 | + key: > |
| 60 | + py |
| 61 | + ${{ runner.os }} |
| 62 | + ${{ env.pythonLocation }} |
| 63 | + - run: pip install pytest |
| 64 | + if: steps.cache-py.outputs.cache-hit != 'true' |
| 65 | + |
| 66 | + - run: pip install -e . |
| 67 | + env: |
| 68 | + RUST_BACKTRACE: 1 |
| 69 | + |
| 70 | + - run: pip freeze |
| 71 | + |
| 72 | + - run: pytest |
| 73 | + |
| 74 | + lint: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v3 |
| 79 | + |
| 80 | + - name: install rust stable |
| 81 | + uses: dtolnay/rust-toolchain@stable |
| 82 | + with: |
| 83 | + components: rustfmt, clippy |
| 84 | + |
| 85 | + - name: cache rust |
| 86 | + uses: Swatinem/rust-cache@v2 |
| 87 | + |
| 88 | + - uses: actions/setup-python@v4 |
| 89 | + with: |
| 90 | + python-version: "3.10" |
| 91 | + |
| 92 | + - uses: actions/cache@v2 |
| 93 | + id: cache-py |
| 94 | + name: cache python |
| 95 | + with: |
| 96 | + path: ${{ env.pythonLocation }} |
| 97 | + key: > |
| 98 | + py |
| 99 | + ${{ env.pythonLocation }} |
| 100 | + - run: pip install black flake8 isort |
| 101 | + if: steps.cache-py.outputs.cache-hit != 'true' |
| 102 | + |
| 103 | + - run: pip install . |
| 104 | + if: steps.cache-py.outputs.cache-hit != 'true' |
| 105 | + |
| 106 | + - run: pip freeze |
| 107 | + |
| 108 | + - run: black --check . |
| 109 | + - run: flake8 |
| 110 | + - run: isort --check . |
| 111 | + |
| 112 | + # https://github.com/marketplace/actions/alls-green#why used for branch protection checks |
| 113 | + check: |
| 114 | + if: always() |
| 115 | + needs: [test, lint] |
| 116 | + runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - name: Decide whether the needed jobs succeeded or failed |
| 119 | + uses: re-actors/alls-green@release/v1 |
| 120 | + with: |
| 121 | + jobs: ${{ toJSON(needs) }} |
| 122 | + |
| 123 | + build: |
| 124 | + name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }}) |
| 125 | + if: success() |
| 126 | + strategy: |
| 127 | + fail-fast: false |
| 128 | + matrix: |
| 129 | + os: [ubuntu, macos, windows] |
| 130 | + target: [x86_64, aarch64] |
| 131 | + manylinux: [auto] |
| 132 | + include: |
| 133 | + - os: ubuntu |
| 134 | + platform: linux |
| 135 | + - os: windows |
| 136 | + ls: dir |
| 137 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 138 | + - os: windows |
| 139 | + ls: dir |
| 140 | + target: i686 |
| 141 | + python-architecture: x86 |
| 142 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 143 | + - os: macos |
| 144 | + target: aarch64 |
| 145 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 146 | + - os: ubuntu |
| 147 | + platform: linux |
| 148 | + target: i686 |
| 149 | + # GCC 4.8.5 in manylinux2014 container doesn't support c11 atomic |
| 150 | + # we use manylinux_2_24 container for aarch64 and armv7 targets instead, |
| 151 | + - os: ubuntu |
| 152 | + platform: linux |
| 153 | + target: aarch64 |
| 154 | + container: messense/manylinux_2_24-cross:aarch64 |
| 155 | + - os: ubuntu |
| 156 | + platform: linux |
| 157 | + target: armv7 |
| 158 | + container: messense/manylinux_2_24-cross:armv7 |
| 159 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 160 | + # musllinux |
| 161 | + - os: ubuntu |
| 162 | + platform: linux |
| 163 | + target: x86_64 |
| 164 | + manylinux: musllinux_1_1 |
| 165 | + - os: ubuntu |
| 166 | + platform: linux |
| 167 | + target: aarch64 |
| 168 | + manylinux: musllinux_1_1 |
| 169 | + - os: ubuntu |
| 170 | + platform: linux |
| 171 | + target: ppc64le |
| 172 | + container: messense/manylinux_2_24-cross:ppc64le |
| 173 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 174 | + - os: ubuntu |
| 175 | + platform: linux |
| 176 | + target: s390x |
| 177 | + container: messense/manylinux_2_24-cross:s390x |
| 178 | + interpreter: 3.7 3.8 3.9 3.10 3.11 |
| 179 | + exclude: |
| 180 | + # Windows on arm64 only supports Python 3.11+ |
| 181 | + - os: windows |
| 182 | + target: aarch64 |
| 183 | + |
| 184 | + runs-on: ${{ matrix.os }}-latest |
| 185 | + steps: |
| 186 | + - uses: actions/checkout@v3 |
| 187 | + |
| 188 | + - name: set up python |
| 189 | + uses: actions/setup-python@v4 |
| 190 | + with: |
| 191 | + python-version: "3.11" |
| 192 | + architecture: ${{ matrix.python-architecture || 'x64' }} |
| 193 | + |
| 194 | + - run: pip install -U twine |
| 195 | + |
| 196 | + - name: build sdist |
| 197 | + if: ${{ matrix.os == 'ubuntu' && matrix.target == 'x86_64' && matrix.manylinux == 'auto' }} |
| 198 | + uses: PyO3/maturin-action@v1 |
| 199 | + with: |
| 200 | + command: sdist |
| 201 | + args: --out dist |
| 202 | + rust-toolchain: stable |
| 203 | + |
| 204 | + - name: build wheels |
| 205 | + uses: PyO3/maturin-action@v1 |
| 206 | + with: |
| 207 | + target: ${{ matrix.target }} |
| 208 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 209 | + container: ${{ matrix.container }} |
| 210 | + args: --release --out dist --interpreter ${{ matrix.interpreter || '3.7 3.8 3.9 3.10 3.11 pypy3.7 pypy3.8 pypy3.9' }} |
| 211 | + rust-toolchain: stable |
| 212 | + |
| 213 | + - run: ${{ matrix.ls || 'ls -lh' }} dist/ |
| 214 | + |
| 215 | + - run: twine check dist/* |
| 216 | + |
| 217 | + - uses: actions/upload-artifact@v3 |
| 218 | + with: |
| 219 | + name: wheels |
| 220 | + path: dist |
| 221 | + |
| 222 | + release: |
| 223 | + needs: [build, check] |
| 224 | + if: "success() && startsWith(github.ref, 'refs/tags/')" |
| 225 | + runs-on: ubuntu-latest |
| 226 | + |
| 227 | + steps: |
| 228 | + - uses: actions/checkout@v3 |
| 229 | + |
| 230 | + - name: set up python |
| 231 | + uses: actions/setup-python@v4 |
| 232 | + with: |
| 233 | + python-version: "3.10" |
| 234 | + |
| 235 | + - run: pip install -U twine |
| 236 | + |
| 237 | + - name: get dist artifacts |
| 238 | + uses: actions/download-artifact@v3 |
| 239 | + with: |
| 240 | + name: wheels |
| 241 | + path: dist |
| 242 | + |
| 243 | + - run: twine check dist/* |
| 244 | + |
| 245 | + - name: upload to pypi |
| 246 | + run: twine upload dist/* |
| 247 | + env: |
| 248 | + TWINE_USERNAME: __token__ |
| 249 | + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
0 commit comments