diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 9b8e89e236..3aa3e23cc3 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,47 +1,46 @@ #!/bin/sh -printf "==> Step 1: Gofmt Check...\n" -make fmtcheck +REQUIRED_GO_VERSION=go$(cat .go-version) # use the .go-version + +printf "==> Step 1: [Faster]Gofmt Check...\n" +make fmt-faster if [ $? -ne 0 ]; then printf "COMMIT FAILED\n" exit 1 fi - -#make lint -#if [ $? -ne 0 ]; then -# printf "COMMIT FAILED\n" -# exit 1 -#fi - -printf "==> Step 2: Generating docs for tencentcloud provider...\n" -doc=`make doc 2>&1` +printf "==> Step 2: [Faster]Generating Docs...\n" +doc=$(make doc-faster 2>&1) if [ $? -ne 0 ]; then - echo "$doc"| tail -n 4|head -n 2 + echo "$doc" | tail -n 4 | head -n 2 printf "COMMIT FAILED\n" exit 1 fi -#make website-lint -#if [ $? -ne 0 ]; then -# printf "COMMIT FAILED\n" -# exit 1 -#fi - -printf "==> Step 3: Doc Check...\n" -diff=`git diff --name-only website/docs/` -if [ "$diff" != "" ]; then - printf "There are docs updated when checking, 'git add' it first.\n" +printf "==> Step 3: Checking go version...\n" +go_version=$(go version | awk '{print $3}' | cut -d '.' -f 1-2) +if echo "$REQUIRED_GO_VERSION" | grep -q "$go_version\."; then + echo "Go version is compatible. Current:$go_version" +else + echo "Go version is not compatible. Expected:$REQUIRED_GO_VERSION Current:$go_version" printf "COMMIT FAILED\n" exit 1 fi -printf "==> Step 4: Incremental unit tests...\n" -# go test check -make deltatest -if [ $? -ne 0 ]; then - printf "COMMIT FAILED\n" - exit 1 -fi +# printf "==> Step 4: Doc Check...\n" +# diff=$(git diff --name-only website/docs/) +# if [ "$diff" != "" ]; then +# printf "There are docs updated when checking, 'git add' it first.\n" +# printf "COMMIT FAILED\n" +# exit 1 +# fi + +# printf "==> Step 5: Incremental unit tests...\n" +# # go test check +# make deltatest +# if [ $? -ne 0 ]; then +# printf "COMMIT FAILED\n" +# exit 1 +# fi printf "COMMIT READY\n" exit 0 diff --git a/.go-version b/.go-version index 511a76e6fa..b9fb27ab4f 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.17.1 +1.18.3 diff --git a/GNUmakefile b/GNUmakefile index 3db164976b..fcf1c17994 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -27,9 +27,14 @@ fmt: gofmt -s -w ./$(PKG_NAME) fmt-faster: - @echo "==> [Faster]Fixing source code with gofmt...\n $(CHANGED_FILES) \n" - goimports -w $(CHANGED_FILES) - gofmt -s -w $(CHANGED_FILES) + @if [[ -z $(CHANGED_FILES) ]]; then \ + echo "skip the fmt cause the CHANGED_FILES is null."; \ + exit 0; \ + else \ + echo "==> [Faster]Fixing source code with gofmt...\n $(CHANGED_FILES) \n"; \ + goimports -w $(CHANGED_FILES); \ + gofmt -s -w $(CHANGED_FILES); \ + fi # Currently required by tf-deploy compile fmtcheck: @@ -101,10 +106,9 @@ lint: ./$(PKG_NAME) tools: - GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint - GO111MODULE=on go install github.com/client9/misspell/cmd/misspell - GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint - GO111MODULE=on go install github.com/katbyte/terrafmt + GO111MODULE=on cd .ci/tools && go install github.com/bflad/tfproviderlint/cmd/tfproviderlint && cd ../.. + GO111MODULE=on cd .ci/tools && go install github.com/client9/misspell/cmd/misspell && cd ../.. + GO111MODULE=on cd .ci/tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2 && cd ../.. test-compile: @if [ "$(TEST)" = "./..." ]; then \ @@ -136,9 +140,24 @@ test-build-x86: doc: cd gendoc && go run ./... && cd .. +doc-faster: + @echo "==> [Faster]Generating doc..." + @if [ ! -f gendoc/gendoc ]; then \ + $(MAKE) doc-bin-build; \ + fi + @$(MAKE) doc-with-bin + +doc-with-bin: + cd gendoc && ./gendoc ./... && cd .. + +doc-bin-build: + @echo "==> Building gendoc binary..." + cd gendoc && go build ./... && cd .. + hooks: tools - find .git/hooks -type l -exec rm {} \; - find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \; + @find .git/hooks -type l -exec rm {} \; + @find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \; + @echo "==> Install hooks done." website: ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))