Skip to content

Commit d2cdaff

Browse files
dev: standard makefile tasks for practicalli projects
1 parent 9f2b04b commit d2cdaff

File tree

2 files changed

+95
-57
lines changed

2 files changed

+95
-57
lines changed

CHANGELOG.org

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Unreleased
44

5+
** Updated
6+
- dev: standard makefile tasks for Practicalli projects
57
* 2024-12-19
68
** Added
79

Makefile

+93-57
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# ------------------------------------------
2-
# Makefile: Clojure Service
2+
# Practicalli Makefile
33
#
44
# Consistent set of targets to support local development of Clojure
55
# and build the Clojure service during CI deployment
66
#
7+
# `-` before a command ignores any errors returned
8+
79
# Requirements
810
# - cljstyle
9-
# - Clojure CLI aliases
11+
# - Clojure CLI aliases from practicalli/clojure-cli-config
1012
# - `:env/dev` to include `dev` directory on class path
1113
# - `:env/test` to include `test` directory and libraries to support testing
1214
# - `:test/run` to run kaocha kaocha test runner and supporting paths and dependencies
@@ -33,8 +35,8 @@ HELP-DESCRIPTION-SPACING := 24
3335
# EDN-FILES := $(wildcard *.edn)
3436

3537
# Tool variables
36-
# MEGALINTER_RUNNER = npx mega-linter-runner --flavor documentation --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
37-
MEGALINTER_RUNNER = npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
38+
# MEGALINTER_RUNNER := npx mega-linter-runner --flavor documentation --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
39+
MEGALINTER_RUNNER := npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
3840
# ------------------------------------ #
3941

