Skip to content

Commit 62a2647

Browse files
committed
refactor ci; add mockery
1 parent d7ee1b7 commit 62a2647

28 files changed

+5316
-66
lines changed

.github/workflows/go.yml renamed to .github/workflows/ci.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go
1+
name: CI
22

33
on:
44
push:
@@ -40,21 +40,27 @@ jobs:
4040
restore-keys: |
4141
ci-tools-${{ runner.os }}-${{ runner.arch }}
4242
43-
- name: go mod verify
44-
run: go mod verify
45-
46-
- name: version of make
47-
run: make --version
48-
49-
- name: env
50-
run: make env
51-
5243
- name: Install Tools
5344
if: steps.cache-tools.outputs.cache-hit != 'true'
5445
run: make tools
5546

56-
- name: Checks
57-
run: make checks
47+
- name: env
48+
run: |
49+
make --version
50+
echo ''
51+
make env
52+
53+
- name: ci-gen-n-format
54+
run: make ci-gen-n-format
55+
56+
- name: ci-mod
57+
run: make ci-mod
58+
59+
- name: staticcheck
60+
run: make staticcheck
61+
62+
- name: golangci-lint
63+
run: make golangci-lint-github-actions
5864

5965
- name: Build
6066
run: make build

.mockery.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://vektra.github.io/mockery/latest/configuration/
2+
3+
packages:
4+
github.com/moukoublen/goboilerplate:
5+
config:
6+
all: true
7+
recursive: true
8+
exclude: [vendor]
9+
with-expecter: true
10+
filename: mock_{{ .InterfaceName | snakecase }}_test.go
11+
mockname: Mock{{ .InterfaceName | firstUpper }}
12+
dir: "{{ .InterfaceDir }}"
13+
#outpkg: "mocks"
14+
inpackage: true

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ checks: vet staticcheck gofumpt goimports golangci-lint-github-actions
166166
.PHONY: run
167167
run: $(TOOLS_BIN)/gojq
168168
$(GO_EXEC) run -mod=vendor ./cmd/goboilerplate | $(TOOLS_BIN)/gojq
169+
170+
.PHONY: ci-format
171+
ci-format: goimports gofumpt
172+
./scripts/git-check-dirty
173+
174+
.PHONY: ci-mod
175+
ci-mod: mod
176+
./scripts/git-check-dirty

doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package goboilerplate

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2727
github.com/pkg/errors v0.9.1 // indirect
2828
github.com/pmezard/go-difflib v1.0.0 // indirect
29+
github.com/stretchr/objx v0.5.2 // indirect
2930
golang.org/x/sys v0.25.0 // indirect
3031
gopkg.in/yaml.v3 v3.0.1 // indirect
3132
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4545
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
4646
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
4747
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
48+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
49+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
4850
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4951
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
5052
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/httpx/mock_inner_client_test.go

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mock_daemon_config_option_test.go

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/git-check-dirty

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
# https://git-scm.com/docs/git-status
6+
7+
if [ -n "$(git status --porcelain)" ]; then
8+
echo "new or modified files"
9+
echo ""
10+
11+
git status --short --branch --untracked-files=all --ahead-behind
12+
exit 1
13+
fi

scripts/tools.mk

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,11 @@ $(TOOLS_BIN)/goimports: $(TOOLS_DB)/goimports.$(GOIMPORTS_VER).$(GO_VER).ver
8282

8383
.PHONY: goimports
8484
goimports: $(TOOLS_BIN)/goimports
85-
@echo '$(TOOLS_BIN)/goimports -l `$(GO_FILES)`'
86-
@if [[ -n "$$($(TOOLS_BIN)/goimports -l `$(GO_FILES)` | tee /dev/stderr)" ]]; then \
87-
echo 'goimports errors'; \
88-
echo ''; \
89-
echo -e "\e[0;34m→\e[0m To display the needed changes run:"; \
90-
echo ' make goimports.display'; \
91-
echo ''; \
92-
echo -e "\e[0;34m→\e[0m To fix them run:"; \
93-
echo ' make goimports.fix'; \
94-
echo ''; \
95-
exit 1; \
96-
fi
97-
@echo ''
85+
$(TOOLS_BIN)/goimports -w `$(GO_FILES)`
9886

