-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
181 lines (146 loc) · 4.97 KB
/
Makefile
File metadata and controls
181 lines (146 loc) · 4.97 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# dish / Makefile
#
#
# VARS
#
include .env.example
-include .env
PROJECT_NAME?=${APP_NAME}
# release binaries build vars
MAIN_PATH?=./cmd/dish/
LATEST_TAG?=$(shell git describe --tags --abbrev=0 | sed 's/^v//')
DOCKER_DEV_IMAGE?=${PROJECT_NAME}-image
DOCKER_DEV_CONTAINER?=${PROJECT_NAME}-run
DOCKER_TEST_CONTAINER?=${PROJECT_NAME}-test
COMPOSE_FILE=deployments/docker-compose.yml
COMPOSE_FILE_TEST=./docker-compose.test.yml
# define standard colors
# https://gist.github.com/rsperl/d2dfe88a520968fbc1f49db0a29345b9
ifneq (,$(findstring xterm,${TERM}))
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RESET := ""
endif
export
#
# FUNCTIONS
#
define print_info
@echo -e "\n>>> ${YELLOW}${1}${RESET}\n"
endef
define update_semver
$(call print_info, Incrementing semver to ${1}...)
@[ -f ".env" ] || cp .env.example .env
@sed -i 's|APP_VERSION=.*|APP_VERSION=${1}|' .env
@sed -i 's|APP_VERSION=.*|APP_VERSION=${1}|' .env.example
endef
#
# TARGETS
#
all: info
.PHONY: build local_build logs major minor patch push run stop test version lint lint-fix format
info:
@echo -e "\n${GREEN} ${PROJECT_NAME} / Makefile ${RESET}\n"
@echo -e "${YELLOW} make test --- run unit tests (go test) ${RESET}"
@echo -e "${YELLOW} make build --- build project (docker image) ${RESET}"
@echo -e "${YELLOW} make run --- run project ${RESET}"
@echo -e "${YELLOW} make logs --- fetch container's logs ${RESET}"
@echo -e "${YELLOW} make stop --- stop and purge project (only docker containers!) ${RESET}\n"
build:
@echo -e "\n${YELLOW} Building project (docker-compose build)... ${RESET}\n"
@docker compose -f ${COMPOSE_FILE} build
local_build:
@echo -e "\n${YELLOW} [local] Building project... ${RESET}\n"
@go mod tidy
@go build -tags dev -o bin/ ${MAIN_PATH}
run: build
@echo -e "\n${YELLOW} Starting project (docker-compose up)... ${RESET}\n"
@docker compose -f ${COMPOSE_FILE} up --force-recreate
logs:
@echo -e "\n${YELLOW} Fetching container's logs (CTRL-C to exit)... ${RESET}\n"
@docker logs ${DOCKER_DEV_CONTAINER} -f
stop:
@echo -e "\n${YELLOW} Stopping and purging project (docker-compose down)... ${RESET}\n"
@docker compose -f ${COMPOSE_FILE} down
test:
@go test -v -coverprofile cover.out ./...
@go tool cover -html cover.out -o cover.html
@open cover.html
docker-test:
@echo -e "\n${YELLOW} Running tests... ${RESET}\n"
@docker compose -f ${COMPOSE_FILE_TEST} build --no-cache
@docker compose -f ${COMPOSE_FILE_TEST} up --force-recreate --exit-code-from dish
push:
@git tag -fa 'v${APP_VERSION}' -m 'v${APP_VERSION}'
@git push --follow-tags --set-upstream origin master
format:
@echo -e "\nFormating code with golangci-lint..."
@golangci-lint fmt \
--config .golangci.yaml \
./...
lint:
@echo -e "\nRunning golangci-lint..."
@golangci-lint run \
--config .golangci.yaml \
--timeout 2m \
./...
lint-fix:
@echo -e "\nAuto-fixing with golangci-lint..."
@golangci-lint run --fix \
--config .golangci.yaml \
--timeout 2m \
./...
MAJOR := $(shell echo ${APP_VERSION} | cut -d. -f1)
MINOR := $(shell echo ${APP_VERSION} | cut -d. -f2)
PATCH := $(shell echo ${APP_VERSION} | cut -d. -f3)
major:
$(eval APP_VERSION := $(shell echo $$(( ${MAJOR} + 1 )).0.0))
$(call update_semver,${APP_VERSION})
minor:
$(eval APP_VERSION := $(shell echo ${MAJOR}.$$(( ${MINOR} + 1 )).0))
$(call update_semver,${APP_VERSION})
patch:
$(eval APP_VERSION := $(shell echo ${MAJOR}.${MINOR}.$$(( ${PATCH} + 1 ))))
$(call update_semver,${APP_VERSION})
version:
$(call print_info, Current version: ${APP_VERSION}...)
binaries:
@GOARCH=arm64 GOOS=linux go build -o dish-${LATEST_TAG}.linux-arm64 ${MAIN_PATH}
@gzip dish-${LATEST_TAG}.linux-arm64
@GOARCH=amd64 GOOS=linux go build -o dish-${LATEST_TAG}.linux-x86_64 ${MAIN_PATH}
@gzip dish-${LATEST_TAG}.linux-x86_64
@GOARCH=amd64 GOOS=windows go build -o dish-${LATEST_TAG}.windows-x86_64.exe ${MAIN_PATH}
@gzip dish-${LATEST_TAG}.windows-x86_64.exe
@GOARCH=arm64 GOOS=darwin go build -o dish-${LATEST_TAG}.macos-arm64 ${MAIN_PATH}
@gzip dish-${LATEST_TAG}.macos-arm64
@GOARCH=amd64 GOOS=darwin go build -o dish-${LATEST_TAG}.macos-x86_64 ${MAIN_PATH}
@gzip dish-${LATEST_TAG}.macos-x86_64
ifeq (${SONAR_HOST_URL}${SONAR_TOKEN},)
sonar_check:
else
sonar_check:
$(call print_info, Starting the sonarqube code analysis...)
@docker run --rm \
--dns ${DNS_NAMESERVER} \
-e SONAR_HOST_URL="${SONAR_HOST_URL}" \
-e SONAR_TOKEN="${SONAR_TOKEN}" \
-v ".:/usr/src" \
sonarsource/sonar-scanner-cli
endif