-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
74 lines (57 loc) · 2 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
SHA1 := $(shell git rev-parse --verify HEAD)
SHA1_SHORT := $(shell git rev-parse --verify --short HEAD)
VERSION := $(shell cat VERSION.txt)
INTERNAL_BUILD_ID := $(shell [ -z "${GITHUB_RUN_NUMBER}" ] && echo "0" || echo ${GITHUB_RUN_NUMBER})
PWD := $(shell pwd)
VERSION_HASH := ${VERSION}.${INTERNAL_BUILD_ID}
BUILD_IMAGE := golang:1.18
LINT_IMAGE := golangci/golangci-lint:v1.46.1
SHELL_LINT_IMAGE := koalaman/shellcheck:v0.8.0
MARKDOWN_LINT_IMAGE := tmknom/markdownlint:0.23.1
ENVIRONMENT ?= local
.DEFAULT_GOAL := test
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: version ## Generates the BUILD_VERSION.txt
version:
@echo "Setting build to Version: v$(VERSION)"
$(shell echo v$(VERSION_HASH) > BUILD_VERSION.txt)
.PHONY: lint
lint: ## Runs more than 60 different linters using golangci-lint, shellcheck and markdownlint to ensure consistency in code.
@echo "Running Lint"
docker run --rm \
-e GOPACKAGESPRINTGOLISTERRORS=1 \
-e GO111MODULE=on \
-v $(PWD):/usr/src/app \
-w /usr/src/app \
$(LINT_IMAGE) \
golangci-lint run --timeout=2m
find . -name "*.sh" | xargs docker run --rm \
-v $(PWD):/usr/src/app \
-w /usr/src/app \
$(SHELL_LINT_IMAGE)
docker run -i --rm \
-v $(PWD):/work \
$(MARKDOWN_LINT_IMAGE)
@echo "Completed Lint"
.PHONY: test
test: ## Runs `go test` within a docker container
@echo "Running Tests"
docker run --rm \
-v $(PWD):/usr/src/app \
-w /usr/src/app $(BUILD_IMAGE) \
go test -cover -race -coverprofile=coverage.txt -v -p 8 -count=1 ./...
@echo "Completed tests"
.PHONY: build
build: ## Runs `go build` within a docker container
@echo "Running build"
docker run --rm \
-v $(PWD):/usr/src/app \
-w /usr/src/app $(BUILD_IMAGE) \
go build ./...
@echo "Completed build"
.PHONY: release
release: version test ## Runs the release steps