From 40da61cae98b1c1ece96baba54a615ebc3516300 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:32:51 +0800 Subject: [PATCH 1/7] Add the linting command --- Makefile | 14 +++++++++++++- gcb-visualizer.go | 3 ++- internal/utils/cloudbuild_test.go | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6931948..95aedda 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,17 @@ build: go build -ldflags="-s -w" -tests: +.PHONY: test +test: go test -count=1 ./... + +format-lint: + errors=$$(gofmt -l .); if [ "$${errors}" != "" ]; then echo "Format Lint Error Files:\n$${errors}"; exit 1; fi + +import-lint: + errors=$$(goimports -l .); if [ "$${errors}" != "" ]; then echo "Import Lint Error Files:\n$${errors}"; exit 1; fi + +style-lint: + errors=$$(golint ./...); if [ "$${errors}" != "" ]; then echo "Style Lint Error Files:\n$${errors}"; exit 1; fi + +lint: format-lint import-lint style-lint diff --git a/gcb-visualizer.go b/gcb-visualizer.go index ba37b59..4c1d653 100644 --- a/gcb-visualizer.go +++ b/gcb-visualizer.go @@ -2,9 +2,10 @@ package main import ( "fmt" + "os" + "github.com/RyanSiu1995/gcb-visualizer/cmd" log "github.com/sirupsen/logrus" - "os" ) func init() { diff --git a/internal/utils/cloudbuild_test.go b/internal/utils/cloudbuild_test.go index 7242963..4598e5c 100644 --- a/internal/utils/cloudbuild_test.go +++ b/internal/utils/cloudbuild_test.go @@ -3,7 +3,6 @@ package util import ( "bytes" "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "os" "path" @@ -14,6 +13,7 @@ import ( graphviz "github.com/goccy/go-graphviz" "github.com/goccy/go-graphviz/cgraph" "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" ) var supportedFormat = []string{".yaml", ".yml", ".json"} From ddcbdf3e77501735f83e6aec56586f0c94eea131 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:35:00 +0800 Subject: [PATCH 2/7] Use make command in CI --- .github/workflows/go.yml | 9 ++++++--- Makefile | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d310128..fe22865 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,10 +27,13 @@ jobs: uses: actions/checkout@v2 - name: Get dependencies run: | - go get -v -t -d ./... + make get + - name: Lint Code + run: | + make lint - name: Test run: | - go test ./... -v + make test - name: Build Artifacts run: | - go build -ldflags="-s -w" -o gcb-visualizer + make build diff --git a/Makefile b/Makefile index 95aedda..d14a655 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,13 @@ build: - go build -ldflags="-s -w" + go build -ldflags="-s -w" -o gcb-visualizer .PHONY: test test: go test -count=1 ./... +get: + go get -v -t -d ./... + format-lint: errors=$$(gofmt -l .); if [ "$${errors}" != "" ]; then echo "Format Lint Error Files:\n$${errors}"; exit 1; fi From b2f46b333a6b25a8ffc425492143a819cd5d05e2 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:40:41 +0800 Subject: [PATCH 3/7] Install the golint and goimport --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fe22865..896a33a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,6 +30,9 @@ jobs: make get - name: Lint Code run: | + go get -u golang.org/x/tools/cmd/goimports + go get -u golang.org/x/lint/golint + export PATH=$PATH:$GOPATH/bin make lint - name: Test run: | From 709c321b8353af48df45b9ddffbbe04a53d5a986 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:46:54 +0800 Subject: [PATCH 4/7] Update the implementation of linter in workflow --- .github/workflows/go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 896a33a..030f81e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,9 +30,9 @@ jobs: make get - name: Lint Code run: | - go get -u golang.org/x/tools/cmd/goimports - go get -u golang.org/x/lint/golint - export PATH=$PATH:$GOPATH/bin + GOBIN=$PWD/bin go install golang.org/x/tools/cmd/goimports + GOBIN=$PWD/bin go install golang.org/x/lint/golint + export PATH=$PATH:$PWD/bin make lint - name: Test run: | From e6f72396f50ad170fddf4e109d0d3db466bc7ce8 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:50:53 +0800 Subject: [PATCH 5/7] Run the command without a specified shell langugage --- .github/workflows/go.yml | 5 ++--- Makefile | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 030f81e..c7b106c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,9 +30,8 @@ jobs: make get - name: Lint Code run: | - GOBIN=$PWD/bin go install golang.org/x/tools/cmd/goimports - GOBIN=$PWD/bin go install golang.org/x/lint/golint - export PATH=$PATH:$PWD/bin + go install golang.org/x/tools/cmd/goimports + go install golang.org/x/lint/golint make lint - name: Test run: | diff --git a/Makefile b/Makefile index d14a655..df03c95 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,12 @@ get: go get -v -t -d ./... format-lint: - errors=$$(gofmt -l .); if [ "$${errors}" != "" ]; then echo "Format Lint Error Files:\n$${errors}"; exit 1; fi + gofmt -l -d . import-lint: - errors=$$(goimports -l .); if [ "$${errors}" != "" ]; then echo "Import Lint Error Files:\n$${errors}"; exit 1; fi + goimports -l -d . style-lint: - errors=$$(golint ./...); if [ "$${errors}" != "" ]; then echo "Style Lint Error Files:\n$${errors}"; exit 1; fi + golint ./... lint: format-lint import-lint style-lint From 65c7b9e8d3a364e0b5b71a01dd4346361e147c02 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 18:58:15 +0800 Subject: [PATCH 6/7] Update Makefile --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index df03c95..1387a94 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +BIN=$(GOBIN) + build: go build -ldflags="-s -w" -o gcb-visualizer @@ -12,9 +14,9 @@ format-lint: gofmt -l -d . import-lint: - goimports -l -d . + ${BIN}/goimports -l -d . style-lint: - golint ./... + ${BIN}/golint ./... lint: format-lint import-lint style-lint From 7e9c3508f4a85fd243f3d4dba9604ba79963a802 Mon Sep 17 00:00:00 2001 From: Ryan SIU Date: Tue, 2 Jun 2020 19:02:08 +0800 Subject: [PATCH 7/7] Ensure the GOBIN is on the dir --- .github/workflows/go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c7b106c..62e9865 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,9 +30,9 @@ jobs: make get - name: Lint Code run: | - go install golang.org/x/tools/cmd/goimports - go install golang.org/x/lint/golint - make lint + GOBIN=$HOME go install golang.org/x/tools/cmd/goimports + GOBIN=$HOME go install golang.org/x/lint/golint + GOBIN=$HOME make lint - name: Test run: | make test