|
| 1 | +# ------------------------------------------ |
| 2 | +# Makefile: Clojure Service |
| 3 | +# |
| 4 | +# Consistent set of targets to support local development of Clojure |
| 5 | +# and build the Clojure service during CI deployment |
| 6 | +# |
| 7 | +# Requirements |
| 8 | +# - cljstyle |
| 9 | +# - Clojure CLI aliases |
| 10 | +# - `:env/dev` to include `dev` directory on class path |
| 11 | +# - `:env/test` to include `test` directory and libraries to support testing |
| 12 | +# - `:test/run` to run kaocha kaocha test runner and supporting paths and dependencies |
| 13 | +# - `:repl/rebel` to start a Rebel terminal UI |
| 14 | +# - `:package/uberjar` to create an uberjar for the service |
| 15 | +# - docker |
| 16 | +# - mega-linter-runner |
| 17 | +# |
| 18 | +# ------------------------------------------ |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +# .PHONY: ensures target used rather than matching file name |
| 23 | +# https://makefiletutorial.com/#phony |
| 24 | +.PHONY: all lint deps dist pre-commit-check repl test clean |
| 25 | + |
| 26 | + |
| 27 | +# ------- Makefile Variables --------- # |
| 28 | + |
| 29 | +# run help if no target specified |
| 30 | +.DEFAULT_GOAL := help |
| 31 | + |
| 32 | +# Column the target description is printed from |
| 33 | +HELP-DESCRIPTION-SPACING := 24 |
| 34 | + |
| 35 | +# Makefile file and directory name wildcard |
| 36 | +# EDN-FILES := $(wildcard *.edn) |
| 37 | + |
| 38 | +# ------------------------------------ # |
| 39 | + |
| 40 | + |
| 41 | +# ------- Help ----------------------- # |
| 42 | + |
| 43 | +# Source: https://nedbatchelder.com/blog/201804/makefile_help_target.html |
| 44 | + |
| 45 | +help: ## Describe available tasks in Makefile |
| 46 | + @grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \ |
| 47 | + sort | \ |
| 48 | + awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-$(HELP-DESCRIPTION-SPACING)s\033[0m %s\n", $$1, $$2}' |
| 49 | + |
| 50 | +# ------------------------------------ # |
| 51 | + |
| 52 | + |
| 53 | +# ------- Clojure Development -------- # |
| 54 | + |
| 55 | +repl: ## Run Clojure REPL with rich terminal UI (Rebel Readline) |
| 56 | + $(info --------- Run Rebel REPL ---------) |
| 57 | + clojure -M:test/env:repl/reloaded |
| 58 | + |
| 59 | +outdated: ## Check deps.edn & GitHub actions for new versions |
| 60 | + $(info --------- Search for outdated libraries ---------) |
| 61 | + clojure -T:search/outdated > outdated-$(date +"%y-%m-%d-%T").org |
| 62 | + |
| 63 | + |
| 64 | +# deps: deps.edn ## Prepare dependencies for test and dist targets |
| 65 | +# $(info --------- Download test and service libraries ---------) |
| 66 | +# clojure -P -X:build |
| 67 | + |
| 68 | + |
| 69 | +# dist: deps build-uberjar ## Build and package Clojure service |
| 70 | +# $(info --------- Build and Package Clojure service ---------) |
| 71 | + |
| 72 | + |
| 73 | +# Remove files and directories after build tasks |
| 74 | +# `-` before the command ignores any errors returned |
| 75 | +clean: ## Clean build temporary files |
| 76 | + $(info --------- Clean Clojure classpath cache ---------) |
| 77 | + - rm -rf ./.cpcache |
| 78 | + |
| 79 | +# ------------------------------------ # |
| 80 | + |
| 81 | + |
| 82 | +# ------- Testing -------------------- # |
| 83 | + |
| 84 | +# test-config: ## Print Kaocha test runner configuration |
| 85 | +# $(info --------- Runner Configuration ---------) |
| 86 | +# clojure -M:test/env:test/run --print-config |
| 87 | + |
| 88 | +# test-profile: ## Profile unit test speed, showing 3 slowest tests |
| 89 | +# $(info --------- Runner Profile Tests ---------) |
| 90 | +# clojure -M:test/env:test/run --plugin kaocha.plugin/profiling |
| 91 | + |
| 92 | +# test: ## Run unit tests - stoping on first error |
| 93 | +# $(info --------- Runner for unit tests ---------) |
| 94 | +# clojure -X:test/env:test/run |
| 95 | + |
| 96 | + |
| 97 | +# test-all: ## Run all unit tests regardless of failing tests |
| 98 | +# $(info --------- Runner for all unit tests ---------) |
| 99 | +# clojure -X:test/env:test/run :fail-fast? false |
| 100 | + |
| 101 | +# test-watch: ## Run tests when changes saved, stopping test run on first error |
| 102 | +# $(info --------- Watcher for unit tests ---------) |
| 103 | +# clojure -X:test/env:test/run :watch? true |
| 104 | + |
| 105 | +# test-watch-all: ## Run all tests when changes saved, regardless of failing tests |
| 106 | +# $(info --------- Watcher for unit tests ---------) |
| 107 | +# clojure -X:test/env:test/run :fail-fast? false :watch? true |
| 108 | + |
| 109 | +# ------------------------------------ # |
| 110 | + |
| 111 | + |
| 112 | +# -------- Build tasks --------------- # |
| 113 | +# build-config: ## Pretty print build configuration |
| 114 | +# $(info --------- View current build config ---------) |
| 115 | +# clojure -T:build config |
| 116 | + |
| 117 | +# build-jar: ## Build a jar archive of Clojure project |
| 118 | +# $(info --------- Build library jar ---------) |
| 119 | +# clojure -T:build jar |
| 120 | + |
| 121 | +# build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime |
| 122 | +# $(info --------- Build service Uberjar ---------) |
| 123 | +# clojure -T:build uberjar |
| 124 | + |
| 125 | +# build-clean: ## Clean build assets or given directory |
| 126 | +# $(info --------- Clean Build ---------) |
| 127 | +# clojure -T:build clean |
| 128 | + |
| 129 | +# ------------------------------------ # |
| 130 | + |
| 131 | +# ------- Code Quality --------------- # |
| 132 | + |
| 133 | +pre-commit-check: format-check lint test ## Run format, lint and test targets |
| 134 | + |
| 135 | + |
| 136 | +format-check: ## Run cljstyle to check the formatting of Clojure code |
| 137 | + $(info --------- cljstyle Runner ---------) |
| 138 | + cljstyle check |
| 139 | + |
| 140 | + |
| 141 | +format-fix: ## Run cljstyle and fix the formatting of Clojure code |
| 142 | + $(info --------- cljstyle Runner ---------) |
| 143 | + cljstyle fix |
| 144 | + |
| 145 | +lint: ## Run MegaLinter with custom configuration (node.js required) |
| 146 | + $(info --------- MegaLinter Runner ---------) |
| 147 | + npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container |
| 148 | + |
| 149 | +lint-clean: ## Clean MegaLinter report information |
| 150 | + $(info --------- MegaLinter Clean Reports ---------) |
| 151 | + - rm -rf ./megalinter-reports |
| 152 | + |
| 153 | +# ------------------------------------ # |
| 154 | + |
| 155 | + |
| 156 | +# ------- Docker Containers ---------- # |
| 157 | + |
| 158 | +# docker-build: ## Build Clojure Service with docker compose |
| 159 | +# $(info --------- Docker Compose Build ---------) |
| 160 | +# docker compose up --build |
| 161 | + |
| 162 | +# docker-build-clean: ## Build Clojure Service with docker compose, removing orphans |
| 163 | +# $(info --------- Docker Compose Build - remove orphans ---------) |
| 164 | +# docker compose up --build --remove-orphans |
| 165 | + |
| 166 | +# docker-down: ## Shut down Clojure service using docker compose |
| 167 | +# $(info --------- Docker Compose Down ---------) |
| 168 | +# docker-compose down |
| 169 | + |
| 170 | + |
| 171 | +# swagger-editor: ## Start Swagger Editor in Docker |
| 172 | +# $(info --------- Run Swagger Editor at locahost:8282 ---------) |
| 173 | +# docker compose -f swagger-editor.yml up -d swagger-editor |
| 174 | + |
| 175 | +# swagger-editor-down: ## Stop Swagger Editor in Docker |
| 176 | +# $(info --------- Run Swagger Editor at locahost:8282 ---------) |
| 177 | +# docker compose -f swagger-editor.yml down |
| 178 | + |
| 179 | +# ------------------------------------ # |
| 180 | + |
| 181 | + |
| 182 | +# ------ Continuous Integration ------ # |
| 183 | + |
| 184 | +# .DELETE_ON_ERROR: halts if command returns non-zero exit status |
| 185 | +# https://makefiletutorial.com/#delete_on_error |
| 186 | + |
| 187 | + |
| 188 | +# TODO: focus runner on ^:integration` tests |
| 189 | +# test-ci: deps ## Test runner for integration tests |
| 190 | +# $(info --------- Runner for integration tests ---------) |
| 191 | +# clojure -P -X:test/env:test/run |
| 192 | + |
| 193 | + |
| 194 | +# Run tests, build & package the Clojure code and clean up afterward |
| 195 | +# `make all` used in Docker builder stage |
| 196 | +# .DELETE_ON_ERROR: |
| 197 | +# all: test-ci dist clean ## Call test-ci dist and clean targets, used for CI |
| 198 | + |
| 199 | +# ------------------------------------ # |
0 commit comments