Skip to content

Commit 3526902

Browse files
committed
export tools to module to update the version from dependabot
1 parent 61faf86 commit 3526902

File tree

10 files changed

+1457
-83
lines changed

10 files changed

+1457
-83
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ on:
1010
jobs:
1111

1212
ci:
13+
name: Lints and Tests
1314
runs-on: ubuntu-latest
15+
# strategy:
16+
# matrix:
17+
# go-version: [ '1.22', '1.23' ]
1418
steps:
15-
- uses: actions/checkout@v4
1619

17-
# - uses: streetsidesoftware/cspell-action@v6
18-
# with:
19-
# root: '.'
20-
# inline: warning
21-
# strict: true
22-
# incremental_files_only: false
23-
# config: '.vscode/cspell.json'
24-
# verbose: false
20+
# https://github.com/actions/checkout
21+
- uses: actions/checkout@v4
2522

23+
# https://github.com/actions/setup-go
2624
- name: Set up Go
2725
uses: actions/setup-go@v5
2826
with:
29-
go-version: '1.23'
27+
go-version: "1.23.x"
28+
check-latest: true
3029
cache: false
3130

31+
# https://github.com/actions/cache
3232
- name: Cache Tools
3333
id: cache-tools
3434
uses: actions/cache@v4
@@ -37,37 +37,34 @@ jobs:
3737
.tools/
3838
~/.cache/go-build/
3939
~/go/pkg/
40-
key: ci-tools-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum', '**/Makefile', 'scripts/tools.mk', '.github/workflows/go.yml') }}
40+
key: ci-tools-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.mod', '**/go.sum', '**/Makefile', 'scripts/tools.mk', '.github/workflows/ci.yml', 'tools/tools.go') }}
4141
restore-keys: |
4242
ci-tools-${{ runner.os }}-${{ runner.arch }}
4343
4444
- name: Install Tools
4545
if: steps.cache-tools.outputs.cache-hit != 'true'
4646
run: make tools
4747

48-
- name: env
48+
- name: Env
4949
run: |
5050
make --version
51-
echo ''
51+
echo ""
5252
make env
5353
54-
- name: Check shell files
54+
- name: Check Shell Files
5555
run: make ci-sh
5656

57-
- name: ci-gen-n-format
58-
run: make ci-gen-n-format
59-
60-
- name: ci-mod
57+
- name: Mod
6158
run: make ci-mod
6259

60+
- name: Generate Format and Check
61+
run: make ci-gen-n-format
62+
6363
- name: staticcheck
6464
run: make staticcheck
6565

6666
- name: golangci-lint
67-
run: make golangci-lint-github-actions
68-
69-
- name: Build
70-
run: make build
67+
run: make golangci-lint
7168

7269
- name: Test
7370
run: make test

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ output:
1818
path: stderr
1919
print-issued-lines: true
2020
print-linter-name: true
21-
uniq-by-line: true
2221

2322
linters:
2423
enable-all: true

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ env:
5555
@echo ""
5656

5757
.PHONY: checks
58-
checks: vet staticcheck gofumpt goimports golangci-lint-github-actions
58+
checks: vet staticcheck gofumpt goimports golangci-lint
5959

6060
.PHONY: ci-gen-n-format
61-
ci-gen-n-format: goimports gofumpt
61+
ci-gen-n-format: mockery goimports gofumpt
6262
./scripts/git-check-dirty
6363

6464
.PHONY: ci-mod

internal/httpx/mock_http_client_test.go

Lines changed: 1 addition & 1 deletion
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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/go.mk

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
REPO_GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || true)
2-
REPO_GIT_COMMIT = $(shell git rev-parse HEAD 2>/dev/null || true)
3-
REPO_GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD 2>/dev/null || true)
4-
REPO_GIT_TAG = $(shell git describe --tags 2>/dev/null || true)
5-
61
MODULE := $(shell cat go.mod | grep -e "^module" | sed "s/^module //")
7-
X_FLAGS = \
8-
-X '$(MODULE)/build.Branch=$(REPO_GIT_BRANCH)' \
9-
-X '$(MODULE)/build.Commit=$(REPO_GIT_COMMIT)' \
10-
-X '$(MODULE)/build.CommitShort=$(REPO_GIT_COMMIT_SHORT)' \
11-
-X '$(MODULE)/build.Tag=$(REPO_GIT_TAG)'
122

