Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 80111c9

Browse files
committed
Makefile: Use 'git diff --exit-code' for the gofmt check
This makes fixing errors easier, because you can just commit/amend after a failed 'make gofmt'. The diff check failes the target if there are any changes (either from gofmt or otherwise), which is good for continuous integration testing and such. Splitting gofmt out into its own .PHONY rule makes it more obvious that the diff call is part of the check, and allows you to run the gofmt check without pulling in the other, unrelated 'check' tests. This also reduces our shell exposure. The read and [ bits looked ok to me, but this was the only place we called read in the Makefile, so I expect it was the source of [1]: 05:22:18 [1650506.967906] golang[6]: /bin/sh: 1: read: arg count which was part of the motivation for 132a381 (use bash for the makefile shell, 2018-01-29, #870). [1]: #870 (comment)
1 parent 0749dc0 commit 80111c9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ release: \
2727
check \
2828
_output/release/bootkube.tar.gz \
2929

30-
check:
31-
@gofmt -l -s $(GOFILES) | read; if [ $$? == 0 ]; then gofmt -s -d $(GOFILES); exit 1; fi
30+
check: gofmt
3231
ifdef TERRAFORM
3332
$(TERRAFORM) fmt -check ; if [ ! $$? -eq 0 ]; then exit 1; fi
3433
else
@@ -38,6 +37,10 @@ endif
3837
@./scripts/verify-gopkg.sh
3938
@go test -v $(shell go list ./... | grep -v '/vendor/\|/e2e')
4039

40+
gofmt:
41+
gofmt -s -w $(GOFILES)
42+
git diff --exit-code
43+
4144
install:
4245
go install -ldflags "$(LDFLAGS)" ./cmd/bootkube
4346

@@ -80,4 +83,4 @@ vendor:
8083
clean:
8184
rm -rf _output
8285

83-
.PHONY: all check clean install release vendor
86+
.PHONY: all check clean gofmt install release vendor

0 commit comments

Comments
 (0)