From e49a37632fa4740b27b083f7551d37ea40293e6b Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Mon, 5 Apr 2021 15:40:02 -0500 Subject: [PATCH] ci: add makefile and go releaser Signed-off-by: Derek Smith --- .github/workflows/release.yml | 31 ++++++++++++ .github/workflows/test.yml | 10 +++- .goreleaser.yml | 10 ++++ Makefile | 88 +++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 Makefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a44de88 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +env: + GO_VERSION: "1.16" + +jobs: + goreleaser: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37daef4..f934164 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,9 @@ on: [push, pull_request] name: test and build + +env: + GO_VERSION: "1.16" + jobs: coverage: runs-on: ubuntu-latest @@ -8,18 +12,22 @@ jobs: if: success() uses: actions/setup-go@v2 with: - go-version: 1.16.x + go-version: ${{ env.GO_VERSION }} + - name: Checkout code uses: actions/checkout@v2 + - name: Calc coverage run: | export PATH=$PATH:$(go env GOPATH)/bin go test -v -covermode=count -coverprofile=coverage.out -run ^Test_ + - name: Convert coverage to lcov uses: jandelgado/gcov2lcov-action@v1.0.8 with: infile: coverage.out outfile: coverage.lcov + - name: Coveralls uses: coverallsapp/github-action@v1.1.2 with: diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..856c339 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,10 @@ +project_name: "github.com/clok/cdocs" + +builds: + - skip: true + +changelog: + sort: desc + filters: + exclude: + - '^Merge' diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ad8dfc --- /dev/null +++ b/Makefile @@ -0,0 +1,88 @@ +# Build Variables +VERSION ?= $(shell git describe --tags --always) + +# Go variables +GO ?= go +GOOS ?= $(shell $(GO) env GOOS) +GOARCH ?= $(shell $(GO) env GOARCH) +GOHOST ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) + +LDFLAGS ?= "-X main.version=$(VERSION)" + +.PHONY: all +all: help + +############### +##@ Development + +.PHONY: clean +clean: ## Clean workspace + @ $(MAKE) --no-print-directory log-$@ + rm -rf cover.out + go mod tidy + +.PHONY: test +test: ## Run tests + @ $(MAKE) --no-print-directory log-$@ + $(GOHOST) test -covermode count -coverprofile cover.out -v -run ^Test ./... + +.PHONY: lint +lint: ## Run linters + @ $(MAKE) --no-print-directory log-$@ + golangci-lint run + +########### +##@ Release + +.PHONY: check +check: ## Check if version exists + @ $(MAKE) --no-print-directory log-$@ + ifeq ($(shell git tag -l | grep -c $(VERSION) 2>/dev/null), 0) + else + @git tag -l + @echo "VERSION: $(VERSION) has already been used. Please pass in a different version value." + @exit 2 + endif + +.PHONY: changelog +changelog: check ## Generate changelog + @ $(MAKE) --no-print-directory log-$@ + git-chglog --next-tag $(VERSION) -o CHANGELOG.md + +.PHONY: release +release: changelog ## Release a new tag + @ $(MAKE) --no-print-directory log-$@ + git add CHANGELOG.md + git commit -m "chore: update changelog for $(VERSION)" + git tag $(VERSION) + git push origin main $(VERSION) + +######## +##@ Help + +.PHONY: help +help: ## Display this help + @awk \ + -v "col=\033[36m" -v "nocol=\033[0m" \ + ' \ + BEGIN { \ + FS = ":.*##" ; \ + printf "Usage:\n make %s%s\n", col, nocol \ + } \ + /^[a-zA-Z_-]+:.*?##/ { \ + printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \ + } \ + /^##@/ { \ + printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \ + } \ + ' $(MAKEFILE_LIST) + +log-%: + @grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \ + awk \ + 'BEGIN { \ + FS = ":.*?## " \ + }; \ + { \ + printf "\033[36m==> %s\033[0m\n", $$2 \ + }'