From f5fe306f7d060f087c565a463114ea862db299ca Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Fri, 19 Dec 2025 16:40:51 +0100 Subject: [PATCH 1/9] =?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 f17705f380..d45416e45a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ -r requirements-tests.txt -r requirements-docs.txt -pre-commit >=2.17.0,<5.0.0 +prek==0.2.22 From 0b6e11af2f6ab51fd903955bd429d6b52825e808 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Mon, 22 Dec 2025 22:28:50 +0100 Subject: [PATCH 2/9] =?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 0000000000..e628ce541d --- /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 9b10446f653af78dc8f347dc1a3ffac05d496ed4 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Mon, 22 Dec 2025 22:34:12 +0100 Subject: [PATCH 3/9] 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 d45416e45a..81dabc967b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ -r requirements-tests.txt -r requirements-docs.txt -prek==0.2.22 +prek==0.2.23 From 17b0c5db3ce65408734e2ea3afd744575eb8306b Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 16:29:04 +0100 Subject: [PATCH 4/9] Remove `Lint` step from `test.yml` --- .github/workflows/test.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dadb437fbb..73e8ffa5a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,9 +81,6 @@ jobs: - name: Install Pydantic v2 if: matrix.pydantic-version == 'pydantic-v2' run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0" - - name: Lint - if: matrix.pydantic-version == 'pydantic-v2' && matrix.python-version != '3.8' - run: bash scripts/lint.sh - run: mkdir coverage - name: Test run: bash scripts/test.sh From 2754f5120954636e68673664e3de521147de48dc Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 16:33:05 +0100 Subject: [PATCH 5/9] 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 e628ce541d..b397912e67 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 6cb959aeb9220c074a313d4d28d8421408599913 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 16:33:49 +0100 Subject: [PATCH 6/9] 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 81dabc967b..01da92143d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ -r requirements-tests.txt -r requirements-docs.txt -prek==0.2.23 +prek==0.2.24 From 6cfe32431f5e2c8c1560a6cb8984b84279119777 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 16:35:10 +0100 Subject: [PATCH 7/9] 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 584ba3cbee..6f5c887c76 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 178b7ab3e8464eb79d9c80e71d57b03f2eaf5e69 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 23 Dec 2025 17:18:23 +0100 Subject: [PATCH 8/9] Remove new line to check linting with prek --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 5510da3c34..b122bcdab7 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -13,4 +13,4 @@ dirty-equals ==0.9.0 jinja2 ==3.1.6 # Remove when support for Python 3.8 is dropped typing-extensions ==4.13.2; python_version < "3.9" -typing-extensions ==4.15.0; python_version >= "3.9" +typing-extensions ==4.15.0; python_version >= "3.9" \ No newline at end of file From 56bd31b3924cb616a1ae066dc7110c6396af4269 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 23 Dec 2025 16:20:15 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 9d04e21180..4094a006c8 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -13,4 +13,4 @@ dirty-equals ==0.9.0 jinja2 ==3.1.6 # Remove when support for Python 3.8 is dropped typing-extensions ==4.13.2; python_version < "3.9" -typing-extensions ==4.15.0; python_version >= "3.9" \ No newline at end of file +typing-extensions ==4.15.0; python_version >= "3.9"