-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
196 lines (139 loc) · 3.52 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env make
env.file ?=
ifdef env.file
include $(env.file)
export $(shell sed 's/=.*//' $(env.file))
endif
###############################
# Common defaults/definitions #
###############################
comma := ,
# Checks two given strings for equality.
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)
###############
# Git Section #
###############
MAINLINE_BRANCH := dev
CURRENT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
# Squash changes of the current Git branch onto another Git branch.
#
# WARNING: You must merge `onto` branch in the current branch before squash!
#
# Usage:
# make squash [onto=] [del=(no|yes)]
onto ?= $(MAINLINE_BRANCH)
del ?= no
upstream ?= origin
squash:
ifeq ($(CURRENT_BRANCH),$(onto))
@echo "--> Current branch is '$(onto)' already" && false
endif
git checkout $(onto)
git branch -m $(CURRENT_BRANCH) orig-$(CURRENT_BRANCH)
git checkout -b $(CURRENT_BRANCH)
git branch --set-upstream-to $(upstream)/$(CURRENT_BRANCH)
git merge --squash orig-$(CURRENT_BRANCH)
ifeq ($(del),yes)
git branch -d orig-$(CURRENT_BRANCH)
endif
###########
# Aliases #
###########
build:
@make yarn yarncmd='run build'
@make maven.build
clean: maven.clean
# Resolve all project dependencies.
#
# Usage:
# make deps
deps:
@make yarn.deps
@make maven.deps
docs: maven.docs
down: docker.down
up: docker.up
##################
# Maven commands #
##################
# Maven command.
#
# Usage:
# make mvn [task=]
task ?=
maven.image = 3-openjdk-16
maven:
mkdir -p $(PWD)/.m2
./mvnw -Duser.home=$(PWD) $(task)
# clean command
maven.clean:
@make maven task='clean'
# deps command
maven.deps:
@make maven task='dependency:go-offline'
# build command
maven.build:
@make maven task='-Dmaven.test.skip package'
# docs command
maven.docs:
@make maven task='-Dmaven.test.skip javadoc:javadoc'
# test command
maven.test:
@make maven task='test jacoco:report'
####################
# Node.js commands #
####################
# Yarn command.
#
# Usage:
# make yarn [yarn-cmd=]
yarncmd ?=
yarn:
docker run \
--rm \
--user $(shell id -u):$(shell id -g) \
-v "$(PWD)":/app -w /app \
-e YARN_CACHE_FOLDER=/app/_cache/yarn \
node \
yarn --non-interactive $(yarncmd)
# Resolve Yarn project dependencies.
#
# Optional 'cmd' parameter may be used for handy usage of docker-wrapped Yarn,
# for example: make yarn.deps cmd='upgrade'
#
# Usage:
# make yarn.deps [cmd=('install --pure-lockfile'|<yarn-cmd>)]
yarn-deps-cmd = $(if $(call eq,$(cmd),),install --pure-lockfile,$(cmd))
yarn.deps:
@make yarn yarncmd='$(yarn-deps-cmd)'
###################
# Docker commands #
###################
# Execute docker command with needed params.
#
# Usage:
docker.run:
# Stop project in Docker Compose development environment
# and remove all related containers.
#
# Usage:
# make docker.down
docker.down:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ./docker/docker-compose.yml down --rmi=local -v
# Run Docker Compose development environment.
#
# Usage:
# make docker.up [rebuild=(yes|no)]
# [background=(no|yes)]
rebuild ?= yes
background ?= no
docker.up:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ./docker/docker-compose.yml up \
$(if $(call eq,$(rebuild),no),,--build) \
$(if $(call eq,$(background),yes),-d,--abort-on-container-exit)
.PHONY: squash \
clean deps build docs up down \
maven maven.clean maven.docs maven.build maven.deps maven.test \
yarn yarn.deps \
docker.up docker.down