Skip to content

Commit 6434199

Browse files
authored
chore(Makefile): ensure that make fmt/go only formats go source files (#15971)
An unfortunate branch name resulted in failures when running `make fmt/go` and consequently `make fmt`. fmt should not be run on the .git directory. This PR excludes `.git` and anything else that's not a go source file in the currently checked out branch from the consideration of `make fmt/go`.
1 parent 8befb34 commit 6434199

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,14 @@ RESET := $(shell tput sgr0 2>/dev/null)
417417
fmt: fmt/ts fmt/go fmt/terraform fmt/shfmt fmt/prettier
418418
.PHONY: fmt
419419

420+
GO_FMT_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -exec sh -c 'grep -L "DO NOT EDIT" "{}" 2>/dev/null || true' \;)
421+
420422
fmt/go:
421423
go mod tidy
422424
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/go$(RESET)"
423425
# VS Code users should check out
424426
# https://github.com/mvdan/gofumpt#visual-studio-code
425-
go run mvdan.cc/gofumpt@v0.4.0 -w -l .
427+
go run mvdan.cc/gofumpt@v0.4.0 -w -l $(GO_FMT_FILES)
426428
.PHONY: fmt/go
427429

428430
fmt/ts:
@@ -511,9 +513,7 @@ TAILNETTEST_MOCKS := \
511513
tailnet/tailnettest/workspaceupdatesprovidermock.go \
512514
tailnet/tailnettest/subscriptionmock.go
513515

514-
515-
# all gen targets should be added here and to gen/mark-fresh
516-
gen: \
516+
GEN_FILES := \
517517
tailnet/proto/tailnet.pb.go \
518518
agent/proto/agent.pb.go \
519519
provisionersdk/proto/provisioner.pb.go \
@@ -538,6 +538,9 @@ gen: \
538538
examples/examples.gen.json \
539539
$(TAILNETTEST_MOCKS) \
540540
coderd/database/pubsub/psmock/psmock.go
541+
542+
# all gen targets should be added here and to gen/mark-fresh
543+
gen: $(GEN_FILES)
541544
.PHONY: gen
542545

543546
# Mark all generated files as fresh so make thinks they're up-to-date. This is

0 commit comments

Comments
 (0)