From f1186d8e009c6d8ce912b8044ba7f0a089145fff Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 9 Sep 2026 18:33:21 +0000 Subject: [PATCH] tools/bump: reformat inside the lock bump gateFlake judges the formatting check right after the lock moves, but the fmt area runs last, so the new toolchain's formatting had not been applied yet and the flake area dropped itself every run. --- tools/bump/flake.go | 9 +++++++++ tools/bump/generate.go | 23 ++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/bump/flake.go b/tools/bump/flake.go index 5297ce39..04b63fba 100644 --- a/tools/bump/flake.go +++ b/tools/bump/flake.go @@ -88,6 +88,15 @@ func applyFlake(ctx context.Context, r *repo) (change, error) { return change{Empty: true}, nil } + // The lock decides which prettier, gofumpt and nixfmt the tree is judged + // by, so moving it can leave files no bump touched failing the formatting + // check. Reformatting belongs in this commit rather than a later one: the + // gate below judges this tree, and the cause is this change. + err = runFormatters(ctx, r) + if err != nil { + return change{}, err + } + detail := moved if tools, err := toolVersions(ctx, r); err == nil { //nolint:noinlineerr diff --git a/tools/bump/generate.go b/tools/bump/generate.go index a8bcb61f..55217a46 100644 --- a/tools/bump/generate.go +++ b/tools/bump/generate.go @@ -140,13 +140,7 @@ func gateGenerate(ctx context.Context, r *repo) error { // The first hook pass is expected to fail, because a hook that rewrites a file // reports failure. The second pass is the real verdict. func applyFormat(ctx context.Context, r *repo) (change, error) { - if _, err := r.nixRun(ctx, "make", "fmt"); err != nil { //nolint:noinlineerr - return change{}, err - } - - _, _ = r.nixRun(ctx, "prek", "run", "--all-files") - - if _, err := r.nixRun(ctx, "prek", "run", "--all-files"); err != nil { //nolint:noinlineerr + if err := runFormatters(ctx, r); err != nil { //nolint:noinlineerr return change{}, err } @@ -164,3 +158,18 @@ func applyFormat(ctx context.Context, r *repo) (change, error) { Detail: touched, }, nil } + +// runFormatters brings the tree up to whatever the current toolchain considers +// formatted. The first hook pass is expected to fail, because a hook that +// rewrites a file reports failure; the second pass is the verdict. +func runFormatters(ctx context.Context, r *repo) error { + if _, err := r.nixRun(ctx, "make", "fmt"); err != nil { //nolint:noinlineerr + return err + } + + _, _ = r.nixRun(ctx, "prek", "run", "--all-files") + + _, err := r.nixRun(ctx, "prek", "run", "--all-files") + + return err +}