Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.1
1.18.3
37 changes: 28 additions & 9 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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)))
Expand Down