|
| 1 | +name: Lint check |
| 2 | +run-name: Lint code |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +concurrency: |
| 10 | + # Cancel previous workflow run when a new commit is pushed to a feature branch |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} |
| 13 | + |
| 14 | +env: |
| 15 | + PYTHON_VERSION: "3.10" |
| 16 | + |
| 17 | +jobs: |
| 18 | + changed-files: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + name: Get changed files |
| 21 | + outputs: |
| 22 | + any_python_changed: ${{ steps.raw-changed-python-files.outputs.any_changed }} |
| 23 | + changed_python_files: ${{ steps.changed-python-files.outputs.all_changed_files }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v6 |
| 26 | + - name: Get changed python files |
| 27 | + id: raw-changed-python-files |
| 28 | + uses: tj-actions/changed-files@v47 |
| 29 | + with: |
| 30 | + files: | |
| 31 | + **.py |
| 32 | + poetry.lock |
| 33 | +
|
| 34 | + - name: Check changed python files |
| 35 | + id: changed-python-files |
| 36 | + env: |
| 37 | + CHANGED_PYTHON_FILES: ${{ steps.raw-changed-python-files.outputs.all_changed_files }} |
| 38 | + run: | |
| 39 | + if [[ " $CHANGED_PYTHON_FILES " == *" poetry.lock "* ]]; then |
| 40 | + # if poetry.lock is changed, we need to check everything |
| 41 | + CHANGED_PYTHON_FILES="." |
| 42 | + fi |
| 43 | + echo "all_changed_files=$CHANGED_PYTHON_FILES" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + format: |
| 46 | + if: needs.changed-files.outputs.any_python_changed == 'true' |
| 47 | + runs-on: ubuntu-latest |
| 48 | + name: Check formatting |
| 49 | + needs: changed-files |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v6 |
| 52 | + - name: Install Python tools |
| 53 | + uses: BrandonLWhite/pipx-install-action@v1.0.3 |
| 54 | + - uses: actions/setup-python@v6 |
| 55 | + with: |
| 56 | + python-version: ${{ env.PYTHON_VERSION }} |
| 57 | + cache: poetry |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: poetry install |
| 61 | + |
| 62 | + - name: Check code formatting |
| 63 | + # the job output will contain colored diffs with what needs adjusting |
| 64 | + run: poe check-format --output-format=github ${{ needs.changed-files.outputs.changed_python_files }} |
| 65 | + |
| 66 | + lint: |
| 67 | + if: needs.changed-files.outputs.any_python_changed == 'true' |
| 68 | + runs-on: ubuntu-latest |
| 69 | + name: Check linting |
| 70 | + needs: changed-files |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v6 |
| 73 | + - name: Install Python tools |
| 74 | + uses: BrandonLWhite/pipx-install-action@v1.0.3 |
| 75 | + - uses: actions/setup-python@v6 |
| 76 | + with: |
| 77 | + python-version: ${{ env.PYTHON_VERSION }} |
| 78 | + cache: poetry |
| 79 | + |
| 80 | + - name: Install dependencies |
| 81 | + run: poetry install |
| 82 | + |
| 83 | + - name: Lint code |
| 84 | + run: poe lint --output-format=github ${{ needs.changed-files.outputs.changed_python_files }} |
| 85 | + |
| 86 | + mypy: |
| 87 | + if: needs.changed-files.outputs.any_python_changed == 'true' |
| 88 | + runs-on: ubuntu-latest |
| 89 | + name: Check types with mypy |
| 90 | + needs: changed-files |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v6 |
| 93 | + - name: Install Python tools |
| 94 | + uses: BrandonLWhite/pipx-install-action@v1.0.3 |
| 95 | + - uses: actions/setup-python@v6 |
| 96 | + with: |
| 97 | + python-version: ${{ env.PYTHON_VERSION }} |
| 98 | + cache: poetry |
| 99 | + |
| 100 | + - name: Install dependencies |
| 101 | + run: poetry install |
| 102 | + |
| 103 | + - name: Type check code |
| 104 | + uses: liskin/gh-problem-matcher-wrap@v3 |
| 105 | + with: |
| 106 | + linters: mypy |
| 107 | + run: poe check-types --show-column-numbers --no-error-summary . |
0 commit comments