|
| 1 | +name: ci |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - develop |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: test-${{ github.ref_name }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +env: |
| 15 | + PYTHONUNBUFFERED: "1" |
| 16 | + FORCE_COLOR: "1" |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint: |
| 20 | + name: Lint |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + steps: |
| 25 | + - |
| 26 | + uses: actions/checkout@v3 |
| 27 | + - |
| 28 | + name: Set up Python 3.10 |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: '3.10' |
| 32 | + cache: 'pip' |
| 33 | + - |
| 34 | + name: Install Hatch |
| 35 | + run: | |
| 36 | + pip3 --quiet install --upgrade hatch |
| 37 | + - |
| 38 | + name: Lint project |
| 39 | + run: | |
| 40 | + hatch run lint:all |
| 41 | + - |
| 42 | + name: Check files with pre-commit |
| 43 | + uses: pre-commit/[email protected] |
| 44 | + test: |
| 45 | + name: Python ${{ matrix.python-version }} |
| 46 | + runs-on: ubuntu-latest |
| 47 | + permissions: |
| 48 | + contents: read |
| 49 | + needs: |
| 50 | + - lint |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + # No pikepdf wheels for pypy3.8 |
| 55 | + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3.9'] |
| 56 | + |
| 57 | + steps: |
| 58 | + - |
| 59 | + uses: actions/checkout@v3 |
| 60 | + - |
| 61 | + name: Start containers |
| 62 | + run: | |
| 63 | + docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test.yml pull --quiet |
| 64 | + docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test.yml up --detach |
| 65 | + echo "Wait for container to be started" |
| 66 | + sleep 5 |
| 67 | + - |
| 68 | + name: Set up Python ${{ matrix.python-version }} |
| 69 | + uses: actions/setup-python@v4 |
| 70 | + with: |
| 71 | + python-version: ${{ matrix.python-version }} |
| 72 | + cache: 'pip' |
| 73 | + - |
| 74 | + name: Install Hatch |
| 75 | + run: pip install --upgrade hatch |
| 76 | + - |
| 77 | + name: Run tests |
| 78 | + run: hatch run cov |
| 79 | + - |
| 80 | + name: Upload coverage to Codecov |
| 81 | + if: matrix.python-version == '3.10' |
| 82 | + uses: codecov/codecov-action@v3 |
| 83 | + with: |
| 84 | + # not required for public repos, but intermittently fails otherwise |
| 85 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 86 | + - |
| 87 | + name: Stop containers |
| 88 | + if: always() |
| 89 | + run: | |
| 90 | + docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test.yml logs |
| 91 | + docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test.yml down |
| 92 | +
|
| 93 | + build: |
| 94 | + name: Build |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: read |
| 98 | + needs: |
| 99 | + - lint |
| 100 | + steps: |
| 101 | + - |
| 102 | + uses: actions/checkout@v3 |
| 103 | + - |
| 104 | + name: Set up Python 3.10 |
| 105 | + uses: actions/setup-python@v4 |
| 106 | + with: |
| 107 | + python-version: '3.10' |
| 108 | + cache: 'pip' |
| 109 | + - |
| 110 | + name: Install Hatch |
| 111 | + run: | |
| 112 | + pip3 --quiet install --upgrade hatch |
| 113 | + - |
| 114 | + name: Build |
| 115 | + run: | |
| 116 | + hatch build --clean |
| 117 | + - |
| 118 | + uses: actions/upload-artifact@v3 |
| 119 | + with: |
| 120 | + name: artifacts |
| 121 | + path: dist/* |
| 122 | + if-no-files-found: error |
| 123 | + retention-days: 7 |
| 124 | + |
| 125 | + create-release: |
| 126 | + name: Release |
| 127 | + runs-on: ubuntu-latest |
| 128 | + if: startsWith(github.ref, 'refs/tags/') |
| 129 | + permissions: |
| 130 | + contents: write |
| 131 | + needs: |
| 132 | + - build |
| 133 | + - test |
| 134 | + steps: |
| 135 | + - |
| 136 | + uses: actions/checkout@v3 |
| 137 | + - |
| 138 | + uses: actions/download-artifact@v3 |
| 139 | + with: |
| 140 | + name: artifacts |
| 141 | + path: dist |
| 142 | + - |
| 143 | + name: Get latest release info |
| 144 | + id: query-release-info |
| 145 | + uses: release-flow/keep-a-changelog-action@v2 |
| 146 | + with: |
| 147 | + command: query |
| 148 | + version: ${{ github.ref_name }} |
| 149 | + - |
| 150 | + name: Display release info |
| 151 | + run: | |
| 152 | + echo "Version: ${{ steps.query-release-info.outputs.version }}" |
| 153 | + echo "Date: ${{ steps.query-release-info.outputs.release-date }}" |
| 154 | + echo "${{ steps.query-release-info.outputs.release-notes }}" |
| 155 | + - |
| 156 | + uses: ncipollo/release-action@v1 |
| 157 | + with: |
| 158 | + artifacts: "dist/*.tar.gz,dist/*.whl" |
| 159 | + body: ${{ steps.query-release-info.outputs.release-notes }} |
| 160 | + |
| 161 | + pypi-publish: |
| 162 | + name: Publish |
| 163 | + runs-on: ubuntu-latest |
| 164 | + if: startsWith(github.ref, 'refs/tags/') |
| 165 | + permissions: |
| 166 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 167 | + needs: |
| 168 | + - build |
| 169 | + - test |
| 170 | + steps: |
| 171 | + - |
| 172 | + uses: actions/download-artifact@v3 |
| 173 | + with: |
| 174 | + name: artifacts |
| 175 | + path: dist |
| 176 | + - |
| 177 | + name: Publish build to PyPI |
| 178 | + |
0 commit comments