-
-
Notifications
You must be signed in to change notification settings - Fork 824
👷 Add pre-commit workflow #1453
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
Merged
+258
−1
Merged
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| name: pre-commit | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - synchronize | ||
|
|
||
| env: | ||
| IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }} | ||
|
|
||
| jobs: | ||
| pre-commit: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Dump GitHub context | ||
| env: | ||
| GITHUB_CONTEXT: ${{ toJson(github) }} | ||
| run: echo "$GITHUB_CONTEXT" | ||
| - uses: actions/checkout@v5 | ||
| name: Checkout PR for own repo | ||
| if: env.IS_FORK == 'false' | ||
| with: | ||
| # To be able to commit it needs to fetch the head of the branch, not the | ||
| # merge commit | ||
| ref: ${{ github.head_ref }} | ||
| # And it needs the full history to be able to compute diffs | ||
| fetch-depth: 0 | ||
| # A token other than the default GITHUB_TOKEN is needed to be able to trigger CI | ||
| token: ${{ secrets.PRE_COMMIT }} | ||
| # pre-commit lite ci needs the default checkout configs to work | ||
| - uses: actions/checkout@v5 | ||
| name: Checkout PR for fork | ||
| if: env.IS_FORK == 'true' | ||
| with: | ||
| # To be able to commit it needs the head branch of the PR, the remote one | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| fetch-depth: 0 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.14" | ||
| - name: Setup uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| cache-dependency-glob: | | ||
| requirements**.txt | ||
| pyproject.toml | ||
| uv.lock | ||
| - name: Install Dependencies | ||
| run: | | ||
| uv venv | ||
| uv pip install -r requirements.txt | ||
| - name: Run prek - pre-commit | ||
| id: precommit | ||
| run: uvx prek run --from-ref origin/${GITHUB_BASE_REF} --to-ref HEAD --show-diff-on-failure | ||
| continue-on-error: true | ||
| - name: Commit and push changes | ||
| if: env.IS_FORK == 'false' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add -A | ||
| if git diff --staged --quiet; then | ||
| echo "No changes to commit" | ||
| else | ||
| git commit -m "🎨 Auto format" | ||
| git push | ||
| fi | ||
| - uses: pre-commit-ci/lite-action@v1.1.0 | ||
| if: env.IS_FORK == 'true' | ||
| with: | ||
| msg: 🎨 Auto format | ||
| - name: Error out on pre-commit errors | ||
| if: steps.precommit.outcome == 'failure' | ||
| run: exit 1 | ||
|
|
||
| # https://github.com/marketplace/actions/alls-green#why | ||
| pre-commit-alls-green: # This job does nothing and is only used for the branch protection | ||
| if: always() | ||
| needs: | ||
| - pre-commit | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Dump GitHub context | ||
| env: | ||
| GITHUB_CONTEXT: ${{ toJson(github) }} | ||
| run: echo "$GITHUB_CONTEXT" | ||
| - name: Decide whether the needed jobs succeeded or failed | ||
| uses: re-actors/alls-green@release/v1 | ||
| with: | ||
| jobs: ${{ toJSON(needs) }} |
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 |
|---|---|---|
|
|
@@ -3,4 +3,4 @@ | |
| -r requirements-tests.txt | ||
| -r requirements-docs.txt | ||
|
|
||
| pre-commit >=2.17.0,<5.0.0 | ||
| prek==0.2.22 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was autogenerated by prek, but we'll end up moving to uv, so it's fine to have it right away.