From 3643f148df2851b813b0386eeb92e27082b93928 Mon Sep 17 00:00:00 2001
From: Injun Song <ijsong@gmail.com>
Date: Tue, 20 Jun 2023 12:01:11 +0900
Subject: [PATCH] ci: add more check rules to Makefile and github action

---
 .github/workflows/ci.yaml | 16 ++++++++++++++--
 Makefile                  | 38 ++++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index b4b19c76b..c199d5b4d 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -23,10 +23,22 @@ jobs:
         with:
           go-version: ${{ env.GO_VERSION }}
 
+      - name: Install tools
+        run: |
+          make tools
+
       - name: Check go mod
         run: |
-          go mod tidy
-          git diff --exit-code go.mod
+          make mod-tidy-check
+          make mod-vendor-check
+
+      - name: Check proto
+        run: |
+          make proto-check
+
+      - name: Check generate
+        run: |
+          make generate-check
 
   lint:
     runs-on: ubuntu-latest
diff --git a/Makefile b/Makefile
index 4b310fd7e..c40591cb9 100644
--- a/Makefile
+++ b/Makefile
@@ -22,8 +22,8 @@ all: generate precommit build
 
 # precommit
 .PHONY: precommit precommit_lint
-precommit: fmt tidy vet test test_py
-precommit_lint: fmt tidy vet lint test test_py
+precommit: fmt mod-tidy-check vet test test_py
+precommit_lint: fmt mod-tidy-check vet lint test test_py
 
 
 # build
@@ -91,7 +91,7 @@ PROTO_SRCS := $(shell find . -name "*.proto" -not -path "./vendor/*")
 PROTO_PBS := $(PROTO_SRCS:.proto=.pb.go)
 PROTO_INCS := -I$(GOPATH)/src -I$(CURDIR)/proto -I$(CURDIR)/vendor
 
-.PHONY: proto
+.PHONY: proto proto-check
 proto: $(PROTO_PBS)
 $(PROTO_PBS): $(PROTO_SRCS)
 	@echo $(PROTOC)
@@ -100,15 +100,30 @@ $(PROTO_PBS): $(PROTO_SRCS)
 		--gogo_out=plugins=grpc,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,paths=source_relative:. $$src ; \
 	done
 
+proto-check:
+	$(MAKE) proto
+	$(MAKE) fmt
+	git diff --exit-code $(PROTO_PBS)
+
 
 # go:generate
-.PHONY: generate
+.PHONY: generate generate-check
 generate:
 	$(GO) generate ./...
 
+generate-check:
+	$(MAKE) generate
+	$(MAKE) fmt
+	git diff --exit-code
+
 
 # tools: lint, fmt, vet
-.PHONY: fmt lint vet
+.PHONY: tools fmt lint vet mod-tidy mod-tidy-check mod-vendor mod-vendor-check
+tools:
+	$(GO) install golang.org/x/tools/cmd/goimports@latest
+	$(GO) install golang.org/x/lint/golint@latest
+	$(GO) install github.com/golang/mock/mockgen@v1.6.0
+
 fmt:
 	@echo goimports
 	@$(foreach path,$(PKGS),goimports -w -local $(shell $(GO) list -m) ./$(path);)
@@ -122,9 +137,20 @@ vet:
 	@echo govet
 	@$(foreach path,$(PKGS),$(GO) vet ./$(path);)
 
-tidy:
+mod-tidy:
 	$(GO) mod tidy
 
+mod-tidy-check:
+	$(MAKE) mod-tidy
+	git diff --exit-code go.mod
+
+mod-vendor:
+	$(GO) mod vendor
+
+mod-vendor-check:
+	$(MAKE) mod-vendor
+	git diff --exit-code vendor
+
 
 # cleanup
 .PHONY: clean clean_mock