-
-
Notifications
You must be signed in to change notification settings - Fork 801
Swap pre-commit for prek (#20305) #20314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeonarddeR
wants to merge
30
commits into
nvaccess:master
Choose a base branch
from
LeonarddeR:prek
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b10884d
Swap pre-commit for prek (#20305)
LeonarddeR 3a3944e
Convert to native prek.toml, drop pre-commit.ci config
LeonarddeR d14b822
Add autofix-or-fail GitHub Actions workflow
LeonarddeR 213d8ce
Settle uv env before prek gate and cross-reference python version in …
LeonarddeR 48c1aec
Add scheduled prek auto-update workflow
LeonarddeR 313f715
Use consistent "Prek auto-update" title for auto-update PR
LeonarddeR 4c22e96
Docs and workflows: complete pre-commit.ci to prek + GitHub Actions m…
LeonarddeR 723f63a
Run prek via uvx instead of uv run in autofix workflow
LeonarddeR 8e0b7c4
Drop redundant prek hook install from add-new-language workflow
LeonarddeR 8716980
Add NVDA license headers to the new prek workflows
LeonarddeR 34a64e7
One sentence per line in the prek hooks doc
LeonarddeR 4b26a96
Don't activate uv venv
LeonarddeR e35c974
Run autofix on windows
LeonarddeR dc817a3
Definitely need submodules
LeonarddeR d01ee9a
Create a linter error on purpose so autofix will pick it up on fork
LeonarddeR 360e523
Auto-fix: apply prek fixes
invalid-email-address 5c2768e
Use prek-action for lint gate and standalone prek for auto-update
LeonarddeR b2aa55c
Update docs
LeonarddeR fa7beab
Guard prek auto-update to the upstream repo
LeonarddeR 0d24efa
Merge remote-tracking branch 'origin/master' into prek
LeonarddeR 4f97e6d
Review actions
LeonarddeR 9ef3c90
Bump action deps
LeonarddeR 320725b
Merge remote-tracking branch 'origin/master' into prek
LeonarddeR 6af4c05
Back to .pre-commit-config.yaml
LeonarddeR 433dcce
Remove stale mentions of prek.toml
LeonarddeR 20a40ea
Review actions
LeonarddeR 10a28c7
Update .github/workflows/autofix.yml
LeonarddeR 5004afa
Update job
LeonarddeR 42f85da
Merge branch 'master' into prek
seanbudd f73b431
Merge remote-tracking branch 'origin/master' into prek
LeonarddeR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # A part of NonVisual Desktop Access (NVDA) | ||
| # Copyright (C) 2026 NV Access Limited, Leonard de Ruijter | ||
| # This file may be used under the terms of the GNU General Public License, version 2 or later, as modified by the NVDA license. | ||
| # For full terms and any additional permissions, see the NVDA license file: https://github.com/nvaccess/nvda/blob/master/copying.txt | ||
|
|
||
| # This flow has a single job with two roles: | ||
| # - Autofix: on push events, run the fixer hooks (the "autofix" group), commit | ||
| # any fixes back to the branch, and push them. | ||
| # - Gate: on every event, run all hooks (minus the heavy/env-bound ones that | ||
| # have their own dedicated jobs in testAndPublish.yml) as a blocking check. | ||
| # | ||
| # The autofix step needs write access. On fork `pull_request` events GitHub | ||
| # downgrades the token to read-only, so autofix is guarded to push events only | ||
| # (it runs in a contributor's fork when they enable Actions, and on NV Access | ||
| # branches). On a fork PR with Actions disabled nothing gets fixed, so | ||
| # any lint issue fails the gate, forcing a manual fix or enabling fork Actions. | ||
|
|
||
| name: Autofix or fail | ||
|
|
||
| on: | ||
|
LeonarddeR marked this conversation as resolved.
|
||
| push: | ||
| # Never auto-fix or push to the protected branches; PRs targeting them are | ||
| # handled by the pull_request trigger below. | ||
| branches-ignore: | ||
| - master | ||
| - beta | ||
| - rc | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| - beta | ||
| - rc | ||
|
seanbudd marked this conversation as resolved.
seanbudd marked this conversation as resolved.
|
||
| - 'try-**' | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| autofix: | ||
| name: Auto-fix and lint gate | ||
| runs-on: windows-2025-vs2026 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| submodules: true | ||
| - name: Set up python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| # Keep in sync with defaultPythonVersion in testAndPublish.yml. | ||
| python-version: '3.13.13' | ||
| - name: Install the latest version of uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| activate-environment: "false" | ||
| # prek is run via `uvx` (an ephemeral, isolated tool run) rather than | ||
| # `uv run`. `uv run` would sync the project environment and could silently | ||
| # regenerate uv.lock as a side effect, masking a genuinely stale lock and | ||
| # causing spurious mid-run failures. `uvx` touches no project state, so the | ||
| # uv-lock hook itself is what gates lock staleness. | ||
| # Autofix only on push events (write token), and never react to the bot's | ||
| # own auto-fix commit. A commit pushed with this repo's GITHUB_TOKEN does | ||
| # not re-trigger this repo's own push workflow, so the fix commit cannot | ||
| # loop back into another autofix run here; the actor guard below just | ||
| # covers the rare manual re-run case too. (Note: on a fork PR the fix | ||
| # commit DOES start a fresh pull_request run on the base repo, since that | ||
| # is a different repository - but it lands as "action required" pending | ||
| # maintainer approval because the bot is the triggering actor.) | ||
| - name: Apply prek auto-fixes | ||
| if: github.event_name == 'push' && github.actor != 'github-actions[bot]' | ||
|
LeonarddeR marked this conversation as resolved.
Outdated
|
||
| shell: bash | ||
| env: | ||
| REF_NAME: ${{ github.ref_name }} | ||
| run: | | ||
| # Fixers exit non-zero when they change files. Some fixers' output feeds | ||
| # another fixer, so a single pass may not reach a stable tree. | ||
| # Re-run on the fixed tree until prek exits clean or we hit the cap. | ||
| for attempt in 1 2 3; do | ||
| if uvx prek run --group autofix --all-files; then | ||
| break | ||
| fi | ||
| done | ||
| if ! git diff --quiet; then | ||
| git config user.name "github-actions" | ||
| git config user.email "github-actions@github.com" | ||
| git add -A | ||
| git commit -m "Auto-fix: apply prek fixes" | ||
| # Push via an explicit refspec so this works even if checkout left us | ||
| # in a detached HEAD state. | ||
| git push origin HEAD:"$REF_NAME" | ||
| fi | ||
| # Blocking lint gate: runs on every event. The 6 skipped hooks are the | ||
| # heavy / environment-bound checks that have their own dedicated jobs in | ||
| # testAndPublish.yml. A non-zero exit here fails the job. | ||
| # Run via prek-action (not `uvx prek`) so prek's hook environments are | ||
| # cached across runs. The action installs prek standalone, so it does not | ||
| # touch uv.lock; on push events the gate runs against the tree already | ||
| # fixed by the autofix step above. | ||
| - name: Lint gate | ||
| uses: j178/prek-action@v2 | ||
| with: | ||
| extra-args: >- | ||
| --all-files | ||
| --skip checkPo | ||
| --skip scons-source | ||
| --skip checkPot | ||
| --skip unitTest | ||
| --skip licenseCheck | ||
| --skip pyright | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||
| # A part of NonVisual Desktop Access (NVDA) | ||||||
| # Copyright (C) 2026 NV Access Limited, Leonard de Ruijter | ||||||
| # This file may be used under the terms of the GNU General Public License, version 2 or later, as modified by the NVDA license. | ||||||
| # For full terms and any additional permissions, see the NVDA license file: https://github.com/nvaccess/nvda/blob/master/copying.txt | ||||||
|
|
||||||
| name: Prek auto-update | ||||||
|
|
||||||
| on: | ||||||
| schedule: | ||||||
| # Monthly, at midnight on the first day of the month. | ||||||
| - cron: '0 0 1 * *' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SaschaCowley - thoughts on keeping this manual only for now?
Suggested change
|
||||||
| workflow_dispatch: | ||||||
|
|
||||||
| permissions: | ||||||
| contents: write | ||||||
| pull-requests: write | ||||||
|
|
||||||
| jobs: | ||||||
| prekAutoUpdate: | ||||||
| name: Prek auto-update | ||||||
| runs-on: ubuntu-latest | ||||||
| steps: | ||||||
| - name: Checkout code | ||||||
| uses: actions/checkout@v7 | ||||||
| # Install prek as a standalone binary | ||||||
| - name: Install prek | ||||||
| run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/latest/download/prek-installer.sh | sh | ||||||
| # --cooldown-days skips releases younger than 3 days, avoiding pinning to | ||||||
| # a freshly published (and potentially yanked/broken) hook revision. | ||||||
| - name: Run prek auto-update | ||||||
| run: prek auto-update --cooldown-days 3 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SaschaCowley thoughts on changing this to 7? higher?
Suggested change
|
||||||
| - name: Create pull request | ||||||
| shell: bash | ||||||
| env: | ||||||
| GITHUB_TOKEN: ${{ github.token }} | ||||||
| run: | | ||||||
| if git diff --quiet; then | ||||||
| echo "No hook updates available." | ||||||
| exit 0 | ||||||
| fi | ||||||
| git config --local user.name "github-actions" | ||||||
| git config --local user.email "github-actions@github.com" | ||||||
| git checkout -b prek-autoupdate | ||||||
| git commit -am "Prek auto-update" | ||||||
| # Force push so a re-run replaces a stale auto-update branch. | ||||||
| git push --force --set-upstream origin prek-autoupdate | ||||||
| # Reuse the existing PR if one is already open from a previous run. | ||||||
| gh pr create --base master --head prek-autoupdate \ | ||||||
| --title "Prek auto-update" \ | ||||||
| --body "Automated update of prek hook revisions." \ | ||||||
| || echo "A pull request for prek-autoupdate already exists." | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.