|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | + |
| 10 | +env: |
| 11 | + PRE_COMMIT_COLOR: always |
| 12 | + |
| 13 | +jobs: |
| 14 | + # We only need to lint once, not for _each_ python version |
| 15 | + lint: |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + python-version: ['3.11'] |
| 21 | + os: [ubuntu-latest] |
| 22 | + env: |
| 23 | + PYTHON: ${{ matrix.python-version }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + - name: Install poetry |
| 27 | + run: pipx install poetry |
| 28 | + - name: Set up Python ${{ matrix.python-version }} |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: ${{ matrix.python-version }} |
| 32 | + cache: poetry |
| 33 | + - name: Install pre-commit |
| 34 | + run: pipx install pre-commit |
| 35 | + - name: Cache pre-commitdeps |
| 36 | + uses: actions/cache@v3 |
| 37 | + with: |
| 38 | + path: | |
| 39 | + ~/.cache/pre-commit/ |
| 40 | + key: precommit-py${{ matrix.python-version }}-precommit-${{ hashFiles('poetry.lock', '.pre-commit-config.yaml') }} |
| 41 | + restore-keys: precommit-py${{ matrix.python-version }}- |
| 42 | + - name: Install dependencies |
| 43 | + run: poetry install --no-root |
| 44 | + - name: Lint |
| 45 | + run: | |
| 46 | + pre-commit run --all-files -v --show-diff-on-failure |
| 47 | + pre-commit gc |
| 48 | + test: |
| 49 | + runs-on: ${{ matrix.os }} |
| 50 | + strategy: |
| 51 | + fail-fast: false |
| 52 | + matrix: |
| 53 | + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] |
| 54 | + os: [ubuntu-latest] |
| 55 | + env: |
| 56 | + PYTHON: ${{ matrix.python-version }} |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v3 |
| 59 | + - name: Install poetry |
| 60 | + run: pipx install poetry |
| 61 | + - name: Set up Python ${{ matrix.python-version }} |
| 62 | + uses: actions/setup-python@v4 |
| 63 | + with: |
| 64 | + python-version: ${{ matrix.python-version }} |
| 65 | + cache: poetry |
| 66 | + - name: Install dependencies |
| 67 | + run: poetry install |
| 68 | + - name: Test with pytest |
| 69 | + run: | |
| 70 | + make test args="--color=yes" |
| 71 | + poetry run pytest --dead-fixtures --dup-fixtures --color=yes |
| 72 | + - name: Upload coverage to Codecov |
| 73 | + |
| 74 | + with: |
| 75 | + flags: unittests |
| 76 | + env_vars: PYTHON |
| 77 | + |
| 78 | + check: |
| 79 | + if: always() |
| 80 | + needs: [test, lint] |
| 81 | + runs-on: ubuntu-latest |
| 82 | + steps: |
| 83 | + - name: Decide whether the needed jobs succeeded or failed |
| 84 | + uses: re-actors/alls-green@release/v1 |
| 85 | + with: |
| 86 | + jobs: ${{ toJSON(needs) }} |
| 87 | + |
| 88 | + build: |
| 89 | + runs-on: ${{ matrix.os }} |
| 90 | + strategy: |
| 91 | + fail-fast: false |
| 92 | + matrix: |
| 93 | + python-version: ['3.11'] |
| 94 | + os: [ubuntu-latest] |
| 95 | + name: build |
| 96 | + # only run on push to main and on release, or with tag |
| 97 | + if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build'))" |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v3 |
| 100 | + |
| 101 | + - name: Install poetry |
| 102 | + run: pipx install poetry |
| 103 | + - name: set up python |
| 104 | + uses: actions/setup-python@v4 |
| 105 | + with: |
| 106 | + python-version: ${{ matrix.python-version }} |
| 107 | + cache: 'poetry' |
| 108 | + |
| 109 | + - run: poetry build |
| 110 | + |
| 111 | + - run: ls -altrh dist/ |
| 112 | + shell: bash |
| 113 | + |
| 114 | + - uses: actions/upload-artifact@v3 |
| 115 | + with: |
| 116 | + name: pypi_files |
| 117 | + path: dist |
| 118 | + |
| 119 | + inspect-pypi-assets: |
| 120 | + needs: [build] |
| 121 | + runs-on: ubuntu-latest |
| 122 | + |
| 123 | + steps: |
| 124 | + - uses: actions/checkout@v3 |
| 125 | + |
| 126 | + - name: get dist artifacts |
| 127 | + uses: actions/download-artifact@v3 |
| 128 | + with: |
| 129 | + name: pypi_files |
| 130 | + path: dist |
| 131 | + |
| 132 | + - name: list dist files |
| 133 | + run: | |
| 134 | + ls -lh dist/ |
| 135 | + echo "`ls dist | wc -l` files" |
| 136 | + - name: extract and list sdist file |
| 137 | + run: | |
| 138 | + mkdir sdist-files |
| 139 | + tar -xvf dist/*.tar.gz -C sdist-files |
| 140 | + tree -a sdist-files |
| 141 | + - name: extract and list wheel file |
| 142 | + run: | |
| 143 | + ls dist/*.whl | head -n 1 |
| 144 | + python -m zipfile --list `ls dist/*.whl | head -n 1` |
| 145 | +
|
| 146 | + release: |
| 147 | + needs: [build, check] |
| 148 | + if: "success() && startsWith(github.ref, 'refs/tags/')" |
| 149 | + runs-on: ubuntu-latest |
| 150 | + |
| 151 | + steps: |
| 152 | + - uses: actions/checkout@v3 |
| 153 | + |
| 154 | + - name: Install poetry |
| 155 | + run: pipx install poetry |
| 156 | + - name: set up python |
| 157 | + uses: actions/setup-python@v4 |
| 158 | + with: |
| 159 | + python-version: '3.11' |
| 160 | + cache: 'poetry' |
| 161 | + |
| 162 | + - name: check package version |
| 163 | + run: | |
| 164 | + set -euo pipefail |
| 165 | + package_ver="$(poetry version --short)" |
| 166 | + if [[ "refs/tags/v${package_ver}" == "$GITHUB_REF" ]] |
| 167 | + echo "✓ GITHUB_REF version matches ${package_ver}" |
| 168 | + else |
| 169 | + echo >&2 "✖ GITHUB_REF '${GITHUB_REF}' does not match package version '${package_ver}' |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | +
|
| 173 | + - name: get dist artifacts |
| 174 | + uses: actions/download-artifact@v3 |
| 175 | + with: |
| 176 | + name: pypi_files |
| 177 | + path: dist |
| 178 | + |
| 179 | + |
| 180 | + - name: upload to pypi |
| 181 | + run: poetry publish --dry-run |
| 182 | + env: |
| 183 | + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.pypi_token }} |
| 184 | + |
| 185 | + - name: upload to github release |
| 186 | + uses: softprops/action-gh-release@v1 |
| 187 | + with: |
| 188 | + files: | |
| 189 | + dist/* |
| 190 | + generate_release_notes: true |
| 191 | + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} |
0 commit comments