|
| 1 | +name: PR pre-commit |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request_target: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | + |
| 16 | +jobs: |
| 17 | + pre-commit: |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/create-github-app-token@v2 |
| 22 | + id: app-token |
| 23 | + with: |
| 24 | + app-id: ${{ vars.APP_ID }} |
| 25 | + private-key: ${{ secrets.APP_KEY }} |
| 26 | + |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 30 | + ref: ${{ github.head_ref }} |
| 31 | + token: ${{ steps.app-token.outputs.token }} |
| 32 | + |
| 33 | + - uses: actions/setup-python@v5 |
| 34 | + with: |
| 35 | + python-version: "3.11" |
| 36 | + |
| 37 | + - uses: tj-actions/changed-files@v46.0.5 |
| 38 | + id: changed-files |
| 39 | + |
| 40 | + - name: List changed files |
| 41 | + run: echo '${{ steps.changed-files.outputs.all_changed_files }}' |
| 42 | + |
| 43 | + # only check the full repository if PR and correctly labelled |
| 44 | + - if: ${{ github.event_name != 'pull_request_target' || contains(github.event.pull_request.labels.*.name, 'full pre-commit') }} |
| 45 | + name: Full pre-commit |
| 46 | + uses: pre-commit/action@v3.0.1 |
| 47 | + with: |
| 48 | + extra_args: --all-files |
| 49 | + - if: ${{ github.event_name == 'pull_request_target' && !contains(github.event.pull_request.labels.*.name, 'full pre-commit') }} |
| 50 | + name: Local pre-commit |
| 51 | + uses: pre-commit/action@v3.0.1 |
| 52 | + with: |
| 53 | + extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }} |
| 54 | + |
| 55 | + # push fixes if pre-commit fails and PR is eligible |
| 56 | + - if: ${{ failure() && github.event_name == 'pull_request_target' && !github.event.pull_request.draft && !contains(github.event.pull_request.labels.*.name, 'stop pre-commit fixes') }} |
| 57 | + name: Push pre-commit fixes |
| 58 | + uses: stefanzweifel/git-auto-commit-action@v6 |
| 59 | + with: |
| 60 | + commit_message: Automatic `pre-commit` fixes |
| 61 | + commit_user_name: ayrna-actions-bot[bot] |
| 62 | + create_branch: false |
0 commit comments