Skip to content

Commit 29c0a28

Browse files
fix(ci): skip no-commit-to-branch for pre-commit run on main (#43)
The hook fails when HEAD is main/master, which breaks lint.yml on push to main and local just check/precommit on main. Set SKIP only for pre-commit run invocations; git commit still runs the hook unless SKIP is exported in the shell. - lint.yml and template ci.yml.jinja: env SKIP on pre-commit step - justfile and template: SKIP on precommit and check recipes - Integration test asserts SKIP in generated ci.yml and justfile Made-with: Cursor Co-authored-by: Claude <claude@anthropic.com>
1 parent c9488e7 commit 29c0a28

7 files changed

Lines changed: 19 additions & 9 deletions

File tree

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ jobs:
5959
- name: Root/template sync policy check
6060
run: uv run python scripts/check_root_template_sync.py
6161

62+
# no-commit-to-branch blocks direct commits to main; SKIP avoids false failures when
63+
# checkout is on main (e.g. post-merge push) while still running the hook on git commit.
6264
- name: Pre-commit (all files)
65+
env:
66+
SKIP: no-commit-to-branch
6367
run: uv run pre-commit run --all-files

justfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ cz-commit:
172172
@uv run cz commit
173173

174174
precommit:
175-
@uv run pre-commit run --all-files
175+
@SKIP=no-commit-to-branch uv run pre-commit run --all-files
176176

177177
# Dependency audit matching .github/workflows/security.yml (pip-audit).
178178
# Uses ``uv run --with pip-audit`` so the tool runs with the project Python (``uv tool run``/``uvx``
@@ -274,7 +274,7 @@ check:
274274
@just sync-check
275275
@just docs-check
276276
@just test-ci
277-
@uv run pre-commit run --all-files
277+
@SKIP=no-commit-to-branch uv run pre-commit run --all-files
278278
# @just audit
279279

280280
ci:
@@ -324,9 +324,9 @@ doctor:
324324
# - Push permissions to main branch
325325
#
326326
# Usage:
327-
# just release patch # v0.0.8 → v0.0.9 (bug fixes)
328-
# just release minor # v0.0.8 → v0.1.0 (new features)
329-
# just release major # v0.0.8 → v1.0.0 (breaking changes)
327+
# just release patch # v0.0.9 → v0.0.10 (bug fixes)
328+
# just release minor # v0.0.9 → v0.1.0 (new features)
329+
# just release major # v0.0.9 → v1.0.0 (breaking changes)
330330
release BUMP_TYPE="patch":
331331
@echo "=== Release Workflow ==="
332332
@echo "Release type: {{BUMP_TYPE}}"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python_project_template"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
description = "Copier template repository for generating uv-first Python projects."
55
readme = "README.md"
66
requires-python = ">=3.11"

template/.github/workflows/ci.yml.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ jobs:
8888
- name: Install dependencies
8989
run: uv sync --frozen --extra dev --extra test{% if include_docs %} --extra docs{% endif %}
9090

91+
# no-commit-to-branch blocks direct commits to main; SKIP avoids false failures when
92+
# checkout is on main (e.g. post-merge push) while still running the hook on git commit.
9193
- name: Pre-commit (all files)
94+
env:
95+
SKIP: no-commit-to-branch
9296
run: uv run pre-commit run --all-files
9397

9498
test:

template/justfile.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ cz-commit:
149149
@uv run cz commit
150150

151151
precommit:
152-
@uv run pre-commit run --all-files
152+
@SKIP=no-commit-to-branch uv run pre-commit run --all-files
153153

154154
# Dependency audit matching .github/workflows/security.yml (pip-audit).
155155
# Uses ``uv run --with pip-audit`` so the tool runs with the project Python (``uv tool run``/``uvx``
@@ -266,7 +266,7 @@ check:
266266
@uv run basedpyright
267267
@just docs-check
268268
@just test-ci
269-
@uv run pre-commit run --all-files
269+
@SKIP=no-commit-to-branch uv run pre-commit run --all-files
270270

271271
ci:
272272
@just fix

tests/integration/test_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ def test_ci_workflow_aligns_with_just_ci(tmp_path: Path) -> None:
15681568
"Aggregate check must gate on pre-commit alongside lint, typecheck, and tests"
15691569
)
15701570
assert "uv run pre-commit run --all-files" in workflow
1571+
assert "SKIP: no-commit-to-branch" in workflow
15711572
assert "uv run ruff format --check src tests" in workflow
15721573
assert "uv run ruff check src tests" in workflow
15731574
assert (
@@ -1582,6 +1583,7 @@ def test_ci_workflow_aligns_with_just_ci(tmp_path: Path) -> None:
15821583
in justfile
15831584
)
15841585
assert "@just test-ci" in justfile
1586+
assert "SKIP=no-commit-to-branch uv run pre-commit run --all-files" in justfile
15851587

15861588
lint_yml = (test_dir / ".github" / "workflows" / "lint.yml").read_text(encoding="utf-8")
15871589
assert "uv run ruff format --check src tests" in lint_yml

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)