-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
94 lines (73 loc) · 2.66 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
.SHELL := /usr/bin/env bash
# Environment
GO := $(shell which go)
DOCKER := $(shell which docker)
GOTEST = $(GO) test
GOLIST := $(shell $(GO) list ./... | grep -v /vendor/)
YAMLFILES := $(shell git ls-files '*.yml' '*.yaml')
PWD := $(shell pwd)
BUILD_VERSION := $(shell git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)
# Fancy colors
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
# Configuration
GOLANGCI_LINT_IMAGE = golangci/golangci-lint:latest-alpine
YAMLLINT_IMAGE = cytopia/yamllint:latest
COVERAGE_EXPORT = false # Set to 'true' if 'COVERAGE_FILE' should be kept, otherwise it is deleted.
COVERAGE_FILE = profile.cov
BINARY_NAME = calendarsync
.PHONY: all test build vendor
all: help
## Build
build: ## Build CalendarSync
@mkdir -p bin
$(GO) build -race -ldflags \
"-X 'main.Version=$(BUILD_VERSION)' \
-X 'main.BuildTime=$(shell date)' \
-X 'main.GoogleClientID=${CS_GOOGLE_CLIENT_ID}' \
-X 'main.GoogleClientKey=${CS_GOOGLE_CLIENT_KEY}'" \
-o bin/$(BINARY_NAME) cmd/calendarsync/main.go
build_goreleaser:
goreleaser build --snapshot --clean
clean: ## Clean build assets
rm -rf ./bin
vendor: ## Vendor dependencies
$(GO) mod vendor
## Test
test: ## Run all tests
$(GO) run github.com/vektra/mockery/[email protected]
$(GOTEST) -race $(GOLIST)
coverage: ## Run tests with coverage and export it into 'profile.cov'. If 'COVERAGE_EXPORT' is true, 'COVERAGE_FILE' is written
$(GOTEST) -cover -covermode=count -coverprofile=$(COVERAGE_FILE) ./...
$(GO) tool cover -func $(COVERAGE_FILE)
ifeq ($(COVERAGE_EXPORT), false)
@rm $(COVERAGE_FILE)
endif
## Lint
lint: lint-go lint-yaml lint-dockerfile ## Run all linters
lint-go: ## Lint all GO files
$(DOCKER) run --rm -it -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) golangci-lint run --go "1.23"
lint-yaml: ## Lint all YAML files
$(DOCKER) run --rm -it -v $(PWD):/data $(YAMLLINT_IMAGE) -f parsable $(YAMLFILES)
@echo '${CYAN}TODO${RESET}'
lint-dockerfile: ## Lint Dockerfile if there is one
@echo '${CYAN}TODO${RESET}'
## Documentation
docs-serve: ## Run 'hugo server' to serve the documentation on localhost:1313
@cd docs && hugo server
## Help
help: ## Show this help.
@echo '====================='
@echo '${GREEN}CalendarSync Makefile${RESET}'
@echo '====================='
@echo ''
@echo 'Usage:'
@echo ' make ${CYAN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${CYAN}%-20s${WHITE}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${WHITE}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)