Skip to content

Commit

Permalink
Run go generate during make and make sure that generated files ar…
Browse files Browse the repository at this point in the history
…e in sync in CI (#101)

* Run go generate in the precommit target

So we should always get an updated version of a file generated by a
stringer utility.

* Update the generated file

* Make CI to fail if working tree has uncommited changes

The uncommitted changes may come from the golang linter (that formats
our code among other things) and from stringer (when updated some
enumeration).
  • Loading branch information
krnowak authored and rghetia committed Aug 22, 2019
1 parent 8e7e1fd commit 8d93efa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ $(TOOLS_DIR)/golangci-lint: go.mod go.sum tools.go
$(TOOLS_DIR)/misspell: go.mod go.sum tools.go
go build -o $(TOOLS_DIR)/misspell github.com/client9/misspell/cmd/misspell

precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell
$(TOOLS_DIR)/stringer: go.mod go.sum tools.go
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer

precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/stringer
PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...
$(TOOLS_DIR)/golangci-lint run --fix # TODO: Fix this on windows.
$(TOOLS_DIR)/misspell -w $(ALL_DOCS)

Expand All @@ -29,7 +33,17 @@ test-with-coverage:
go tool cover -html=coverage.txt -o coverage.html

.PHONY: circle-ci
circle-ci: precommit test-with-coverage test-386
circle-ci: precommit test-clean-work-tree test-with-coverage test-386

.PHONY: test-clean-work-tree
test-clean-work-tree:
@if ! git diff --quiet; then \
echo; \
echo "Working tree is not clean"; \
echo; \
git status; \
exit 1; \
fi

.PHONY: test
test:
Expand All @@ -43,4 +57,4 @@ all-pkgs:
@echo $(ALL_PKGS) | tr ' ' '\n' | sort

all-docs:
@echo $(ALL_DOCS) | tr ' ' '\n' | sort
@echo $(ALL_DOCS) | tr ' ' '\n' | sort
19 changes: 3 additions & 16 deletions experimental/streaming/exporter/observer/eventtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package tools
import (
_ "github.com/client9/misspell/cmd/misspell"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "golang.org/x/tools/cmd/stringer"
)

0 comments on commit 8d93efa

Please sign in to comment.