-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
216 lines (169 loc) · 8.24 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
# -------------------------------------- #
# Practicalli Makefile
#
# Consistent set of targets to support local development of Clojure
# and build the Clojure service during CI deployment
#
# `-` before a command ignores any errors returned
# Requirements
# - cljstyle
# - Clojure CLI aliases
# - `:dev/env` to include `dev` directory on class path
# - `:test/env` to include `test` directory and libraries to support testing
# - `:test/run` to run kaocha kaocha test runner and supporting paths and dependencies
# - `:repl/rebel` to start a Rebel terminal UI
# - `:build/task` to build this project into a jar or uberjar
# - docker
# - mega-linter-runner
# -------------------------------------- #
# -- Makefile task config -------------- #
# .PHONY: ensures target used rather than matching file name
# https://makefiletutorial.com/#phony
.PHONY: all clean deps dist docs lint pre-commit-check repl test test-ci test-watch
# -------------------------------------- #
# -- Makefile Variables ---------------- #
# run help if no target specified
.DEFAULT_GOAL := help
# Column the target description is printed from
HELP-DESCRIPTION-SPACING := 24
# Tool variables
CLOJURE_TEST_RUNNER = clojure -M:test/env:test/run
CLOJURE_EXEC_TEST_RUNNER = clojure -X:test/env:test/run
DOCKER-BUILD-LOGFILE := docker-build-log-$(shell date +%y-%m-%d-%T).md
MEGALINTER_RUNNER := npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
OUTDATED_FILE := outdated-$(shell date +%y-%m-%d-%T).md
# Makefile file and directory name wildcard
# EDN-FILES := $(wildcard *.edn)
# ------------------------------------ #
# -- Help ------------------------------ #
# Source: https://nedbatchelder.com/blog/201804/makefile_help_target.html
help: ## Describe available tasks in Makefile
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
sort | \
awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-$(HELP-DESCRIPTION-SPACING)s\033[0m %s\n", $$1, $$2}'
# -------------------------------------- #
# -- Clojure Workflow ------------------ #
repl: rebel ## Start default REPL configuration
rebel: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
$(info -- Run Rebel REPL ------------------------)
clojure -M:dev/env:test/env:repl/rebel
reloaded: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
$(info -- Run Rebel REPL ------------------------)
clojure -M:repl/reloaded
deps: deps.edn ## Prepare dependencies for test and dist targets
$(info -- Download test and service libraries ---)
clojure -P -M:test/run && clojure -P -T:build/task
dist: build-uberjar ## Build and package Clojure service
$(info -- Build and Package Clojure service -----)
clean: ## Clean Clojure tooling temporary files
$(info -- Clean Clojure temporary files ---------)
- rm -rf ./.cpcache ./.clj-kondo/cache ./.lsp
run: ## Run Service using clojure.main
$(info -- Download test and service libraries ---)
clojure -M:run/service
outdated: ## Check deps.edn & GitHub actions for new versions
$(info -- Search for outdated libraries ---------)
- clojure -T:search/outdated > $(OUTDATED_FILE)
# -------------------------------------- #
# -- Testing --------------------------- #
test-config: ## Print Kaocha test runner configuration
$(info -- Runner Configuration ------------------)
$(CLOJURE_TEST_RUNNER) --print-config
test-profile: ## Profile unit test speed, showing 3 slowest tests
$(info -- Runner Profile Tests ------------------)
$(CLOJURE_TEST_RUNNER) --plugin kaocha.plugin/profiling
test: ## Run unit tests - stoping on first error
$(info -- Runner for unit tests -----------------)
$(CLOJURE_EXEC_TEST_RUNNER)
test-all: ## Run all unit tests regardless of failing tests
$(info -- Runner for all unit tests -------------)
$(CLOJURE_EXEC_TEST_RUNNER) :fail-fast? false
test-watch: ## Run tests when changes saved, stopping test run on first error
$(info -- Watcher for unit tests, fail fast -----)
$(CLOJURE_EXEC_TEST_RUNNER) :watch? true
test-watch-all: ## Run all tests when changes saved, regardless of failing tests
$(info -- Watcher for unit tests ----------------)
$(CLOJURE_EXEC_TEST_RUNNER) :fail-fast? false :watch? true
# -------------------------------------- #
# -- Build tasks ----------------------- #
build-config: ## Pretty print build configuration
$(info --------- View current build config ------)
clojure -T:build/task config
build-jar: ## Build a jar archive of Clojure project
$(info --------- Build library jar --------------)
clojure -T:build/task jar
build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime
$(info --------- Build service Uberjar ---------)
clojure -T:build/task uberjar
build-uberjar-echo: ## Build a uberjar archive of Clojure project & Clojure runtime
$(info -- Build service Uberjar ----------------)
$(info -- Prerequisites newer than target -------)
echo $?
clojure -T:build/task uberjar
build-clean: ## Clean build assets or given directory
$(info -- Clean Build --------------------------)
clojure -T:build/task clean
# -------------------------------------- #
# -- Code Quality ---------------------- #
pre-commit-check: format-check lint test ## Run format, lint and test targets
format-check: ## Run cljstyle to check the formatting of Clojure code
$(info -- cljstyle Runner show errors -----------)
cljstyle check
format-fix: ## Run cljstyle and fix the formatting of Clojure code
$(info -- cljstyle Runner fix errors ------------)
cljstyle fix
lint: ## Run MegaLinter with custom configuration (node.js required)
$(info -- MegaLinter Runner ---------------------)
$(MEGALINTER_RUNNER)
lint-fix: ## Run MegaLinter with applied fixes and custom configuration (node.js required)
$(info -- MegaLinter Runner fix errors ----------)
$(MEGALINTER_RUNNER) --fix
lint-clean: ## Clean MegaLinter report information
$(info -- MegaLinter Clean Reports --------------)
- rm -rf ./megalinter-reports
megalinter-upgrade: ## Update MegaLinter config to latest version
$(info --------- MegaLinter Upgrade Config ---------)
npx mega-linter-runner@latest --upgrade
# -------------------------------------- #
# -- Docker Containers ----------------- #
docker-build: ## Build Clojure project and run with docker compose
$(info -- Docker Compose Build ------------------)
docker compose up --build --detach
docker-build-log: ## Build Clojure project and run with docker compose - log to file
$(info --------- Docker Compose Build ---------)
docker compose up --build --detach &> $(DOCKER-BUILD-LOGFILE) | tee $(DOCKER-BUILD-LOGFILE)
docker-build-clean: ## Build Clojure project and run with docker compose, removing orphans
$(info -- Docker Compose Build, remove orphans --)
docker compose up --build --remove-orphans --detach
docker-down: ## Shut down containers in docker compose
$(info -- Docker Compose Down -------------------)
docker compose down
docker-inspect: ## Inspect given docker image - image-id=12e45fg89
$(info -- Docker Image Prune --------------------)
docker inspect --format='{{json .Config}}' $(image-id) | jq
docker-image-prune: ## Prune docker images
$(info -- Docker Image Prune --------------------)
docker image prune
docker-container-prune: ## Prune docker containers
$(info -- Docker Container Prune ----------------)
docker container prune
docker-prune: docker-image-prune docker-image-prune ## Prune docker images and containers
swagger-editor: ## Start Swagger Editor in Docker
$(info -- Run Swagger Editor at locahost:8282 ---)
docker compose -f swagger-editor.yaml up -d swagger-editor --detatch
swagger-editor-down: ## Stop Swagger Editor in Docker
$(info -- Run Swagger Editor at locahost:8282 ---)
docker compose -f swagger-editor.yaml down
# -------------------------------------- #
# -- Continuous Integration ------------ #
# .DELETE_ON_ERROR: halts if command returns non-zero exit status
# https://makefiletutorial.com/#delete_on_error
# TODO: focus runner on ^:integration` tests
test-ci: deps ## Test runner for integration tests
$(info -- Runner for integration tests ---------)
clojure -P -X:test/env:test/run
# Run tests, build & package the Clojure code and clean up afterward
# `make all` used in Docker builder stage
.DELETE_ON_ERROR:
all: test-ci dist clean ## Call test-ci dist and clean targets, used for CI
# -------------------------------------- #