Skip to content

Commit

Permalink
ci: add more check rules to Makefile and github action
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsong committed Jun 20, 2023
1 parent 7bf9bf9 commit 3643f14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 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
38 changes: 32 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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/[email protected]

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 3643f14

Please sign in to comment.