|
| 1 | +name: Test |
| 2 | +description: Setup Poetry and run ruff, mypy, and pytest for Python projects |
| 3 | + |
| 4 | +inputs: |
| 5 | + python-version: |
| 6 | + description: Python version to use |
| 7 | + required: false |
| 8 | + default: "3.14" |
| 9 | + poetry-version: |
| 10 | + description: Poetry version to install |
| 11 | + required: false |
| 12 | + default: "2.2.1" |
| 13 | + src-dirs: |
| 14 | + description: Source directories for linting (space-separated) |
| 15 | + required: false |
| 16 | + default: "src tests" |
| 17 | + |
| 18 | +runs: |
| 19 | + using: composite |
| 20 | + steps: |
| 21 | + - name: Setup Python ${{ inputs.python-version }} |
| 22 | + id: setup |
| 23 | + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 |
| 24 | + with: |
| 25 | + python-version: ${{ inputs.python-version }} |
| 26 | + |
| 27 | + - name: Load cached Poetry installation |
| 28 | + id: cached-poetry |
| 29 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 30 | + with: |
| 31 | + path: ~/.local |
| 32 | + key: poetry-${{ inputs.poetry-version }} |
| 33 | + |
| 34 | + - name: Install Poetry |
| 35 | + uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 |
| 36 | + with: |
| 37 | + version: ${{ inputs.poetry-version }} |
| 38 | + virtualenvs-path: ~/.venv |
| 39 | + |
| 40 | + - name: Load cached venv |
| 41 | + id: venv |
| 42 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 43 | + with: |
| 44 | + path: ~/.venv |
| 45 | + key: venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 46 | + restore-keys: | |
| 47 | + venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}- |
| 48 | +
|
| 49 | + - name: Sync dependencies |
| 50 | + if: steps.venv.outputs.cache-hit != 'true' |
| 51 | + shell: bash |
| 52 | + run: poetry sync --no-interaction --no-root |
| 53 | + |
| 54 | + - name: Install project |
| 55 | + shell: bash |
| 56 | + run: poetry install --no-interaction --only-root |
| 57 | + |
| 58 | + - name: Run ruff check |
| 59 | + shell: bash |
| 60 | + run: poetry run ruff check ${{ inputs.src-dirs }} |
| 61 | + |
| 62 | + - name: Run ruff format check |
| 63 | + shell: bash |
| 64 | + run: poetry run ruff format --check ${{ inputs.src-dirs }} |
| 65 | + |
| 66 | + - name: Run mypy |
| 67 | + shell: bash |
| 68 | + run: poetry run mypy ${{ inputs.src-dirs }} |
| 69 | + |
| 70 | + - name: Run pytest |
| 71 | + shell: bash |
| 72 | + run: poetry run pytest |
0 commit comments