From 77a46840de07786603d38fadeb2199db9d6d879c Mon Sep 17 00:00:00 2001 From: linshengqian Date: Mon, 16 Sep 2024 18:11:06 +0800 Subject: [PATCH] workflow --- .github/workflow/main.yml | 63 +++++++++++++++++++++++++++++++++++++++ .idea/vcs.xml | 1 - Makefile | 35 ++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .github/workflow/main.yml create mode 100644 Makefile diff --git a/.github/workflow/main.yml b/.github/workflow/main.yml new file mode 100644 index 0000000..1dc139e --- /dev/null +++ b/.github/workflow/main.yml @@ -0,0 +1,63 @@ +name: CI +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.19 + + - name: Check out code + uses: actions/checkout@v1 + + - name: Lint Go Code + run: | + go install golang.org/x/lint/golint@latest + export PATH="$PATH:$HOME/go/bin" + make lint + + + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.19 + + - name: Check out code + uses: actions/checkout@v1 + + - name: Run Unit tests. + run: make test-coverage + + - name: Upload Coverage report to CodeCov + uses: codecov/codecov-action@v1.0.0 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.txt + + build: + name: Build + runs-on: ubuntu-latest + needs: [lint, test] + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.19 + + - name: Check out code + uses: actions/checkout@v1 + + - name: Build + run: make build diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 9c0b07a..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fa45cfa --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +PROJECT_NAME := "github.com/LinCrayon/gin-gorm-oj" +PKG := "$(PROJECT_NAME)" +PKG_LIST := $(shell go list ${PKG}/...) +GO_FILES := $(shell find . -name '*.go' | grep -v _test.go) + +.PHONY: all dep lint vet test test-coverage build clean + +all: build + +dep: ## Get the dependencies + @go mod download + +lint: ## Lint Golang files + @go install golang.org/x/lint/golint@latest + @golint -set_exit_status ${PKG_LIST} + +vet: ## Run go vet + @go vet ${PKG_LIST} + +test: ## Run unittests + @go test -short ${PKG_LIST} + +test-coverage: ## Run tests with coverage + @go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST} + @cat cover.out >> coverage.txt + +build: dep ## Build the binary file + @go get $(PROJECT_NAME) + @go build -i -o build/main $(PKG) + +clean: ## Remove previous build + @rm -f ./build + +help: ## Display this help screen + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'