Skip to content

Feature/precommit hooks - #517

Draft
danielschlegel wants to merge 1 commit into
mainfrom
feature/precommit-hooks
Draft

Feature/precommit hooks#517
danielschlegel wants to merge 1 commit into
mainfrom
feature/precommit-hooks

Conversation

@danielschlegel

@danielschlegel danielschlegel commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Add prek pre-commit hooks for lint auto-fix

What

Introduces prek as a Git pre-commit hook manager to automatically fix Go linting and formatting issues before every commit.

Changes

prek.toml (new) — declares two hooks that run on staged .go files:

  • gofumpt — formats code in-place using the same formatter enabled in .golangci.yaml.
  • golangci-lint --fix — applies all auto-fixable lint corrections. Runs against full packages (pass_filenames = false) so type-checking is correct.

.mise.toml — adds three new tools so mise install sets up the full dev environment in one step:

  • prek 0.4.3 — the hook manager itself.
  • golangci-lint v2.11.4 (via go: backend) — pinned to match the version in Earthfile.
  • gofumpt v0.10.0 (via go: backend) — pinned to the current latest release.

Both tool versions carry # renovate: comments so Renovate will keep them in sync automatically.

CONTRIBUTING.md — adds a Pre-commit hooks section documenting the two-command setup:

mise install   # installs all tools
prek install   # wires up .git/hooks/pre-commit

How it works

On git commit, prek runs the hooks against staged .go files only (non-Go commits are unaffected). If a hook modifies a file, the commit is blocked so you can review the diff, re-stage, and commit again. To pre-apply all fixes before staging: prek run --all-files.

@danielschlegel danielschlegel self-assigned this May 27, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces pre-commit hooks using prek, updates various tool versions in .mise.toml, migrates repository references from the earthly organization to EarthBuild/earthbuild, and upgrades several Go dependencies in go.mod. The reviewer identified three critical issues: invalid module paths and non-existent versions for both golangci-lint and gofumpt in .mise.toml which will cause installation failures, and a mismatched variable name (BUILDKIT_BRANCH instead of BUILDKIT_GIT_BRANCH) in buildkitd/Earthfile that results in empty branch names in logs.

Comment thread .mise.toml Outdated
Comment thread buildkitd/Earthfile Outdated
@danielschlegel

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Comment thread prek.toml Outdated
@gilescope

Copy link
Copy Markdown

Are these several things going on here? Is this the minimal changes for the precommit? Could we get these split out into smaller PRs please?

@danielschlegel
danielschlegel force-pushed the feature/precommit-hooks branch from a9634ba to 9ef9821 Compare June 4, 2026 11:36
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

⚠️ Are we earthbuild yet?

Warning: "earthly" occurrences have increased by 5 (0.09%)

📈 Overall Progress

Branch Total Count
main 5344
This PR 5349
Difference +5 (0.09%)

📁 Changes by file type:

File Type Change
Go files (.go) ➖ No change
Documentation (.md) ➖ No change
Earthfiles ❌ +3

Keep up the great work migrating from Earthly to Earthbuild! 🚀

💡 Tips for finding more occurrences

Run locally to see detailed breakdown:

./.github/scripts/count-earthly.sh

Note that the goal is not to reach 0.
There is anticipated to be at least some occurences of earthly in the source code due to backwards compatibility with config files and language constructs.

@gilescope gilescope 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.

Looks good but let's eat our own dogfood and use earth to run the commands for reproducibility. If earth is slow used in this fashion we'll have good reason to speed it up.

- Add prek.toml with hooks for gofumpt (staged files only),
  golangci-lint (auto and manual --fix), and shellcheck.
- Add .mise.toml entries for prek and gofumpt so hooks resolve
  without a locally installed binary.
- Refactor Earthfile: split +lint into +lint-deps / +lint, add
  +lint-fix (saves corrected files back via SAVE ARTIFACT AS LOCAL),
  add +fmt-go with a --files ARG (defaults to ".") so the gofumpt
  hook can scope to staged files only, and add +lint-scripts that
  shellchecks every *.sh in the repo in its own directo
- Inline golangci-lint install logic into +lint-deps (removes
  scripts/golangci-lint.sh); fix install.sh branch from master to
  main so the checksum grep is anchored and verification succeeds.
- Fix +lint-fix SAVE ARTIFACT to mirror only the files +code copies,
  preventing silent deletion of non-Go files in the working tree.
- Expand shellcheck coverage from a curated subset to the whole repo;
  fix all 64 pre-existing findings across tests/, release/, examples/,
  and .github/scripts/ (SC2068 unquoted $@, SC2251 ! under set -e,
  SC2295 glob leakage in assert.sh, SC2086/SC2046 unquoted expansions,
  SC2044 for-over-find, SC3040 pipefail under /bin/sh, SC2059
  printf injection, and others).
- Apply gofumpt baseline formatting across 30 files to establish a
  clean prek run --all-files starting point.
@danielschlegel
danielschlegel force-pushed the feature/precommit-hooks branch from fd1e1cb to d371b5b Compare July 16, 2026 14:41
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