From efbe1955c2e465d3d856ba6d0e36b8331e51f4dd Mon Sep 17 00:00:00 2001 From: YuYang Date: Fri, 5 Apr 2024 12:30:03 +0800 Subject: [PATCH] add ci --- .github/workflows/golangci-lint.yml | 31 ++++++++++++++++++++++++++++ .github/workflows/goreleaser.yml | 32 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 20 ++++++++++++++++++ Makefile | 23 +++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .github/workflows/test.yml create mode 100644 Makefile diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..16256ee --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,31 @@ +name: golangci-lint +on: + push: + tags: + - '!v*' + branches: + - '*' + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: latest + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: true diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..f9e0790 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,32 @@ +name: goreleaser + +on: + push: + tags: + - v* + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up environment variables + run: | + echo "VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d4a656f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: test + +on: + push: + tags: + - '!v*' + branches: + - '*' + pull_request: + +jobs: + unittests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + - name: unit tests + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd357f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +.PHONY: deps test unit-test + +REPO_PATH := github.com/yuyang0/dagflow +REVISION := $(shell git rev-parse HEAD || unknown) +BUILTAT := $(shell date +%Y-%m-%dT%H:%M:%S) +VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1)) +GO_LDFLAGS ?= -X $(REPO_PATH)/version.REVISION=$(REVISION) \ + -X $(REPO_PATH)/version.BUILTAT=$(BUILTAT) \ + -X $(REPO_PATH)/version.VERSION=$(VERSION) +deps: + go mod vendor + + +test: deps unit-test + +unit-test: + go vet `go list ./... | grep -v '/vendor/' | grep -v '/tools'` && \ + go test -race -timeout 600s -count=1 -vet=off -cover ./utils/... \ + ./flow/... \ + ./service/... + +lint: + golangci-lint run