Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
234 lines (193 loc) · 9.09 KB
/
Copy pathMakefile
File metadata and controls
234 lines (193 loc) · 9.09 KB
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
# SPDX-License-Identifier: Apache-2.0
# ---------------------------------------------------------------------------
# Makefile — ComplyTime website developer workflow
#
# Quick reference:
# make help — list all targets
# make sync-dry — dry-run content sync (reads GitHub, writes nothing)
# make sync — apply content sync to disk
# make dev — start Hugo dev server (after syncing content)
# make check — vet + fmt-check + race tests
# ---------------------------------------------------------------------------
# Overridable variables
ORG ?= complytime
CONFIG ?= sync-config.yaml
LOCK ?= .content-lock.json
OUTPUT ?= .
WORKERS ?= 5
TIMEOUT ?= 3m
REPO ?=
SYNC_BIN := cmd/sync-content/sync-content
SYNC_PKG := ./cmd/sync-content/...
HUGO_CACHEDIR ?= /tmp/hugo_cache_complytime
# Common flags passed to every sync invocation
SYNC_FLAGS := --org $(ORG) --config $(CONFIG) --output $(OUTPUT) --workers $(WORKERS) --timeout $(TIMEOUT)
ifdef REPO
SYNC_FLAGS += --repo $(REPO)
endif
.DEFAULT_GOAL := help
# ---------------------------------------------------------------------------
# Prerequisite checks — verify required tools before running targets
# ---------------------------------------------------------------------------
REQUIRED_GO_VERSION := 1.25
REQUIRED_NODE_VERSION := 22
REQUIRED_HUGO_VERSION := 0.164.0
.PHONY: _check-go _check-npm _check-hugo _check-node-version _check-go-version _check-hugo-version
_check-go:
@command -v go >/dev/null 2>&1 || { \
echo "Error: 'go' is not installed (need >= $(REQUIRED_GO_VERSION))."; \
echo " See https://go.dev/dl/"; \
exit 1; \
}
_check-go-version: _check-go
@GO_VER=$$(go version | sed -E 's/.*go([0-9]+\.[0-9]+).*/\1/'); \
GO_MAJOR=$$(echo "$$GO_VER" | cut -d. -f1); \
GO_MINOR=$$(echo "$$GO_VER" | cut -d. -f2); \
REQ_MAJOR=$$(echo "$(REQUIRED_GO_VERSION)" | cut -d. -f1); \
REQ_MINOR=$$(echo "$(REQUIRED_GO_VERSION)" | cut -d. -f2); \
if [ "$$GO_MAJOR" -lt "$$REQ_MAJOR" ] || \
{ [ "$$GO_MAJOR" -eq "$$REQ_MAJOR" ] && [ "$$GO_MINOR" -lt "$$REQ_MINOR" ]; }; then \
echo "Error: Go $$GO_VER found, but >= $(REQUIRED_GO_VERSION) is required."; \
exit 1; \
fi
_check-npm:
@command -v npm >/dev/null 2>&1 || { \
echo "Error: 'npm' is not installed. Install Node.js >= $(REQUIRED_NODE_VERSION) from https://nodejs.org/"; \
exit 1; \
}
_check-node-version: _check-npm
@NODE_MAJOR=$$(node --version | sed -E 's/^v([0-9]+)\..*/\1/'); \
if [ "$$NODE_MAJOR" -lt "$(REQUIRED_NODE_VERSION)" ]; then \
echo "Error: Node.js v$$NODE_MAJOR found, but >= v$(REQUIRED_NODE_VERSION) is required."; \
exit 1; \
fi
_check-hugo:
@command -v hugo >/dev/null 2>&1 || { \
echo "Error: 'hugo' is not installed (need >= $(REQUIRED_HUGO_VERSION), extended edition)."; \
echo " Install the extended edition:"; \
echo " brew install hugo # macOS (extended by default)"; \
echo " sudo snap install hugo --channel=extended # Ubuntu/Debian"; \
echo " CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@v$(REQUIRED_HUGO_VERSION) # from source"; \
echo " Or download hugo_extended_* from https://github.com/gohugoio/hugo/releases"; \
exit 1; \
}
_check-hugo-version: _check-hugo
@HUGO_RAW=$$(hugo version); \
HUGO_VER=$$(echo "$$HUGO_RAW" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+).*/\1/'); \
HUGO_MAJOR=$$(echo "$$HUGO_VER" | cut -d. -f1); \
HUGO_MINOR=$$(echo "$$HUGO_VER" | cut -d. -f2); \
HUGO_PATCH=$$(echo "$$HUGO_VER" | cut -d. -f3); \
REQ_MAJOR=$$(echo "$(REQUIRED_HUGO_VERSION)" | cut -d. -f1); \
REQ_MINOR=$$(echo "$(REQUIRED_HUGO_VERSION)" | cut -d. -f2); \
REQ_PATCH=$$(echo "$(REQUIRED_HUGO_VERSION)" | cut -d. -f3); \
if [ "$$HUGO_MAJOR" -lt "$$REQ_MAJOR" ] || \
{ [ "$$HUGO_MAJOR" -eq "$$REQ_MAJOR" ] && [ "$$HUGO_MINOR" -lt "$$REQ_MINOR" ]; } || \
{ [ "$$HUGO_MAJOR" -eq "$$REQ_MAJOR" ] && [ "$$HUGO_MINOR" -eq "$$REQ_MINOR" ] && [ "$$HUGO_PATCH" -lt "$$REQ_PATCH" ]; }; then \
echo "Error: Hugo $$HUGO_VER found, but >= $(REQUIRED_HUGO_VERSION) is required."; \
echo " See https://github.com/gohugoio/hugo/releases"; \
exit 1; \
fi; \
if ! echo "$$HUGO_RAW" | grep -qi 'extended'; then \
echo "Error: Hugo $$HUGO_VER is installed, but the extended edition is required for SCSS support."; \
echo " Your version: $$HUGO_RAW"; \
echo " Install the extended edition:"; \
echo " brew install hugo # macOS (extended by default)"; \
echo " sudo snap install hugo --channel=extended # Ubuntu/Debian"; \
echo " CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@v$(REQUIRED_HUGO_VERSION) # from source"; \
echo " Or download hugo_extended_* from https://github.com/gohugoio/hugo/releases"; \
exit 1; \
fi
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
.PHONY: help
help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} \
/^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
# ---------------------------------------------------------------------------
# Go — build, test, lint
# ---------------------------------------------------------------------------
.PHONY: build
build: _check-go-version ## Compile the sync-content binary
go build -o $(SYNC_BIN) ./cmd/sync-content
.PHONY: test
test: _check-go-version ## Run all Go unit tests
go test $(SYNC_PKG)
.PHONY: test-race
test-race: _check-go-version ## Run Go tests with the race detector
go test -race $(SYNC_PKG)
.PHONY: vet
vet: _check-go-version ## Run go vet
go vet $(SYNC_PKG)
.PHONY: fmt
fmt: _check-go-version ## Format Go source files with gofmt
gofmt -w cmd/sync-content/
.PHONY: fmt-check
fmt-check: _check-go-version ## Check Go formatting (non-destructive)
@out=$$(gofmt -l cmd/sync-content/); \
if [ -n "$$out" ]; then \
echo "The following files need formatting:"; \
echo "$$out"; \
exit 1; \
fi
.PHONY: check
check: vet fmt-check test-race ## Run vet + fmt-check + race tests (CI equivalent)
# ---------------------------------------------------------------------------
# Content sync — uses GITHUB_TOKEN from the environment
# ---------------------------------------------------------------------------
.PHONY: sync-dry
sync-dry: build ## Dry-run content sync — reads GitHub, writes nothing to disk
./$(SYNC_BIN) $(SYNC_FLAGS)
.PHONY: sync
sync: build ## Apply content sync to disk (--write)
./$(SYNC_BIN) $(SYNC_FLAGS) --write
.PHONY: sync-locked
sync-locked: build ## Apply content sync at approved SHAs from .content-lock.json
./$(SYNC_BIN) $(SYNC_FLAGS) --lock $(LOCK) --write
.PHONY: sync-update-lock
sync-update-lock: build ## Refresh .content-lock.json with current upstream SHAs (no content write)
./$(SYNC_BIN) $(SYNC_FLAGS) --lock $(LOCK) --update-lock
.PHONY: sync-single-dry
sync-single-dry: ## Dry-run sync for one repo (REPO=complytime/complyctl)
@if [ -z "$(REPO)" ]; then echo "Usage: make sync-single-dry REPO=complytime/<name>"; exit 1; fi
$(MAKE) sync-dry REPO=$(REPO)
.PHONY: sync-single
sync-single: ## Apply sync for one repo (REPO=complytime/complyctl)
@if [ -z "$(REPO)" ]; then echo "Usage: make sync-single REPO=complytime/<name>"; exit 1; fi
$(MAKE) sync REPO=$(REPO)
# ---------------------------------------------------------------------------
# Hugo / Node — site build and dev server
# ---------------------------------------------------------------------------
.PHONY: node-install
node-install: _check-node-version ## Install Node dependencies (npm install)
npm install
.PHONY: dev
dev: _check-node-version _check-hugo-version ## Start the Hugo dev server (runs: npm run dev)
npm run dev
.PHONY: site-build
site-build: _check-node-version _check-hugo-version ## Build the Hugo site (runs: hugo --minify --gc)
npm run build
.PHONY: preview
preview: sync site-build ## Full preview: sync content then build the site
# ---------------------------------------------------------------------------
# Housekeeping
# ---------------------------------------------------------------------------
.PHONY: clean
clean: ## Remove the compiled sync-content binary
rm -f $(SYNC_BIN)
.PHONY: clean-build
clean-build: _check-node-version _check-hugo-version ## Remove Hugo output + resource cache, then rebuild (CI match)
rm -rf public/ resources/
npm run build
.PHONY: clean-nuclear
clean-nuclear: _check-node-version _check-hugo-version ## Full wipe (Hugo output, Hugo cache, node_modules) + fresh npm ci + rebuild
rm -rf public/ resources/ $(HUGO_CACHEDIR) node_modules/
npm ci
npm run build
.PHONY: reset-sync
reset-sync: _check-go-version _check-node-version _check-hugo-version ## Clear all generated sync content + full rebuild (use when sync logic or upstream changes)
rm -f .sync-manifest.json data/projects.json
rm -rf content/docs/projects/*/
rm -rf public/ resources/
go run ./cmd/sync-content $(SYNC_FLAGS) --lock $(LOCK) --write
npm run build