Skip to content

Commit 05fed9d

Browse files
committed
feat(run-pre-commit): Add support for pre-commit version pinning
1 parent 60faf34 commit 05fed9d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

run-pre-commit/action.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
python-version:
99
description: Python version to install
1010
default: "3.12"
11+
pre-commit-version:
12+
description: Pre-commit version to install
13+
default: 4.2.0
1114
rust:
1215
description: Whether to install the Rust toolchain (and which version to use)
1316
rust-components:
@@ -33,6 +36,21 @@ runs:
3336
cache-dependency-path: .pre-commit-config.yaml
3437
cache: 'pip'
3538

39+
- name: Install pre-commit (${{ env.PRE_COMMIT_VERSION }})
40+
shell: bash
41+
env:
42+
PRE_COMMIT_VERSION: ${{ inputs.pre-commit-version }}
43+
run: |
44+
python -m pip install "pre-commit==$PRE_COMMIT_VERSION"
45+
46+
# This caches downloaded pre-commit hook artifacts and results in faster
47+
# workflow runs after an initial hydration run with the exact same hooks
48+
- name: Setup pre-commit Cache
49+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
50+
with:
51+
path: ~/.cache/pre-commit
52+
key: pre-commit-${{ inputs.pre-commit-version }}-python${{ inputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
53+
3654
- name: Setup Rust Toolchain
3755
uses: dtolnay/rust-toolchain@c5a29ddb4d9d194e7c84ec8c3fba61b1c31fee8c
3856
if: ${{ inputs.rust }}
@@ -72,6 +90,10 @@ runs:
7290
github_access_token: ${{ inputs.nix-github-token }}
7391
install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix }}/install
7492

75-
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
76-
with:
77-
extra_args: "--from-ref '${{ github.event.pull_request.base.sha }}' --to-ref '${{ github.event.pull_request.head.sha }}'"
93+
- name: Run pre-commit
94+
shell: bash
95+
env:
96+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
97+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
98+
run: |
99+
pre-commit run --show-diff-on-failure --color always --from-ref "$BASE_SHA" --to-ref "$HEAD_SHA"

0 commit comments

Comments
 (0)