133
GO_PACKAGES = go list -tags='$(TAGS)' ./...
144
GO_FOLDERS = go list -tags='$(TAGS)' -f '{{ .Dir }}' ./...
@@ -58,11 +48,19 @@ build: $(shell ls -d cmd/* | sed -e 's/\//./')
5848
clean:
5949
rm -rf $(BUILD_OUTPUT)
6050

51+
# https://pkg.go.dev/cmd/go/internal/test
6152
.PHONY: test
6253
test:
63-
CGO_ENABLED=1 go test -timeout 60s -race -tags="$(TAGS)" -coverprofile cover.out -covermode atomic ./...
64-
@go tool cover -func cover.out
65-
@rm cover.out
54+
CGO_ENABLED=1 go test -timeout 30s -tags '$(TAGS)' -race -coverprofile=coverage.txt -covermode=atomic ./...
55+
56+
.PHONY: test-n-read
57+
test-n-read: test
58+
@go tool cover -func coverage.txt
59+
60+
.PHONY: bench
61+
bench: # runs all benchmarks
62+
CGO_ENABLED=1 go test -benchmem -run=^Benchmark$$ -mod=readonly -count=1 -v -race -bench=. ./...
63+
6664

6765
.PHONY: run
6866
run:

scripts/tools.mk

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
## https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
2-
## in order for
3-
#.SECONDEXPANSION:
4-
5-
## https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-not-intermediate-targets_002c-explicit
6-
## NOTINTERMEDIATE requires make >=4.4
7-
.NOTINTERMEDIATE:
8-
91
# https://www.gnu.org/software/make/manual/make.html#Automatic-Variables
102
# https://www.gnu.org/software/make/manual/make.html#Prerequisite-Types
113

@@ -21,7 +13,9 @@ tools: \
2113
$(TOOLS_BIN)/staticcheck \
2214
$(TOOLS_BIN)/golangci-lint \
2315
$(TOOLS_BIN)/gofumpt \
24-
$(TOOLS_BIN)/gojq
16+
$(TOOLS_BIN)/gojq \
17+
$(TOOLS_BIN)/shfmt \
18+
$(TOOLS_BIN)/shellcheck
2519

2620
.PHONY: clean-tools
2721
clean-tools:
@@ -45,17 +39,24 @@ define go_install
4539
@echo ""
4640
endef
4741

42+
# export GOMOD=$(shell pwd)/go_tools.mod
43+
# go get -modfile='go_tools.mod' -u ...
44+
define go_mod_ver
45+
$(shell go list -modfile='./tools/go.mod' -m $(1) | cut -d ' ' -f2)
46+
endef
47+
48+
4849
.PHONY: vet
4950
vet:
5051
go vet `$(GO_PACKAGES)`
5152
@echo ""
5253

5354
## <staticcheck>
5455
# https://github.com/dominikh/go-tools/releases https://staticcheck.io/c
55-
STATICCHECK_CMD:=honnef.co/go/tools/cmd/staticcheck
56-
STATICCHECK_VER:=2024.1.1
56+
STATICCHECK_MOD:=honnef.co/go/tools
57+
STATICCHECK_VER:=$(call go_mod_ver,$(STATICCHECK_MOD))
5758
$(TOOLS_BIN)/staticcheck: $(TOOLS_DB)/staticcheck.$(STATICCHECK_VER).$(GO_VER).ver
58-
$(call go_install,staticcheck,$(STATICCHECK_CMD),$(STATICCHECK_VER))
59+
$(call go_install,staticcheck,$(STATICCHECK_MOD)/cmd/staticcheck,$(STATICCHECK_VER))
5960

6061
.PHONY: staticcheck
6162
staticcheck: $(TOOLS_BIN)/staticcheck
@@ -65,52 +66,47 @@ staticcheck: $(TOOLS_BIN)/staticcheck
6566

6667
## <golangci-lint>
6768
# https://github.com/golangci/golangci-lint/releases
68-
GOLANGCI-LINT_CMD:=github.com/golangci/golangci-lint/cmd/golangci-lint
69-
GOLANGCI-LINT_VER:=v1.63.4
69+
GOLANGCI-LINT_MOD:=github.com/golangci/golangci-lint
70+
GOLANGCI-LINT_VER:=$(call go_mod_ver,$(GOLANGCI-LINT_MOD))
7071
$(TOOLS_BIN)/golangci-lint: $(TOOLS_DB)/golangci-lint.$(GOLANGCI-LINT_VER).$(GO_VER).ver
7172
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI-LINT_VER)
7273

7374
.PHONY: golangci-lint
7475
golangci-lint: $(TOOLS_BIN)/golangci-lint
75-
$(TOOLS_BIN)/golangci-lint run
76-
@echo ''
77-
78-
.PHONY: golangci-lint-github-actions
79-
golangci-lint-github-actions: $(TOOLS_BIN)/golangci-lint
8076
golangci-lint run --out-format colored-line-number
8177
@echo ''
8278
## </golangci-lint>
8379

8480
## <goimports>
8581
# https://pkg.go.dev/golang.org/x/tools?tab=versions
86-
GOIMPORTS_CMD := golang.org/x/tools/cmd/goimports
87-
GOIMPORTS_VER := v0.28.0
82+
GOIMPORTS_MOD:=golang.org/x/tools
83+
GOIMPORTS_VER:=$(call go_mod_ver,$(GOIMPORTS_MOD))
8884
$(TOOLS_BIN)/goimports: $(TOOLS_DB)/goimports.$(GOIMPORTS_VER).$(GO_VER).ver
89-
$(call go_install,goimports,$(GOIMPORTS_CMD),$(GOIMPORTS_VER))
85+
$(call go_install,goimports,$(GOIMPORTS_MOD)/cmd/goimports,$(GOIMPORTS_VER))
9086

9187
.PHONY: goimports
9288
goimports: $(TOOLS_BIN)/goimports
93-
$(TOOLS_BIN)/goimports -w `$(GO_FILES)`
89+
goimports -w `$(GO_FILES)`
9490

9591
.PHONY: goimports.display
9692
goimports.display: $(TOOLS_BIN)/goimports
97-
$(TOOLS_BIN)/goimports -d `$(GO_FILES)`
93+
goimports -d `$(GO_FILES)`
9894
## </goimports>
9995

10096
## <gofumpt>
10197
# https://github.com/mvdan/gofumpt/releases
102-
GOFUMPT_CMD:=mvdan.cc/gofumpt
103-
GOFUMPT_VER:=v0.7.0
98+
GOFUMPT_MOD:=mvdan.cc/gofumpt
99+
GOFUMPT_VER:=$(call go_mod_ver,$(GOFUMPT_MOD))
104100
$(TOOLS_BIN)/gofumpt: $(TOOLS_DB)/gofumpt.$(GOFUMPT_VER).$(GO_VER).ver
105-
$(call go_install,gofumpt,$(GOFUMPT_CMD),$(GOFUMPT_VER))
101+
$(call go_install,gofumpt,$(GOFUMPT_MOD),$(GOFUMPT_VER))
106102

107103
.PHONY: gofumpt
108104
gofumpt: $(TOOLS_BIN)/gofumpt
109-
$(TOOLS_BIN)/gofumpt -w `$(GO_FILES)`
105+
gofumpt -w `$(GO_FILES)`
110106

111107
.PHONY: gofumpt.display
112108
gofumpt.display:
113-
$(TOOLS_BIN)/gofumpt -d `$(GO_FILES)`
109+
gofumpt -d `$(GO_FILES)`
114110
## </gofumpt>
115111

116112
## <gofmt>
@@ -125,21 +121,21 @@ gofmt.display:
125121

126122
## <gojq>
127123
# https://github.com/itchyny/gojq/releases
128-
GOJQ_CMD := github.com/itchyny/gojq/cmd/gojq
129-
GOJQ_VER := v0.12.17
124+
GOJQ_MOD:=github.com/itchyny/gojq
125+
GOJQ_VER:=$(call go_mod_ver,$(GOJQ_MOD))
130126
$(TOOLS_BIN)/gojq: $(TOOLS_DB)/gojq.$(GOJQ_VER).$(GO_VER).ver
131-
$(call go_install,gojq,$(GOJQ_CMD),$(GOJQ_VER))
127+
$(call go_install,gojq,$(GOJQ_MOD)/cmd/gojq,$(GOJQ_VER))
132128

133129
.PHONY: gojq
134130
gojq: $(TOOLS_BIN)/gojq
135131
## </gojq>
136132

137133
## <air>
138134
# https://github.com/air-verse/air/releases
139-
AIR_CMD:=github.com/air-verse/air
140-
AIR_VER:=v1.61.5
135+
AIR_MOD:=github.com/air-verse/air
136+
AIR_VER:=$(call go_mod_ver,$(AIR_MOD))
141137
$(TOOLS_BIN)/air: $(TOOLS_DB)/air.$(AIR_VER).$(GO_VER).ver
142-
$(call go_install,air,$(AIR_CMD),$(AIR_VER))
138+
$(call go_install,air,$(AIR_MOD),$(AIR_VER))
143139

144140
.PHONY: air
145141
air: $(TOOLS_BIN)/air
@@ -148,10 +144,10 @@ air: $(TOOLS_BIN)/air
148144

149145
## <mockery>
150146
# https://github.com/vektra/mockery/releases
151-
MOCKERY_CMD:=github.com/vektra/mockery/v2
152-
MOCKERY_VER:=v2.50.2
147+
MOCKERY_MOD:=github.com/vektra/mockery/v2
148+
MOCKERY_VER:=$(call go_mod_ver,$(MOCKERY_MOD))
153149
$(TOOLS_BIN)/mockery: $(TOOLS_DB)/mockery.$(MOCKERY_VER).$(GO_VER).ver
154-
$(call go_install,air,$(MOCKERY_CMD),$(MOCKERY_VER))
150+
$(call go_install,air,$(MOCKERY_MOD),$(MOCKERY_VER))
155151

156152
.PHONY: mockery
157153
mockery: $(TOOLS_BIN)/mockery
@@ -179,14 +175,19 @@ proto: $(TOOLS_BIN)/protoc $(TOOLS_BIN)/protoc-gen-go
179175

180176
## <shfmt>
181177
# https://github.com/mvdan/sh/releases
182-
SHFMT_CMD := mvdan.cc/sh/v3/cmd/shfmt
183-
SHFMT_VER := v3.10.0
178+
SHFMT_MOD:=mvdan.cc/sh/v3
179+
SHFMT_VER:=$(call go_mod_ver,$(SHFMT_MOD))
184180
$(TOOLS_BIN)/shfmt: $(TOOLS_DB)/shfmt.$(SHFMT_VER).$(GO_VER).ver
185-
$(call go_install,shfmt,$(SHFMT_CMD),$(SHFMT_VER))
181+
$(call go_install,shfmt,$(SHFMT_MOD)/cmd/shfmt,$(SHFMT_VER))
186182

187183
.PHONY: shfmt
188184
shfmt: $(TOOLS_BIN)/shfmt
189-
@./scripts/foreach-script $(TOOLS_BIN)/shfmt --simplify --language-dialect auto --case-indent --indent 2 --write
185+
./scripts/foreach-script $(TOOLS_BIN)/shfmt \
186+
--simplify \
187+
--language-dialect auto \
188+
--case-indent \
189+
--indent 2 \
190+
--write
190191
## </shfmt>
191192

192193
## <shellcheck>
@@ -197,5 +198,9 @@ $(TOOLS_BIN)/shellcheck: $(TOOLS_DB)/shellcheck.$(SHELLCHECK_VER).ver | $(TOOLS_
197198

198199
.PHONY: shellcheck
199200
shellcheck: $(TOOLS_BIN)/shellcheck
200-
@./scripts/foreach-script $(TOOLS_BIN)/shellcheck --external-sources --format=tty --severity=info
201+
./scripts/foreach-script $(TOOLS_BIN)/shellcheck \
202+
--norc \
203+
--external-sources \
204+
--format=tty \
205+
--enable=require-variable-braces,add-default-case
201206
## </shellcheck>

0 commit comments

Comments
 (0)