From 8d9e00b6995828d6b170cf81996cd5d83ca92202 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Wed, 31 Mar 2021 12:41:24 -0400 Subject: [PATCH] ci: overall enhancements and cosmetics improvements (#134) * ci: cosmetic renaming CI jobs Signed-off-by: Khosrow Moossavi * chore: overrall Makefile enhancements Signed-off-by: Khosrow Moossavi --- .github/workflows/{test.yml => ci.yml} | 42 ++++++++--- .github/workflows/lint.yml | 18 ----- .github/workflows/release.yml | 12 ++- .goreleaser.yml | 6 +- Makefile | 100 +++++++++++++++++++------ 5 files changed, 122 insertions(+), 56 deletions(-) rename .github/workflows/{test.yml => ci.yml} (50%) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 50% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 3327c1ab..c6be40f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,35 +1,57 @@ -name: tests +name: ci on: pull_request: - types: ['opened', 'synchronize'] + types: ["opened", "synchronize"] paths-ignore: - - 'README.md' + - "README.md" push: branches: - master paths-ignore: - - 'README.md' + - "README.md" + +env: + GO_VERSION: "1.16" + jobs: - unit: + tests: runs-on: ubuntu-20.04 + if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: ${{ env.GO_VERSION }} + - name: Run tests - run: | - make test + run: make test + - name: Install goveralls + run: go get github.com/mattn/goveralls env: GO111MODULE: off - run: go get github.com/mattn/goveralls + - name: Send coverage + run: goveralls -coverprofile=cover.out -service=github env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: goveralls -coverprofile=cover.out -service=github + + lint: + runs-on: ubuntu-20.04 + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.38 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 49f5fde0..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: lint - -on: - pull_request: - types: ['opened', 'synchronize'] - push: - branches: - - master -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.38 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2cc15f77..dab5ed9c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,28 @@ -name: goreleaser +name: release on: push: tags: - - '*' + - "*" + +env: + GO_VERSION: "1.16" jobs: goreleaser: runs-on: ubuntu-20.04 + if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: ${{ env.GO_VERSION }} + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: diff --git a/.goreleaser.yml b/.goreleaser.yml index 0272d395..834eee6b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -27,13 +27,13 @@ archives: format: zip checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" changelog: sort: desc filters: exclude: - - '^Merge' + - "^Merge" snapshot: name_template: "{{ .Tag }}-next" @@ -47,4 +47,4 @@ brews: test: | system "#{bin}/git-chglog --help" install: | - bin.install "git-chglog" \ No newline at end of file + bin.install "git-chglog" diff --git a/Makefile b/Makefile index fdffdcb4..e05c917c 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,93 @@ -VERSION?=$$(git describe --tags --always) +# Build variables +VERSION ?= $(shell git describe --tags --always) -LDFLAGS="-X main.version=$(VERSION)" +# 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: ## Clean workspace + @ $(MAKE) --no-print-directory log-$@ rm -rf ./dist/ rm -rf ./git-chglog rm -rf $(GOPATH)/bin/git-chglog rm -rf cover.out -.PHONY: build -build: - go build -ldflags=$(LDFLAGS) -o git-chglog ./cmd/git-chglog - .PHONY: test -test: - go test -covermode atomic -coverprofile cover.out -v ./... - -.PHONY: install -install: - go install ./cmd/git-chglog - -.PHONY: changelog -changelog: build - ./git-chglog --next-tag $(VERSION) -o CHANGELOG.md +test: ## Run tests + @ $(MAKE) --no-print-directory log-$@ + $(GOHOST) test -covermode atomic -coverprofile cover.out -v ./... .PHONY: lint -lint: - @golangci-lint run +lint: ## Run linters + @ $(MAKE) --no-print-directory log-$@ + golangci-lint run + +######### +##@ Build + +.PHONY: build +build: ## Build git-chglog + @ $(MAKE) --no-print-directory log-$@ + CGO_ENABLED=0 $(GOHOST) build -ldflags=$(LDFLAGS) -o git-chglog ./cmd/git-chglog + +.PHONY: install +install: ## Install git-chglog + @ $(MAKE) --no-print-directory log-$@ + $(GOHOST) install ./cmd/git-chglog + +########### +##@ Release + +.PHONY: changelog +changelog: build ## Generate changelog + @ $(MAKE) --no-print-directory log-$@ + ./git-chglog --next-tag $(VERSION) -o CHANGELOG.md .PHONY: release -release: changelog - @git add CHANGELOG.md - @git commit -m "chore: update changelog for $(VERSION)" +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 master $(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 \ + }'