-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
363 lines (332 loc) · 15.1 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# -----------------------------------------------------------------------------
# This makefile sets the most common targets found in a typical Makefile.
#
# Notable file modification history (see commits in each repository for details):
# 2022-06-06: Created for https://github.com/olivr/template-repo
#
# Copyright 2022 Romain Barissat. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
.DEFAULT_GOAL:=list
# -----------------------------------------------------------------------------
# Configuration options
# -----------------------------------------------------------------------------
JS_INSTALLER:=yarn# Could be "npm"
# -----------------------------------------------------------------------------
# Tools
# -----------------------------------------------------------------------------
GITLEAKS:=$(shell [[ $$(command -v gitleaks 2> /dev/null) ]]\
&& echo "gitleaks" || echo\
"docker run -v $$PWD:/project zricethezav/gitleaks:latest --source /project"\
)
MAKE_DOCS:=$(shell [[ $$(command -v make-docs 2> /dev/null) ]]\
&& echo "make-docs" || echo "npx make-docs"\
)
ACTION_LINT:=$(shell [[ $$(command -v actionlint 2> /dev/null) ]]\
&& echo "actionlint" || echo\
"docker run -v $$PWD:/project --workdir /project rhysd/actionlint:latest"\
)
YAML_LINT:=$(shell [[ $$(command -v yamllint 2> /dev/null) ]]\
&& echo 'yamllint "."'\
|| echo '@echo "⚠️ Skipping Yamllint: not installed."'\
)
HOMEBREW_INSTALLED:=$(shell command -v brew 2> /dev/null)
JS_INSTALLER_INSTALLED:=$(shell command -v $(JS_INSTALLER) 2> /dev/null)
# -----------------------------------------------------------------------------
# List all phony targets of this Makefile
# -----------------------------------------------------------------------------
.PHONY: list
list:
@${MAKE_DOCS} --format console --sort "."
# -----------------------------------------------------------------------------
# Setup developer environment
#
# - Install the developer dependencies listed in `Brewfile` and `package.json`
# - Setup the git pre-commit hooks
# -----------------------------------------------------------------------------
.PHONY: setup
setup:
@echo -----------------------------------------------------------------------
@echo -- Setup developer environment
@echo -----------------------------------------------------------------------
ifdef HOMEBREW_INSTALLED
ifeq ($(CI),true)
brew bundle
else
@echo "Do you want to install dependencies with Homebrew? [Y/n] ";\
read ANSWER;\
if [[ $${ANSWER:-Y} == Y ]]; then brew bundle; fi;
endif
else
@echo "Homebrew is not installed. \
Skipping automated dependencies installation."
endif
ifdef JS_INSTALLER_INSTALLED
$(JS_INSTALLER) install
else
@echo "$(JS_INSTALLER) is not installed. \
Skipping JS dependencies installation."
endif
pre-commit install --install-hooks -t pre-commit -t commit-msg
@echo
# -----------------------------------------------------------------------------
# Build {{project_name}}
# -----------------------------------------------------------------------------
.PHONY: build
build:
@echo -----------------------------------------------------------------------
@echo -- Build {{project_name}}
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'build' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Remove all {{project_name}} build files
# -----------------------------------------------------------------------------
.PHONY: clean
clean: docs-clean
@echo -----------------------------------------------------------------------
@echo -- Remove all {{project_name}} build files
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'clean' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Lint source code
# Lint the whole code base, respecting .gitignore rules.
# -----------------------------------------------------------------------------
.PHONY: lint
lint:
@echo -----------------------------------------------------------------------
@echo -- Lint source code
@echo -----------------------------------------------------------------------
npx prettier --ignore-path .gitignore --loglevel warn --check "."
npx textlint --ignore-path .gitignore "." ".*/*"
npx markdownlint --ignore-path .gitignore --dot "."
${YAML_LINT}
pre-commit run check-dependabot --all-files
pre-commit run check-renovate --all-files
${ACTION_LINT}
${GITLEAKS} detect --log-level warn
@echo
# -----------------------------------------------------------------------------
# Fix linting errors in source code
# -----------------------------------------------------------------------------
.PHONY: fix
fix:
@echo -----------------------------------------------------------------------
@echo -- Fix linting errors in source code
@echo -----------------------------------------------------------------------
npx prettier --ignore-path .gitignore --loglevel warn --write "."
npx textlint --ignore-path .gitignore --fix "." ".*/*"
npx markdownlint --ignore-path .gitignore --fix --dot "."
@echo
# -----------------------------------------------------------------------------
# Run all test suites
# -----------------------------------------------------------------------------
.PHONY: test
test: test-unit test-integration
# -----------------------------------------------------------------------------
# Run unit tests
# -----------------------------------------------------------------------------
.PHONY: test-unit
test-unit:
@echo -----------------------------------------------------------------------
@echo -- Run unit tests
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'test-unit' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Run integration tests
# -----------------------------------------------------------------------------
.PHONY: test-integration
test-integration:
@echo -----------------------------------------------------------------------
@echo -- Run integration tests
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'test-integration' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Run {{project_name}} in debug mode
# -----------------------------------------------------------------------------
.PHONY: debug
debug:
@echo -----------------------------------------------------------------------
@echo -- Run {{project_name}} in debug mode
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'debug' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Run {{project_name}} and watch for changes
# -----------------------------------------------------------------------------
.PHONY: watch
watch:
@echo -----------------------------------------------------------------------
@echo -- Run {{project_name}} and watch for changes
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'watch' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Run {{project_name}}
# -----------------------------------------------------------------------------
.PHONY: run
run:
@echo -----------------------------------------------------------------------
@echo -- Run {{project_name}}
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'run' target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Install {{project_name}} locally
# It is used for projects that can be installed on a workstation (ie. locally).
# -----------------------------------------------------------------------------
.PHONY: install
install:
@echo -----------------------------------------------------------------------
@echo -- Install {{project_name}} locally
@echo -----------------------------------------------------------------------
@echo "ℹ️ The 'install' target has not been configured yet."
@echo "It is used for projects that can be installed on a workstation."
@echo
# -----------------------------------------------------------------------------
# Uninstall {{project_name}} locally
# It is used to uninstall {{project_name}} from the workstation.
# -----------------------------------------------------------------------------
.PHONY: uninstall
uninstall:
@echo -----------------------------------------------------------------------
@echo -- Uninstall {{project_name}} locally
@echo -----------------------------------------------------------------------
@echo "ℹ️ The uninstall target has not been configured yet."
@echo "It is used for projects that can be installed on a workstation."
@echo
# -----------------------------------------------------------------------------
# Release new version of {{project_name}}
# -----------------------------------------------------------------------------
.PHONY: release
release:
@echo -----------------------------------------------------------------------
@echo -- Release new version of {{project_name}}
@echo -----------------------------------------------------------------------
@echo "ℹ️ The release target has not been configured yet."
@echo
# -----------------------------------------------------------------------------
# Deploy latest version of {{project_name}}
# It is used for projects that can be deployed on a server (ie. remotely).
# -----------------------------------------------------------------------------
.PHONY: deploy
deploy:
@echo -----------------------------------------------------------------------
@echo -- Deploy latest version of {{project_name}}
@echo -----------------------------------------------------------------------
@echo "ℹ️ The deploy target has not been configured yet."
@echo "It is used for projects that can be deployed on a server."
@echo
# -----------------------------------------------------------------------------
# Generate Markdown documentation
# -----------------------------------------------------------------------------
.PHONY: docs
docs:
@echo -----------------------------------------------------------------------
@echo -- Generate Markdown documentation
@echo -----------------------------------------------------------------------
@${MAKE_DOCS} --sort --inject docs/developer-workflow.md "."
# -----------------------------------------------------------------------------
# Build documentation site
# -----------------------------------------------------------------------------
.PHONY: docs-build
docs-build: docs-clean
@echo -----------------------------------------------------------------------
@echo -- Building documentation site
@echo -----------------------------------------------------------------------
npx vitepress build
@echo
# -----------------------------------------------------------------------------
# Watch documentation site
# -----------------------------------------------------------------------------
.PHONY: docs-watch
docs-watch:
@echo -----------------------------------------------------------------------
@echo -- Watch documentation site
@echo -----------------------------------------------------------------------
npx vitepress dev
@echo
# -----------------------------------------------------------------------------
# Remove all documentation site build files
# -----------------------------------------------------------------------------
.PHONY: docs-clean
docs-clean:
@echo -----------------------------------------------------------------------
@echo -- Remove all documentation site build files
@echo -----------------------------------------------------------------------
rm -rf .vitepress/dist
@echo
# -----------------------------------------------------------------------------
# Run documentation site locally
# -----------------------------------------------------------------------------
.PHONY: docs-run
docs-run:
@echo -----------------------------------------------------------------------
@echo -- Run documentation site locally
@echo -----------------------------------------------------------------------
# Using port 5001 because 5000 is already taken on MacOS Monterey.
npx vitepress serve --port 5001
@echo
# -----------------------------------------------------------------------------
# Deploy documentation site
# -----------------------------------------------------------------------------
GIT_URL:=$(shell git config --get remote.origin.url)
.PHONY: docs-deploy
docs-deploy: docs-build
@echo -----------------------------------------------------------------------
@echo -- Deploy documentation site
@echo -----------------------------------------------------------------------
@$(shell [[ -e "CNAME" ]] && cp "CNAME" ".vitepress/dist/CNAME")
@$(shell [[ -e "docs/CNAME" ]] && cp "docs/CNAME" ".vitepress/dist/CNAME")
ifeq ($(GITHUB_ACTIONS),true)
cd .vitepress/dist\
&& git init --initial-branch gh-pages\
&& git remote add origin\
https://x-access-token:$(GITHUB_TOKEN)@github.com/$(GITHUB_REPOSITORY)\
&& git add --all\
&& git commit --message 'chore: deploy documentation site'\
&& git push --force origin gh-pages:gh-pages
else
cd .vitepress/dist\
&& git init --initial-branch gh-pages\
&& git add --all\
&& git commit --message 'chore: deploy documentation site'\
&& git push --force $(GIT_URL) gh-pages:gh-pages
endif
@echo
# -----------------------------------------------------------------------------
# Test developer workflow
#
# Test a typical developer workflow by running all non-destructive commands.
# These are commands that don't change a remote state (eg. deploy) nor hang the
# shell (eg. watch).
# -----------------------------------------------------------------------------
.PHONY: test-workflow
test-workflow: setup lint fix build test-unit install uninstall docs docs-build docs-clean clean
@echo -----------------------------------------------------------------------
@echo -- Test developer workflow
@echo -----------------------------------------------------------------------
@git stash || true
temp_file=$$(mktemp ./XXXXXX) \
&& echo "Test\n" > $$temp_file \
&& git add $$temp_file \
&& git commit -m"chore: test dev workflow" \
&& git reset --soft HEAD^ \
&& git restore --staged $$temp_file \
&& rm -f $$temp_file
@git stash apply --index || true
@echo