Skip to content

Commit

Permalink
ci: add makefile and go releaser
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Smith <dsmith@goodwaygroup.com>
  • Loading branch information
clok committed Apr 5, 2021
1 parent 846c861 commit e49a376
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
on: [push, pull_request]
name: test and build

env:
GO_VERSION: "1.16"

jobs:
coverage:
runs-on: ubuntu-latest
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project_name: "github.com/clok/cdocs"

builds:
- skip: true

changelog:
sort: desc
filters:
exclude:
- '^Merge'
88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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<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 \
}'

0 comments on commit e49a376

Please sign in to comment.