|
| 1 | +# A part of NonVisual Desktop Access (NVDA) |
| 2 | +# Copyright (C) 2026 NV Access Limited, Leonard de Ruijter |
| 3 | +# This file may be used under the terms of the GNU General Public License, version 2 or later, as modified by the NVDA license. |
| 4 | +# For full terms and any additional permissions, see the NVDA license file: https://github.com/nvaccess/nvda/blob/master/copying.txt |
| 5 | + |
| 6 | +name: Autofix or fail |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + # Never auto-fix the protected branches; PRs to them use pull_request below. |
| 11 | + branches-ignore: |
| 12 | + - master |
| 13 | + - beta |
| 14 | + - rc |
| 15 | + pull_request: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + - beta |
| 19 | + - rc |
| 20 | + - 'try-**' |
| 21 | + workflow_dispatch: |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + autofix: |
| 31 | + name: Auto-fix and lint gate |
| 32 | + # On the base repo the pull_request run is the gate; skip its push run on non-Fork pushes to |
| 33 | + # avoid a duplicate. Fork pushes still run for autofix. |
| 34 | + if: github.event_name != 'push' || github.repository != 'nvaccess/nvda' |
| 35 | + runs-on: windows-2025-vs2026 |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + uses: actions/checkout@v7 |
| 39 | + with: |
| 40 | + submodules: true |
| 41 | + - name: Set up python |
| 42 | + uses: actions/setup-python@v6 |
| 43 | + with: |
| 44 | + # Keep in sync with defaultPythonVersion in testAndPublish.yml. |
| 45 | + python-version: '3.13.13' |
| 46 | + - name: Install the latest version of uv |
| 47 | + uses: astral-sh/setup-uv@v7 |
| 48 | + with: |
| 49 | + activate-environment: "false" |
| 50 | + # Autofix role: run the fixer hooks (the "autofix" group) and push the fixes. |
| 51 | + - name: Apply prek auto-fixes |
| 52 | + if: github.event_name == 'push' |
| 53 | + shell: bash |
| 54 | + env: |
| 55 | + REF_NAME: ${{ github.ref_name }} |
| 56 | + run: | |
| 57 | + # Fixers exit non-zero when they change files. Some fixers' output feeds |
| 58 | + # another fixer, so a single pass may not reach a stable tree. |
| 59 | + # Re-run on the fixed tree until prek exits clean or we hit the cap. |
| 60 | + for attempt in 1 2 3; do |
| 61 | + if uvx prek run --group autofix --all-files; then |
| 62 | + break |
| 63 | + fi |
| 64 | + done |
| 65 | + if ! git diff --quiet; then |
| 66 | + git config user.name "github-actions" |
| 67 | + git config user.email "github-actions@github.com" |
| 68 | + git add -A |
| 69 | + git commit -m "Auto-fix: apply prek fixes" |
| 70 | + # Push via an explicit refspec so this works even if checkout left us |
| 71 | + # in a detached HEAD state. |
| 72 | + git push origin HEAD:"$REF_NAME" |
| 73 | + fi |
| 74 | + # Gate role: the merge-required blocking check (non-zero exit fails the job). |
| 75 | + # The 6 skipped hooks are the heavy/env-bound ones with dedicated jobs in |
| 76 | + # testAndPublish.yml. |
| 77 | + - name: Lint gate |
| 78 | + uses: j178/prek-action@v2 |
| 79 | + with: |
| 80 | + extra-args: >- |
| 81 | + --all-files |
| 82 | + --skip checkPo |
| 83 | + --skip scons-source |
| 84 | + --skip checkPot |
| 85 | + --skip unitTest |
| 86 | + --skip licenseCheck |
| 87 | + --skip pyright |
0 commit comments