9987
.PHONY: goimports.display
10088
goimports.display: $(TOOLS_BIN)/goimports
101-
$(TOOLS_BIN)/goimports -d `$(GO_FOLDERS)`
102-
103-
.PHONY: goimports.fix
104-
goimports.fix: $(TOOLS_BIN)/goimports
105-
$(TOOLS_BIN)/goimports -w `$(GO_FOLDERS)`
89+
$(TOOLS_BIN)/goimports -d `$(GO_FILES)`
10690
## </goimports>
10791

10892
## <gofumpt>
@@ -114,53 +98,21 @@ $(TOOLS_BIN)/gofumpt: $(TOOLS_DB)/gofumpt.$(GOFUMPT_VER).$(GO_VER).ver
11498

11599
.PHONY: gofumpt
116100
gofumpt: $(TOOLS_BIN)/gofumpt
117-
@echo '$(TOOLS_BIN)/gofumpt -l `$(GO_FOLDERS)`'
118-
@if [[ -n "$$($(TOOLS_BIN)/gofumpt -l `$(GO_FOLDERS)` | tee /dev/stderr)" ]]; then \
119-
echo 'gofumpt errors'; \
120-
echo ''; \
121-
echo -e "\e[0;34m→\e[0m To display the needed changes run:"; \
122-
echo ' make gofumpt.display'; \
123-
echo ''; \
124-
echo -e "\e[0;34m→\e[0m To fix them run:"; \
125-
echo ' make gofumpt.fix'; \
126-
echo ''; \
127-
exit 1; \
128-
fi
129-
@echo ''
101+
$(TOOLS_BIN)/gofumpt -w `$(GO_FILES)`
130102

131103
.PHONY: gofumpt.display
132104
gofumpt.display:
133-
$(TOOLS_BIN)/gofumpt -d `$(GO_FOLDERS)`
134-
135-
.PHONY: gofumpt.fix
136-
gofumpt.fix:
137-
$(TOOLS_BIN)/gofumpt -w `$(GO_FOLDERS)`
105+
$(TOOLS_BIN)/gofumpt -d `$(GO_FILES)`
138106
## </gofumpt>
139107

140108
## <gofmt>
141109
.PHONY: gofmt
142110
gofmt:
143-
@echo 'gofmt -l `$(GO_FOLDERS)`'
144-
@if [[ -n "$$(gofmt -l `$(GO_FOLDERS)` | tee /dev/stderr)" ]]; then \
145-
echo 'gofmt errors'; \
146-
echo ''; \
147-
echo -e "\e[0;34m→\e[0m To display the needed changes run:"; \
148-
echo ' make gofmt.display'; \
149-
echo ''; \
150-
echo -e "\e[0;34m→\e[0m To fix them run:"; \
151-
echo ' make gofmt.fix'; \
152-
echo ''; \
153-
exit 1; \
154-
fi
155-
@echo ''
111+
gofmt -w `$(GO_FILES)`
156112

157113
.PHONY: gofmt.display
158114
gofmt.display:
159-
gofmt -d `$(GO_FOLDERS)`
160-
161-
.PHONY: gofmt.fix
162-
gofmt.fix:
163-
gofmt -w `$(GO_FOLDERS)`
115+
gofmt -d `$(GO_FILES)`
164116
## </gofmt>
165117

166118
## <gojq>
@@ -186,6 +138,19 @@ air: $(TOOLS_BIN)/air
186138
@exec $(TOOLS_BIN)/air -c .air.toml
187139
## </air>
188140

141+
## <mockery>
142+
# https://github.com/vektra/mockery/releases
143+
MOCKERY_CMD:=github.com/vektra/mockery/v2
144+
MOCKERY_VER:=v2.45.1
145+
$(TOOLS_BIN)/mockery: $(TOOLS_DB)/mockery.$(MOCKERY_VER).$(GO_VER).ver
146+
$(call go_install,air,$(MOCKERY_CMD),$(MOCKERY_VER))
147+
148+
.PHONY: mockery
149+
mockery: $(TOOLS_BIN)/mockery
150+
grep --recursive --files-with-matches '// Code generated by mockery' . | grep -v 'scripts/tools.mk' | grep -v 'bin/mockery' | xargs rm || true
151+
mockery --config=.mockery.yml
152+
## </mockery>
153+
189154
## <protobuf>
190155
# https://github.com/protocolbuffers/protobuf/releases
191156
PROTOC_VER:=v27.3

0 commit comments

Comments
 (0)