|
| 1 | +name: Python checks |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + tags: [v*] |
| 7 | + pull_request: |
| 8 | + merge_group: |
| 9 | + |
| 10 | +env: |
| 11 | + FORCE_COLOR: 1 |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + linting: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + name: "Python linting" |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 22 | + |
| 23 | + - name: Install uv |
| 24 | + uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0 |
| 25 | + with: |
| 26 | + enable-cache: true |
| 27 | + cache-dependency-glob: "uv.lock" |
| 28 | + |
| 29 | + - name: Set up Python 🐍 |
| 30 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 31 | + with: |
| 32 | + python-version-file: "pyproject.toml" |
| 33 | + |
| 34 | + - name: Check lock is up-to-date |
| 35 | + run: | |
| 36 | + uv lock --check |
| 37 | +
|
| 38 | + - name: Install dependencies |
| 39 | + run: | |
| 40 | + uv sync |
| 41 | + echo "$PWD/.venv/bin" >> $GITHUB_PATH |
| 42 | +
|
| 43 | + - name: Check file formatting |
| 44 | + uses: astral-sh/ruff-action@eaf0ecdd668ceea36159ff9d91882c9795d89b49 # v3.4.0 |
| 45 | + with: |
| 46 | + args: "format --check" |
| 47 | + |
| 48 | + - name: Lint with ruff |
| 49 | + env: |
| 50 | + RUFF_OUTPUT_FORMAT: github |
| 51 | + run: | |
| 52 | + ruff check |
| 53 | +
|
| 54 | + - name: Typecheck with pyright |
| 55 | + uses: jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2 |
| 56 | + with: |
| 57 | + version: PATH |
| 58 | + |
| 59 | + tests: |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + os: ["ubuntu-latest", "windows-latest", "macos-latest"] |
| 64 | + python-version: ["3.11", "3.12", "3.13"] |
| 65 | + |
| 66 | + name: Python tests (${{ matrix.python-version }}, ${{ matrix.os }}) |
| 67 | + runs-on: ${{ matrix.os }} |
| 68 | + |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 71 | + |
| 72 | + - name: Install uv |
| 73 | + uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0 |
| 74 | + with: |
| 75 | + enable-cache: true |
| 76 | + cache-dependency-glob: "uv.lock" |
| 77 | + python-version: ${{ matrix.python-version }} |
| 78 | + |
| 79 | + - name: Set up Python ${{ matrix.python-version }} 🐍 |
| 80 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 81 | + with: |
| 82 | + python-version: ${{ matrix.python-version }} |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: uv sync |
| 86 | + |
| 87 | + - name: Install additional backends (best effort) |
| 88 | + continue-on-error: true |
| 89 | + run: uv sync --all-extras |
| 90 | + |
| 91 | + - name: Test with pytest |
| 92 | + run: | |
| 93 | + # codecov requires that the test results are shared in xunit1 / legacy format. |
| 94 | + uv run pytest -v --junitxml=junit.xml -o junit_family=legacy |
| 95 | +
|
| 96 | + - name: Upload coverage reports to Codecov |
| 97 | + uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 |
| 98 | + with: |
| 99 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 100 | + |
| 101 | + - name: Upload test results to Codecov |
| 102 | + if: ${{ !cancelled() }} |
| 103 | + uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1 |
| 104 | + with: |
| 105 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 106 | + |
| 107 | + test-summary: |
| 108 | + name: Test matrix status |
| 109 | + runs-on: ubuntu-latest |
| 110 | + needs: |
| 111 | + - linting |
| 112 | + - tests |
| 113 | + if: always() |
| 114 | + steps: |
| 115 | + - name: Decide whether the needed jobs succeeded or failed |
| 116 | + uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2 |
| 117 | + with: |
| 118 | + jobs: ${{ toJSON(needs) }} |
| 119 | + |
| 120 | + |
| 121 | + build: |
| 122 | + name: Build distribution 📦 |
| 123 | + runs-on: ubuntu-latest |
| 124 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 125 | + needs: |
| 126 | + - test-summary |
| 127 | + |
| 128 | + outputs: |
| 129 | + version: ${{ steps.note.outputs.version }} |
| 130 | + prerelease: ${{ steps.note.outputs.prerelease }} |
| 131 | + |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 134 | + |
| 135 | + - name: Install uv |
| 136 | + uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0 |
| 137 | + with: |
| 138 | + enable-cache: true |
| 139 | + cache-dependency-glob: "uv.lock" |
| 140 | + |
| 141 | + - name: Set up Python 🐍 |
| 142 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 143 | + with: |
| 144 | + python-version-file: "pyproject.toml" |
| 145 | + |
| 146 | + - name: Install dependencies |
| 147 | + run: | |
| 148 | + uv sync |
| 149 | +
|
| 150 | + - name: Build the Python 🐍 binary wheel and source tarball 📦 |
| 151 | + id: build-dist |
| 152 | + run: | |
| 153 | + uv build |
| 154 | + rm -f dist/.gitignore # get-releasenotes can't handle non-dist files here |
| 155 | + echo "version=$(uvx hatch version) >> $GITHUB_OUTPUT |
| 156 | +
|
| 157 | + - name: Check build |
| 158 | + run: uvx twine check --strict dist/* |
| 159 | + |
| 160 | + - name: Prepare Release Note |
| 161 | + id: note |
| 162 | + uses: aio-libs/get-releasenote@b0fcc7f3e5f5cc7c8b01e2f75516b1732f6bd8b2 # v1.4.5 |
| 163 | + with: |
| 164 | + changes_file: CHANGELOG.md |
| 165 | + output_file: release_notes.md |
| 166 | + version: ${{ steps.build-dist.outputs.version }} |
| 167 | + start_line: '<!-- changes go below this line -->' |
| 168 | + head_line: '## \[{version}\] - {date}\)' |
| 169 | + name: Rummikub Solver library |
| 170 | + dist_dir: dist |
| 171 | + |
| 172 | + - name: Store the Python 🐍 distribution 📦 |
| 173 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 174 | + with: |
| 175 | + name: python-package-distributions |
| 176 | + path: | |
| 177 | + dist/ |
| 178 | + release_notes.md |
| 179 | +
|
| 180 | + pypi-publish: |
| 181 | + name: Upload release to PyPI |
| 182 | + runs-on: ubuntu-latest |
| 183 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 184 | + needs: |
| 185 | + - build |
| 186 | + environment: |
| 187 | + name: pypi |
| 188 | + url: https://pypi.org/p/rummikub-solver |
| 189 | + permissions: |
| 190 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 191 | + |
| 192 | + steps: |
| 193 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 194 | + |
| 195 | + - name: Download Python 🐍 distribution 📦 |
| 196 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 197 | + with: |
| 198 | + name: python-package-distributions |
| 199 | + |
| 200 | + - name: Publish Python 🐍 distribution 📦 to PyPI |
| 201 | + uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 |
| 202 | + |
| 203 | + - name: GitHub release |
| 204 | + uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1.16.0 |
| 205 | + with: |
| 206 | + name: Rummikub Solver library ${{ needs.build.outputs.version }} |
| 207 | + bodyFile: release_notes.md |
| 208 | + artifacts: dist/* |
| 209 | + prerelease: ${{ needs.build.outputs.prerelease }} |
0 commit comments