ci: overall enhancements and cosmetics improvements (#134)

* ci: cosmetic renaming CI jobs

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>

* chore: overrall Makefile enhancements

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
Khosrow Moossavi 2021-03-31 12:41:24 -04:00 committed by GitHub
parent b02996e027
commit 8d9e00b699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 56 deletions

View file

@ -1,35 +1,57 @@
name: tests name: ci
on: on:
pull_request: pull_request:
types: ['opened', 'synchronize'] types: ["opened", "synchronize"]
paths-ignore: paths-ignore:
- 'README.md' - "README.md"
push: push:
branches: branches:
- master - master
paths-ignore: paths-ignore:
- 'README.md' - "README.md"
env:
GO_VERSION: "1.16"
jobs: jobs:
unit: tests:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: ${{ env.GO_VERSION }}
- name: Run tests - name: Run tests
run: | run: make test
make test
- name: Install goveralls - name: Install goveralls
run: go get github.com/mattn/goveralls
env: env:
GO111MODULE: off GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Send coverage - name: Send coverage
run: goveralls -coverprofile=cover.out -service=github
env: env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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

View file

@ -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

View file

@ -1,22 +1,28 @@
name: goreleaser name: release
on: on:
push: push:
tags: tags:
- '*' - "*"
env:
GO_VERSION: "1.16"
jobs: jobs:
goreleaser: goreleaser:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: ${{ env.GO_VERSION }}
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2 uses: goreleaser/goreleaser-action@v2
with: with:

View file

@ -27,13 +27,13 @@ archives:
format: zip format: zip
checksum: checksum:
name_template: 'checksums.txt' name_template: "checksums.txt"
changelog: changelog:
sort: desc sort: desc
filters: filters:
exclude: exclude:
- '^Merge' - "^Merge"
snapshot: snapshot:
name_template: "{{ .Tag }}-next" name_template: "{{ .Tag }}-next"
@ -47,4 +47,4 @@ brews:
test: | test: |
system "#{bin}/git-chglog --help" system "#{bin}/git-chglog --help"
install: | install: |
bin.install "git-chglog" bin.install "git-chglog"

100
Makefile
View file

@ -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 .PHONY: clean
clean: clean: ## Clean workspace
@ $(MAKE) --no-print-directory log-$@
rm -rf ./dist/ rm -rf ./dist/
rm -rf ./git-chglog rm -rf ./git-chglog
rm -rf $(GOPATH)/bin/git-chglog rm -rf $(GOPATH)/bin/git-chglog
rm -rf cover.out rm -rf cover.out
.PHONY: build
build:
go build -ldflags=$(LDFLAGS) -o git-chglog ./cmd/git-chglog
.PHONY: test .PHONY: test
test: test: ## Run tests
go test -covermode atomic -coverprofile cover.out -v ./... @ $(MAKE) --no-print-directory log-$@
$(GOHOST) 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
.PHONY: lint .PHONY: lint
lint: lint: ## Run linters
@golangci-lint run @ $(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 .PHONY: release
release: changelog release: changelog ## Release a new tag
@git add CHANGELOG.md @ $(MAKE) --no-print-directory log-$@
@git commit -m "chore: update changelog for $(VERSION)" git add CHANGELOG.md
git commit -m "chore: update changelog for $(VERSION)"
git tag $(VERSION) git tag $(VERSION)
git push origin master $(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<target>%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 \
}'