From 8d93efab11aec8cdb318d474882a6445dbf14517 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 22 Aug 2019 20:16:51 +0200 Subject: [PATCH] Run `go generate` during `make` and make sure that generated files are 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). --- Makefile | 20 ++++++++++++++++--- .../exporter/observer/eventtype_string.go | 19 +++--------------- tools.go | 1 + 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 6e98120222e..487d4abeb04 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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: @@ -43,4 +57,4 @@ all-pkgs: @echo $(ALL_PKGS) | tr ' ' '\n' | sort all-docs: - @echo $(ALL_DOCS) | tr ' ' '\n' | sort \ No newline at end of file + @echo $(ALL_DOCS) | tr ' ' '\n' | sort diff --git a/experimental/streaming/exporter/observer/eventtype_string.go b/experimental/streaming/exporter/observer/eventtype_string.go index 2cb7fa713ad..35d00d64c17 100644 --- a/experimental/streaming/exporter/observer/eventtype_string.go +++ b/experimental/streaming/exporter/observer/eventtype_string.go @@ -1,17 +1,3 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - // Code generated by "stringer -type=EventType"; DO NOT EDIT. package observer @@ -32,11 +18,12 @@ func _() { _ = x[NEW_METRIC-7] _ = x[MODIFY_ATTR-8] _ = x[RECORD_STATS-9] + _ = x[SET_STATUS-10] } -const _EventType_name = "INVALIDSTART_SPANFINISH_SPANLOG_EVENTLOGF_EVENTNEW_SCOPENEW_MEASURENEW_METRICMODIFY_ATTRRECORD_STATS" +const _EventType_name = "INVALIDSTART_SPANFINISH_SPANADD_EVENTADD_EVENTFNEW_SCOPENEW_MEASURENEW_METRICMODIFY_ATTRRECORD_STATSSET_STATUS" -var _EventType_index = [...]uint8{0, 7, 17, 28, 37, 47, 56, 67, 77, 88, 100} +var _EventType_index = [...]uint8{0, 7, 17, 28, 37, 47, 56, 67, 77, 88, 100, 110} func (i EventType) String() string { if i < 0 || i >= EventType(len(_EventType_index)-1) { diff --git a/tools.go b/tools.go index 0e4e2518483..6c4e08c445e 100644 --- a/tools.go +++ b/tools.go @@ -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" )