Skip to content

Commit 6c78559

Browse files
authored
Feat/1.add make doc-faster, 2.update pre-commit githooks (#1952)
* example readjust: tencentcloud_kubernetes_serverless_node_pool * add pre-commit-local add doc-faster * update makefile, pre-commit tmp. * adjust makefile * 1.update .go-version to 1.18.3, 2.use .go-version, 3.fix go version logic, 4.fix tools cmd in makefile.
1 parent 08d73e9 commit 6c78559

File tree

3 files changed

+57
-39
lines changed

3 files changed

+57
-39
lines changed

.githooks/pre-commit

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
#!/bin/sh
2-
printf "==> Step 1: Gofmt Check...\n"
3-
make fmtcheck
2+
REQUIRED_GO_VERSION=go$(cat .go-version) # use the .go-version
3+
4+
printf "==> Step 1: [Faster]Gofmt Check...\n"
5+
make fmt-faster
46
if [ $? -ne 0 ]; then
57
printf "COMMIT FAILED\n"
68
exit 1
79
fi
810

9-
10-
#make lint
11-
#if [ $? -ne 0 ]; then
12-
# printf "COMMIT FAILED\n"
13-
# exit 1
14-
#fi
15-
16-
printf "==> Step 2: Generating docs for tencentcloud provider...\n"
17-
doc=`make doc 2>&1`
11+
printf "==> Step 2: [Faster]Generating Docs...\n"
12+
doc=$(make doc-faster 2>&1)
1813
if [ $? -ne 0 ]; then
19-
echo "$doc"| tail -n 4|head -n 2
14+
echo "$doc" | tail -n 4 | head -n 2
2015
printf "COMMIT FAILED\n"
2116
exit 1
2217
fi
2318

24-
#make website-lint
25-
#if [ $? -ne 0 ]; then
26-
# printf "COMMIT FAILED\n"
27-
# exit 1
28-
#fi
29-
30-
printf "==> Step 3: Doc Check...\n"
31-
diff=`git diff --name-only website/docs/`
32-
if [ "$diff" != "" ]; then
33-
printf "There are docs updated when checking, 'git add' it first.\n"
19+
printf "==> Step 3: Checking go version...\n"
20+
go_version=$(go version | awk '{print $3}' | cut -d '.' -f 1-2)
21+
if echo "$REQUIRED_GO_VERSION" | grep -q "$go_version\."; then
22+
echo "Go version is compatible. Current:$go_version"
23+
else
24+
echo "Go version is not compatible. Expected:$REQUIRED_GO_VERSION Current:$go_version"
3425
printf "COMMIT FAILED\n"
3526
exit 1
3627
fi
3728

38-
printf "==> Step 4: Incremental unit tests...\n"
39-
# go test check
40-
make deltatest
41-
if [ $? -ne 0 ]; then
42-
printf "COMMIT FAILED\n"
43-
exit 1
44-
fi
29+
# printf "==> Step 4: Doc Check...\n"
30+
# diff=$(git diff --name-only website/docs/)
31+
# if [ "$diff" != "" ]; then
32+
# printf "There are docs updated when checking, 'git add' it first.\n"
33+
# printf "COMMIT FAILED\n"
34+
# exit 1
35+
# fi
36+
37+
# printf "==> Step 5: Incremental unit tests...\n"
38+
# # go test check
39+
# make deltatest
40+
# if [ $? -ne 0 ]; then
41+
# printf "COMMIT FAILED\n"
42+
# exit 1
43+
# fi
4544

4645
printf "COMMIT READY\n"
4746
exit 0

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.17.1
1+
1.18.3

GNUmakefile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ fmt:
2727
gofmt -s -w ./$(PKG_NAME)
2828

2929
fmt-faster:
30-
@echo "==> [Faster]Fixing source code with gofmt...\n $(CHANGED_FILES) \n"
31-
goimports -w $(CHANGED_FILES)
32-
gofmt -s -w $(CHANGED_FILES)
30+
@if [[ -z $(CHANGED_FILES) ]]; then \
31+
echo "skip the fmt cause the CHANGED_FILES is null."; \
32+
exit 0; \
33+
else \
34+
echo "==> [Faster]Fixing source code with gofmt...\n $(CHANGED_FILES) \n"; \
35+
goimports -w $(CHANGED_FILES); \
36+
gofmt -s -w $(CHANGED_FILES); \
37+
fi
3338

3439
# Currently required by tf-deploy compile
3540
fmtcheck:
@@ -101,10 +106,9 @@ lint:
101106
./$(PKG_NAME)
102107

103108
tools:
104-
GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint
105-
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
106-
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
107-
GO111MODULE=on go install github.com/katbyte/terrafmt
109+
GO111MODULE=on cd .ci/tools && go install github.com/bflad/tfproviderlint/cmd/tfproviderlint && cd ../..
110+
GO111MODULE=on cd .ci/tools && go install github.com/client9/misspell/cmd/misspell && cd ../..
111+
GO111MODULE=on cd .ci/tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2 && cd ../..
108112

109113
test-compile:
110114
@if [ "$(TEST)" = "./..." ]; then \
@@ -136,9 +140,24 @@ test-build-x86:
136140
doc:
137141
cd gendoc && go run ./... && cd ..
138142

143+
doc-faster:
144+
@echo "==> [Faster]Generating doc..."
145+
@if [ ! -f gendoc/gendoc ]; then \
146+
$(MAKE) doc-bin-build; \
147+
fi
148+
@$(MAKE) doc-with-bin
149+
150+
doc-with-bin:
151+
cd gendoc && ./gendoc ./... && cd ..
152+
153+
doc-bin-build:
154+
@echo "==> Building gendoc binary..."
155+
cd gendoc && go build ./... && cd ..
156+
139157
hooks: tools
140-
find .git/hooks -type l -exec rm {} \;
141-
find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
158+
@find .git/hooks -type l -exec rm {} \;
159+
@find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
160+
@echo "==> Install hooks done."
142161

143162
website:
144163
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))

0 commit comments

Comments
 (0)