Skip to content

Feature/precommit hooks#517

Draft
danielschlegel wants to merge 2 commits into
mainfrom
feature/precommit-hooks
Draft

Feature/precommit hooks#517
danielschlegel wants to merge 2 commits into
mainfrom
feature/precommit-hooks

Conversation

@danielschlegel
Copy link
Copy Markdown
Collaborator

@danielschlegel danielschlegel commented May 27, 2026

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
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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
echo "looking up branch $BUILDKIT_GIT_BRANCH"; \
buildkit_sha1=$(git ls-remote --refs -q https://github.com/$BUILDKIT_GIT_ORG/buildkit.git "$BUILDKIT_GIT_BRANCH" | awk 'BEGIN { FS = "[ \t]+" } {print $1}'); \
echo "pinning github.com/earthly/buildkit@${BUILDKIT_BRANCH} to reference git sha1: $buildkit_sha1"; \
echo "pinning github.com/${BUILDKIT_GIT_ORG}/buildkit@${BUILDKIT_BRANCH} to reference git sha1: $buildkit_sha1"; \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The variable ${BUILDKIT_BRANCH} is used here, but the argument defined at the top of the target is BUILDKIT_GIT_BRANCH. This will result in an empty string being printed for the branch name. Please use ${BUILDKIT_GIT_BRANCH} instead.

            echo "pinning github.com/${BUILDKIT_GIT_ORG}/buildkit@${BUILDKIT_GIT_BRANCH} to reference git sha1: $buildkit_sha1"; \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot fix

@danielschlegel
Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Comment thread prek.toml Outdated
id = "golangci-lint-fix"
name = "golangci-lint (auto-fix)"
language = "system"
entry = "golangci-lint run --fix"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should be running the earth targets for this otherwise you're picking up whatever version of lint is installed on your box.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@gilescope I agree but I thought git hooks need to be as fast as possible. Another solution would be to move it to a shell script which is used in hooks and also Earthfile +lint target.

@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?

BUILDKIT_BRANCH was referenced but only BUILDKIT_GIT_BRANCH was defined,
causing an empty string to be printed. Also uses BUILDKIT_GIT_ORG instead
of the hardcoded 'earthly' org.
@danielschlegel danielschlegel force-pushed the feature/precommit-hooks branch from a9634ba to 9ef9821 Compare June 4, 2026 11:36
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

➖ Are we earthbuild yet?

No change in "earthly" occurrences

📈 Overall Progress

Branch Total Count
main 5317
This PR 5317
Difference +0

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.

@danielschlegel danielschlegel force-pushed the feature/precommit-hooks branch from 9ef9821 to b26d605 Compare June 4, 2026 11:40
- Add prek.toml with hooks for gofumpt, golangci-lint (auto), golangci-lint
  --fix (manual only), and shellcheck.
- Add scripts/golangci-lint.sh as the single source of truth for the pinned
  golangci-lint version; used by both prek hooks and the Earthfile.
- Refactor +lint into +lint-deps (shared setup) and +lint targets.
- Add +lint-fix target that runs golangci-lint --fix and saves corrected
  files back to the working tree via SAVE ARTIFACT ... AS LOCAL.
@danielschlegel danielschlegel force-pushed the feature/precommit-hooks branch from b26d605 to 9cb24c5 Compare June 4, 2026 11:43
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