Skip to content

Commit ea6c6ec

Browse files
committed
chore: simplify build process and add linting target
Signed-off-by: tbxark <tbxark@outlook.com>
1 parent 592cc02 commit ea6c6ec

File tree

2 files changed

+9
-94
lines changed

2 files changed

+9
-94
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ jobs:
1717
uses: actions/setup-go@v5
1818
with:
1919
go-version: '>=1.24'
20-
- name: Build
21-
run: make install && cd layout && IGNORE_INSTALL_SPHERE_TOOLS=1 make init && make build && cd -
2220
- name: Test
23-
run: make test
21+
run: go test -v ./...

Makefile

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,10 @@
1-
SPHERE_CLI ?= sphere-cli
2-
NILAWAY_CLI ?= nilaway
3-
GOLANG_CI_LINT ?= golangci-lint
4-
51
MODULE := $(shell go list -m)
62

7-
MODULES := . \
8-
proto/binding \
9-
proto/errors \
10-
proto/options \
11-
cmd/protoc-gen-route \
12-
cmd/protoc-gen-sphere \
13-
cmd/protoc-gen-sphere-binding \
14-
cmd/protoc-gen-sphere-errors \
15-
cmd/sphere-cli \
16-
layout
17-
18-
COMMANDS := cmd/protoc-gen-route \
19-
cmd/protoc-gen-sphere \
20-
cmd/protoc-gen-sphere-binding \
21-
cmd/protoc-gen-sphere-errors \
22-
cmd/sphere-cli
23-
24-
define install_mod
25-
echo "install $1" && ( \
26-
cd $1 && \
27-
go mod tidy && \
28-
go install ./... \
29-
)
30-
endef
31-
32-
define fmt_mod
33-
echo "fmt $1" && ( \
34-
cd $1 && \
35-
go mod tidy && \
36-
go fmt ./... && \
37-
$(GOLANG_CI_LINT) fmt --no-config --enable gofmt,goimports && \
38-
$(GOLANG_CI_LINT) run --no-config --fix \
39-
)
40-
endef
41-
42-
define upgrade_mod
43-
echo "upgrade $1" && ( \
44-
cd $1 && \
45-
go get -u ./... && \
46-
go mod tidy \
47-
)
48-
endef
49-
50-
define test_mod
51-
echo "test $1" && ( \
52-
cd $1 && \
53-
go test -v ./... \
54-
)
55-
endef
56-
57-
define nil_check
58-
echo "nilaway check $1" && ( \
59-
cd $1 && \
60-
$(NILAWAY_CLI) -include-pkgs="$(MODULE)" ./... || true \
61-
)
62-
endef
63-
64-
.PHONY: install
65-
install: ## Install all dependencies
66-
@$(foreach mod,$(COMMANDS),$(call install_mod,$(mod)) && ) true
67-
68-
.PHONY: fmt
69-
fmt: ## Format code
70-
@$(foreach mod,$(MODULES),$(call fmt_mod,$(mod)) && ) true
71-
72-
.PHONY: upgrade
73-
upgrade: ## Upgrade dependencies
74-
@$(foreach mod,$(MODULES),$(call upgrade_mod,$(mod)) && ) true
75-
76-
.PHONY: test
77-
test: ## Run tests
78-
@$(foreach mod,$(MODULES),$(call test_mod,$(mod)) && ) true
79-
80-
.PHONY: nilaway
81-
nilaway: ## Run nilaway checks
82-
@$(foreach mod,$(MODULES),$(call nil_check,$(mod)) && ) true
83-
84-
.PHONY: cli/service/test
85-
cli/service/test: ## Test sphere-cli service generation
86-
$(SPHERE_CLI) service golang --name KeyValueStore &> layout/internal/service/dash/keyvaluestore.go
87-
$(SPHERE_CLI) service proto --name KeyValueStore &> layout/proto/dash/v1/keyvaluestore.proto
88-
cd layout && make gen/all && make build
89-
90-
.PHONY: hook/before/commit
91-
hook/before/commit: install fmt cli/service/test ## Run before commit hook
92-
cd layout && IGNORE_INSTALL_SPHERE_TOOLS=1 make install && make build
93-
3+
.PHONY: lint
4+
lint:
5+
go mod tidy
6+
go fmt ./...
7+
go test ./...
8+
golangci-lint fmt --no-config --enable gofmt,goimports
9+
golangci-lint run --no-config --fix
10+
nilaway -include-pkgs="$(MODULE)" ./...

0 commit comments

Comments
 (0)