From 508fe0de0b82d94a74164cb7c98c69057cccd05e Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Fri, 19 Dec 2025 17:47:10 +0100 Subject: [PATCH 1/7] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Use=20prek=20as=20a=20?= =?UTF-8?q?pre-commit=20alternative?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c2f941a5..82907cbe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ -r requirements-tests.txt -pre-commit >=2.17.0,<5.0.0 +prek==0.2.22 From 84af21e9510d996fb0e4f7028ce5da2f6559cf93 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Mon, 22 Dec 2025 22:42:02 +0100 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=91=B7=20Add=20pre-commit=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pre-commit.yml | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..e628ce54 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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) }} From 18523ab727dbe8f35f496b806c277b934e3c0bff Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Mon, 22 Dec 2025 22:42:26 +0100 Subject: [PATCH 3/7] Update prek version to 0.2.23 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 82907cbe..c2a78036 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ -r requirements-tests.txt -prek==0.2.22 +prek==0.2.23 From cec35d29dcfa4c94cc28702e91a97b3475632a8d Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 13:51:52 +0100 Subject: [PATCH 4/7] Apply changes like in https://github.com/fastapi/fastapi/pull/14592 --- .github/workflows/pre-commit.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index e628ce54..b397912e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -7,7 +7,8 @@ on: - synchronize env: - IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }} + # Forks and Dependabot don't have access to secrets + HAS_SECRETS: ${{ secrets.PRE_COMMIT != '' }} jobs: pre-commit: @@ -19,7 +20,7 @@ jobs: run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v5 name: Checkout PR for own repo - if: env.IS_FORK == 'false' + if: env.HAS_SECRETS == 'true' with: # To be able to commit it needs to fetch the head of the branch, not the # merge commit @@ -31,7 +32,7 @@ jobs: # 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' + if: env.HAS_SECRETS == 'false' with: # To be able to commit it needs the head branch of the PR, the remote one ref: ${{ github.event.pull_request.head.sha }} @@ -56,7 +57,7 @@ jobs: 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' + if: env.HAS_SECRETS == 'true' run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" @@ -68,7 +69,7 @@ jobs: git push fi - uses: pre-commit-ci/lite-action@v1.1.0 - if: env.IS_FORK == 'true' + if: env.HAS_SECRETS == 'false' with: msg: 🎨 Auto format - name: Error out on pre-commit errors From a5b92feaf1f4beec99a94403812d9d5d670ed8f7 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 15:05:14 +0100 Subject: [PATCH 5/7] Update prek version to 0.2.24 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c2a78036..d4cde9a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ -r requirements-tests.txt -prek==0.2.23 +prek==0.2.24 From ea6c56b14df039f5885354b20b94c69bcaee3268 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 15:06:01 +0100 Subject: [PATCH 6/7] Update `.pre-commit-config.yaml` as in https://github.com/fastapi/fastapi/pull/14397/files --- .pre-commit-config.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 183f632d..42fdf257 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,5 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks -default_language_version: - python: python3.10 repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 @@ -20,6 +18,3 @@ repos: args: - --fix - id: ruff-format -ci: - autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks - autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate From 5cfb1a59ad4f51ea23186185848bcabce239d418 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 15:12:22 +0100 Subject: [PATCH 7/7] Remove `lint` step from `test.yml` --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3eed3e03..936ffb7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,8 +71,6 @@ jobs: limit-access-to-actor: true - name: Install Dependencies run: uv pip install -r requirements-tests.txt - - name: Lint - run: bash scripts/lint.sh - run: mkdir coverage - name: Test run: bash scripts/test.sh