-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
94 lines (71 loc) · 2.7 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
.DEFAULT_GOAL := help
SHELL := /bin/bash
APP_NAME := stylist
BUILD_DIR := ./dist
DST_DIR := /usr/local/bin
CURRENT_SHA = $(shell git rev-parse --short HEAD)
CURRENT_TS = $(shell date -Iseconds)
##@ App
.PHONY: coverage
coverage: gocovsh ## Show code coverage
@make test
gocovsh --profile coverage.out
.PHONY: build
build: ## Build the app
go mod tidy
go build -ldflags='-X main.version=dev -X main.commit=$(CURRENT_SHA) -X main.date=$(CURRENT_TS)' -o ${BUILD_DIR}/${APP_NAME} .
.PHONY: install
install: build ## Install the app
install -d ${DST_DIR}
install -m755 ${BUILD_DIR}/${APP_NAME} ${DST_DIR}/
.PHONY: generate
generate: go-enum
go generate ./...
.PHONY: lint
lint: actionlint golangci-lint ## Lint the app
actionlint
golangci-lint run
.PHONY: format
format: pin-github-action ## Format the app
gofmt -w .
pin-github-action .github/workflows/*.yml
.PHONY: test
test: ## Test the app
go mod tidy
go test --coverprofile=coverage.out ./...
.PHONY: release
release: svu ## Create a new release tag
git fetch --all --tags
@if [[ "$$(svu next)" == "$$(svu current)" ]]; then echo "Nothing to release!" && exit 1; fi
git tag -a "$$(svu next)" -m "Release version $$(svu next)" && git push origin --tags
##@ Other
.PHONY: setup
setup: ## Bootstrap for local development
@if ! command -v gh >/dev/null 2>&1; then echo "Unable to find gh!"; exit 1; fi
@if ! command -v git >/dev/null 2>&1; then echo "Unable to find git!"; exit 1; fi
@if ! command -v go >/dev/null 2>&1; then echo "Unable to find go!"; exit 1; fi
# Via https://www.thapaliya.com/en/writings/well-documented-makefiles/
# Note: The `##@` comments determine grouping
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@echo ""
# Dependencies
.PHONY: actionlint
actionlint:
@if ! command -v actionlint >/dev/null 2>&1; then go install github.com/rhysd/actionlint/cmd/actionlint@latest; fi
.PHONY: go-enum
go-enum:
@if ! command -v go-enum >/dev/null 2>&1; then go install github.com/abice/go-enum@latest; fi
.PHONY: gocovsh
gocovsh:
@if ! command -v gocovsh >/dev/null 2>&1; then go install github.com/orlangure/gocovsh@latest; fi
.PHONY: golangci-lint
golangci-lint:
@if ! command -v golangci-lint >/dev/null 2>&1; then go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; fi
.PHONY: pin-github-action
pin-github-action:
@if ! command -v pin-github-action >/dev/null 2>&1; then npm install -g pin-github-action; fi
.PHONY: svu
svu:
@if ! command -v svu >/dev/null 2>&1; then go install github.com/caarlos0/svu@latest; fi