4042
# ------- Help ----------------------- #
@@ -46,7 +48,7 @@ help: ## Describe available tasks in Makefile
4648
awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-$(HELP-DESCRIPTION-SPACING)s\033[0m %s\n", $$1, $$2}'
4749
# ------------------------------------ #
4850

49-
# ------- Clojure Projects -------- #
51+
# -- Clojure Projects ---------------- #
5052
project-service: ## New project with practicalli/service template
5153
$(info --------- Create Service Project ---------)
5254
clojure -T:project/create :template practicalli/service :name practicalli/gameboard
@@ -70,27 +72,52 @@ landing-page: ## New project with practicalli/landing-page template local
7072
outdated: ## Check deps.edn & GitHub actions for new versions
7173
$(info --------- Search for outdated libraries ---------)
7274
- clojure -T:search/outdated > $(OUTDATED_FILE)
75+
# ------------------------------------ #
7376

7477
# ------- Clojure Workflow -------- #
75-
repl: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
78+
rebel: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
7679
$(info --------- Run Rebel REPL ---------)
77-
clojure -M:test/env:repl/reloaded
78-
80+
clojure -M:dev/env:test/env:repl/rebel
7981

80-
# deps: deps.edn ## Prepare dependencies for test and dist targets
81-
# $(info --------- Download test and service libraries ---------)
82-
# clojure -P -X:build
82+
reloaded: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
83+
$(info --------- Run Rebel REPL ---------)
84+
clojure -M:dev/env:test/env:repl/reloaded
8385

84-
# dist: deps build-uberjar ## Build and package Clojure service
85-
# $(info --------- Build and Package Clojure service ---------)
86+
deps: deps.edn ## Prepare dependencies for test and dist targets
87+
$(info --------- Download test and service libraries ---------)
88+
clojure -P -X:build
8689

87-
# Remove files and directories after build tasks
88-
# `-` before the command ignores any errors returned
89-
clean: ## Clean build temporary files
90+
clean: ## Clean Clojure tooling temporary files
9091
$(info --------- Clean Clojure classpath cache ---------)
9192
- rm -rf ./.cpcache ./.clj-kondo ./.lsp
9293
# ------------------------------------ #
9394

95+
# -------- Build tasks --------------- #
96+
build-config: ## Pretty print build configuration
97+
$(info --------- View current build config ---------)
98+
clojure -T:build config
99+
100+
# build-jar: ## Build a jar archive of Clojure project
101+
$(info --------- Build library jar ---------)
102+
clojure -T:build jar
103+
104+
# build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime
105+
$(info --------- Build service Uberjar ---------)
106+
clojure -T:build uberjar
107+
108+
build-uberjar-echo: ## Build a uberjar archive of Clojure project & Clojure runtime
109+
$(info --------- Build service Uberjar ---------)
110+
$(info Prerequisites newer than target)
111+
echo $?
112+
clojure -T:build uberjar
113+
114+
build-clean: ## Clean build assets or given directory
115+
$(info --------- Clean Build ---------)
116+
clojure -T:build clean
117+
118+
dist: deps build-uberjar ## Build and package Clojure service
119+
# ------------------------------------ #
120+
94121
# ------- Testing -------------------- #
95122
test-config: ## Print Kaocha test runner configuration
96123
$(info --------- Runner Configuration ---------)
@@ -101,39 +128,20 @@ test-profile: ## Profile unit test speed, showing 3 slowest tests
101128
clojure -M:test/env:test/run --plugin kaocha.plugin/profiling
102129

103130
test: ## Run unit tests - stoping on first error
104-
$(info --------- Runner for unit tests ---------)
105-
clojure -X:test/env:test/run
131+
$(info --------- Runner for unit tests ---------)
132+
clojure -X:test/env:test/run
106133

107134
test-all: ## Run all unit tests regardless of failing tests
108-
$(info --------- Runner for all unit tests ---------)
109-
clojure -X:test/env:test/run :fail-fast? false
135+
$(info --------- Runner for all unit tests ---------)
136+
clojure -X:test/env:test/run :fail-fast? false
110137

111138
test-watch: ## Run tests when changes saved, stopping test run on first error
112-
$(info --------- Watcher for unit tests ---------)
113-
clojure -X:test/env:test/run :watch? true
139+
$(info --------- Watcher for unit tests ---------)
140+
clojure -X:test/env:test/run :watch? true
114141

115142
test-watch-all: ## Run all tests when changes saved, regardless of failing tests
116-
$(info --------- Watcher for unit tests ---------)
117-
clojure -X:test/env:test/run :fail-fast? false :watch? true
118-
119-
# ------------------------------------ #
120-
121-
# -------- Build tasks --------------- #
122-
build-config: ## Pretty print build configuration
123-
$(info --------- View current build config ---------)
124-
clojure -T:build config
125-
126-
# build-jar: ## Build a jar archive of Clojure project
127-
# $(info --------- Build library jar ---------)
128-
# clojure -T:build jar
129-
130-
# build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime
131-
# $(info --------- Build service Uberjar ---------)
132-
# clojure -T:build uberjar
133-
134-
build-clean: ## Clean build assets or given directory
135-
$(info --------- Clean Build ---------)
136-
clojure -T:build clean
143+
$(info --------- Watcher for unit tests ---------)
144+
clojure -X:test/env:test/run :fail-fast? false :watch? true
137145

138146
# ------------------------------------ #
139147

@@ -165,41 +173,69 @@ megalinter-upgrade: ## Upgrade MegaLinter config to latest version
165173
npx mega-linter-runner@latest --upgrade
166174
# ------------------------------------ #
167175

176+
# ------- Version Control ------------ #
177+
git-sr: ## status list of git repos under current directory
178+
$(info --------- Multiple Git Status ---------)
179+
mgitstatus -e --flatten
180+
181+
git-status: ## status details of git repos under current directory
182+
$(info --------- Multiple Git Status ---------)
183+
mgitstatus
184+
# ------------------------------------ #
185+
186+
# ------- Documentation Generation ---------- #
187+
docs: ## Run mkdocs server
188+
$(info --------- Mkdocs Local Server ---------)
189+
mkdocs serve --dev-addr localhost:7777
190+
# ------------------------------------ #
191+
168192
# ------- Docker Containers ---------- #
169193
# docker-build: ## Build Clojure project and run with docker compose
170194
# $(info --------- Docker Compose Build ---------)
171195
# docker compose up --build --detach
172196

173197
# docker-build-clean: ## Build Clojure project and run with docker compose, removing orphans
174-
# $(info --------- Docker Compose Build - remove orphans ---------)
175-
# docker compose up --build --remove-orphans --detach
198+
$(info --------- Docker Compose Build - remove orphans ---------)
199+
docker compose up --build --remove-orphans --detach
176200

177201
# docker-down: ## Shut down containers in docker compose
178-
# $(info --------- Docker Compose Down ---------)
179-
# docker compose down
202+
$(info --------- Docker Compose Down ---------)
203+
docker compose down
204+
205+
docker-inspect: ## Inspect given docker image - image-id=12e45fg89
206+
$(info --------- Docker Image Prune ---------)
207+
docker inspect --format='{{json .Config}}' $(image-id) | jq
208+
209+
docker-image-prune: ## Prune docker images
210+
$(info --------- Docker Image Prune ---------)
211+
docker image prune
180212

213+
docker-container-prune: ## Prune docker containers
214+
$(info --------- Docker Container Prune ---------)
215+
docker container prune
181216

182-
# swagger-editor: ## Start Swagger Editor in Docker
183-
# $(info --------- Run Swagger Editor at locahost:8282 ---------)
184-
# docker compose -f swagger-editor.yml up -d swagger-editor
217+
docker-prune: docker-image-prune docker-image-prune ## Prune docker images and containers
185218

186-
# swagger-editor-down: ## Stop Swagger Editor in Docker
187-
# $(info --------- Run Swagger Editor at locahost:8282 ---------)
188-
# docker compose -f swagger-editor.yml down
219+
swagger-editor: ## Start Swagger Editor in Docker
220+
$(info --------- Run Swagger Editor at locahost:8282 ---------)
221+
docker compose -f swagger-editor.yaml up -d swagger-editor --detatch
222+
223+
swagger-editor-down: ## Stop Swagger Editor in Docker
224+
$(info --------- Run Swagger Editor at locahost:8282 ---------)
225+
docker compose -f swagger-editor.yaml down
189226
# ------------------------------------ #
190227

191228
# ------ Continuous Integration ------ #
192229
# .DELETE_ON_ERROR: halts if command returns non-zero exit status
193230
# https://makefiletutorial.com/#delete_on_error
194231

195232
# TODO: focus runner on ^:integration` tests
196-
# test-ci: deps ## Test runner for integration tests
197-
# $(info --------- Runner for integration tests ---------)
198-
# clojure -P -X:test/env:test/run
233+
test-ci: deps ## Test runner for integration tests
234+
$(info --------- Runner for integration tests ---------)
235+
clojure -P -X:test/env:test/run
199236

200237
# Run tests, build & package the Clojure code and clean up afterward
201238
# `make all` used in Docker builder stage
202239
.DELETE_ON_ERROR:
203240
all: test-ci dist clean ## Call test-ci dist and clean targets, used for CI
204-
205241
# ------------------------------------ #

0 commit comments

Comments
 (0)