Skip to content

Commit

Permalink
ci: add more check rules to Makefile and github action (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsong authored Jun 20, 2023
2 parents 61747ed + 087dd07 commit 2f17caf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 34 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ PKGS := $(shell $(GO) list ./... | \

ifneq ($(shell echo $$OSTYPE | egrep "darwin"),)
export CGO_CFLAGS=-Wno-undef-prefix
export MallocNanoZone=0
endif

PYTHON := python3

.DEFAULT_GOAL := all
.PHONY: all
all: generate precommit build
all: precommit


# precommit
.PHONY: precommit precommit_lint
precommit: fmt tidy vet test test_py
precommit_lint: fmt tidy vet lint test test_py
.PHONY: precommit
precommit: mod-tidy mod-vendor proto generate fmt vet lint build test test_py


# build
Expand Down Expand Up @@ -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)
Expand All @@ -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);)
Expand All @@ -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
Expand Down

0 comments on commit 2f17caf

Please sign in to comment.