]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
👷 Add pre-commit workflow (#1684)
authorMotov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Wed, 24 Dec 2025 15:49:07 +0000 (16:49 +0100)
committerGitHub <noreply@github.com>
Wed, 24 Dec 2025 15:49:07 +0000 (16:49 +0100)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
.github/workflows/pre-commit.yml [new file with mode: 0644]
.github/workflows/test.yml
.pre-commit-config.yaml
requirements.txt

diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
new file mode 100644 (file)
index 0000000..b397912
--- /dev/null
@@ -0,0 +1,93 @@
+name: pre-commit
+
+on:
+  pull_request:
+    types:
+      - opened
+      - synchronize
+
+env:
+  # Forks and Dependabot don't have access to secrets
+  HAS_SECRETS: ${{ secrets.PRE_COMMIT != '' }}
+
+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.HAS_SECRETS == 'true'
+        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.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 }}
+          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.HAS_SECRETS == 'true'
+        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.HAS_SECRETS == 'false'
+        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) }}
index 9738ecf5706e248d6dd7871af2d90244a8e0c8c6..72dff0d732d5f85525d7e7c5189ef2236efe5013 100644 (file)
@@ -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
index 916fb479354b35e532df711c8c68645a221e3cfc..20a49e7a9422ee954478e45e107b6df8c397a010 100644 (file)
@@ -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
index f17705f380fb09fb4f3511f1315ffd58b6c44846..01da92143dd7a0bbe576d901803b484ffb1cff6c 100644 (file)
@@ -3,4 +3,4 @@
 -r requirements-tests.txt
 -r requirements-docs.txt
 
-pre-commit >=2.17.0,<5.0.0
+prek==0.2.24