Skip to content

Commit 80b67d4

Browse files
committed
ci: add pre-commit GitHub Actions workflow
Add automated pre-commit check workflow that runs on PRs and pushes to main. Uses caching to optimize performance - runs full check when config changes, otherwise only checks modified files for faster feedback. This ensures all commits meet linting standards before merge. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: dann frazier <dann.frazier@chainguard.dev>
1 parent e08c679 commit 80b67d4

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/pre-commit.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
branches:
6+
- "main" # required to create a usable cache for other PRs
7+
pull_request:
8+
branches:
9+
- "main"
10+
11+
permissions: {}
12+
13+
jobs:
14+
lint:
15+
name: pre-commit checks
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
steps:
20+
- name: Harden Runner
21+
uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3
22+
with:
23+
egress-policy: audit
24+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
with:
26+
fetch-depth: 0 # required for --from-ref and --to-ref
27+
persist-credentials: false
28+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
29+
- run: |
30+
python -m pip install pre-commit
31+
python -m pip freeze --local
32+
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
33+
id: cache
34+
with:
35+
path: ~/.cache/pre-commit
36+
key: ${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
37+
# A cache miss means that the pre-commit config changed and we should check everything
38+
# Otherwise, we can just check modified files which will be much faster
39+
- if: steps.cache.outputs.cache-hit != 'true'
40+
run: pre-commit run --show-diff-on-failure --color=always --all-files
41+
- if: steps.cache.outputs.cache-hit == 'true'
42+
run: pre-commit run --show-diff-on-failure --color=always --from-ref HEAD^^^ --to-ref HEAD

0 commit comments

Comments
 (0)