Skip to content

build(ci): adopt prek for pre-commit hooks and CI autoformat#118

Merged
billyvg merged 4 commits into
mainfrom
billyvong/scm-prek-precommit
Jul 14, 2026
Merged

build(ci): adopt prek for pre-commit hooks and CI autoformat#118
billyvg merged 4 commits into
mainfrom
billyvong/scm-prek-precommit

Conversation

@billyvg

@billyvg billyvg commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Adopts prek — a drop-in pre-commit runner — for local hooks and adds a CI workflow that runs the same hooks and auto-applies formatting fixes. Modeled on the seer and sentry repos.

Important

The formatting changes prek surfaces on the existing codebase are not in this PR. They live in a separate formatting-only PR that should be merged first so this branch's CI passes cleanly.

Changes

  • pyproject.toml / uv.lock — swap pre-commit dev dependency for prek.
  • .envrc — install the git pre-commit hook automatically on direnv load (errors out with uv sync hint if prek is missing).
  • .pre-commit-config.yaml — same ruff + mypy hooks; add exclude: ^bin/ to mypy so the hook matches CI's mypy . scope (which only checks .py files, not the shebang'd bin/ CLI scripts).
  • .github/workflows/pre-commit.yml — runs on PRs and pushes to main. Runs prek over changed files (via dorny/paths-filter), caches ~/.cache/prek, and on failure pushes autofixes back to trusted same-repo non-draft PRs using the SENTRY_INTERNAL_APP token before failing the job.
  • AGENTS.md — document the linting/formatting setup.

Notes

  • Requires SENTRY_INTERNAL_APP_ID (var) and SENTRY_INTERNAL_APP_PRIVATE_KEY (secret) to be available to the repo for autofix pushes. If absent, the autofix step is skipped gracefully and the job simply fails on lint.

Test plan

  • uv run prek run --all-files passes all hooks (post-formatting).
  • uv run mypy . succeeds; full test suite passes (802 tests).

🤖 Generated with Claude Code

Swap the `pre-commit` dev dependency for `prek`, a drop-in runner for the
same `.pre-commit-config.yaml` (ruff + mypy). `.envrc` now installs the git
pre-commit hook automatically on `direnv` load.

Add a `pre-commit` CI workflow that runs the hooks on changed files for every
pull request and pushes any autofixes back to trusted same-repo PRs using the
SENTRY_INTERNAL_APP token.

The mypy hook excludes `bin/` to match CI's `mypy .` scope, which only checks
`.py` files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@billyvg
billyvg marked this pull request as ready for review July 14, 2026 19:24
@billyvg
billyvg requested a review from a team as a code owner July 14, 2026 19:24
billyvg added a commit that referenced this pull request Jul 14, 2026
## Summary

Applies `ruff format` across the codebase (including the shebang'd
`bin/` scripts that prek's hook picks up). Formatting-only — no behavior
changes.

This is the prerequisite for #118, which adopts prek and enforces these
hooks in CI. **Merge this first** so #118's CI passes cleanly.

## Test plan

- `uv run ruff check .` and `uv run ruff format --check .` pass.
- Full test suite passes (802 tests).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread .github/workflows/pre-commit.yml Outdated

env:
# Secrets cannot be referenced directly in `if` expressions.
SECRET_ACCESS: ${{ toJSON(secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY != null) }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repo should have access to this org secret, we'll find out i guess

Drop the push-to-main trigger; the hooks only need to gate PRs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread .github/workflows/pre-commit.yml Outdated
Comment thread .github/workflows/pre-commit.yml Outdated
Pin every third-party action reference to a full commit SHA (with a version
comment) to protect against tag-hijacking supply-chain attacks. Covers the
new pre-commit workflow as well as the pre-existing build, tests, and release
workflows, which were on floating major tags.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ae71c5a. Configure here.

Comment thread .github/workflows/pre-commit.yml Outdated
Comment thread .github/workflows/pre-commit.yml Outdated
Comment thread .github/workflows/pre-commit.yml Outdated
- Detect an unset SENTRY_INTERNAL_APP_PRIVATE_KEY by comparing against '' —
  an absent secret is an empty string, not null, so the old guard was always
  true and the auth-token step ran (and failed) instead of being skipped.
- Key the prek cache on .python-version rather than env.pythonLocation, which
  setup-uv (unlike setup-python) never sets, so the version was omitted and a
  stale cache could survive a Python upgrade.
- Add xargs -r so an all-deletions PR (empty file list) doesn't invoke prek
  with no arguments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@billyvg
billyvg merged commit 4f378b0 into main Jul 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants