From 3dabf9677b2bd68778d07d68f9f71c4d1bc92a74 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Sun, 8 Mar 2020 23:58:28 -0400 Subject: [PATCH] Add github action CI (#26) * add basic github action workflow Signed-off-by: yeya24 --- .github/workflows/workflow.yaml | 20 ++++++++++++++++++++ .gitignore | 4 +++- Makefile | 23 ++++++++++++++++------- cmd/go-tpc/main.go | 6 +++--- tpcc/load.go | 2 +- 5 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/workflow.yaml diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml new file mode 100644 index 0000000..c6be5e2 --- /dev/null +++ b/.github/workflows/workflow.yaml @@ -0,0 +1,20 @@ +name: "workflow" +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2 + with: + go-version: 1.13.x + - uses: actions/checkout@v2 + + - name: "format" + run: make format + + - name: "test" + run: make test + + - name: "build" + run: make build diff --git a/.gitignore b/.gitignore index c5e82d7..9696c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -bin \ No newline at end of file +bin +.idea/ +go-tpc diff --git a/Makefile b/Makefile index 7dd194a..835b403 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,27 @@ GO=GO15VENDOREXPERIMENT="1" CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GO111MOD PACKAGE_LIST := go list ./...| grep -vE "cmd" PACKAGES := $$($(PACKAGE_LIST)) -FILES := $$(find . -name "*.go" | grep -vE "vendor") -GOFILTER := grep -vE 'vendor|render.Delims|bindata_assetfs|testutil|\.pb\.go' -GOCHECKER := $(GOFILTER) | awk '{ print } END { if (NR > 0) { exit 1 } }' +FILES_TO_FMT := $(shell find . -path -prune -o -name '*.go' -print) -all: build +all: format test build + +format: vet fmt fmt: @echo "gofmt" - @gofmt -s -l -w $(FILES) 2>&1 | $(GOCHECKER) + @gofmt -w ${FILES_TO_FMT} + @git diff --exit-code . test: go test ./... -cover $(PACKAGES) -build: - go build -o ./bin/go-tpc cmd/go-tpc/* \ No newline at end of file +build: mod + go build -o ./bin/go-tpc cmd/go-tpc/* + +vet: + go vet ./... + +mod: + @echo "go mod tidy" + GO111MODULE=on go mod tidy + @git diff --exit-code -- go.sum go.mod diff --git a/cmd/go-tpc/main.go b/cmd/go-tpc/main.go index 6d7559d..0ca22d0 100644 --- a/cmd/go-tpc/main.go +++ b/cmd/go-tpc/main.go @@ -39,9 +39,9 @@ var ( ) const ( - unknownDB = "Unknown database" - createDBDDL = "CREATE DATABASE " - mysqlDriver = "mysql" + unknownDB = "Unknown database" + createDBDDL = "CREATE DATABASE " + mysqlDriver = "mysql" ) func closeDB() { diff --git a/tpcc/load.go b/tpcc/load.go index 6465d76..ce8afe7 100644 --- a/tpcc/load.go +++ b/tpcc/load.go @@ -46,7 +46,7 @@ func (w *Workloader) loadItem(ctx context.Context) error { var v []string if isDataGen { - v = []string{strconv.Itoa(i+1), strconv.Itoa(iImID), iName, fmt.Sprintf("%f", iPrice), iData} + v = []string{strconv.Itoa(i + 1), strconv.Itoa(iImID), iName, fmt.Sprintf("%f", iPrice), iData} } else { v = []string{fmt.Sprintf(`(%d, %d, '%s', %f, '%s')`, i+1, iImID, iName, iPrice, iData)} }