-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
443 lines (402 loc) Β· 13.8 KB
/
Makefile
File metadata and controls
443 lines (402 loc) Β· 13.8 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
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# =====================
# Config
# =====================
# Export environment variables to all targets
include .env
DOCKER_PASSWORD := $(SUBVORTEX_DOCKER_TOKEN)
export DOCKER_PASSWORD
# Actions per component
ACTIONS_miner := bump-major bump-minor bump-patch bump-alpha bump-rc
ACTIONS_validator := bump-major bump-minor bump-patch bump-alpha bump-rc
# Services per component
SERVICES_miner := neuron metagraph redis
SERVICES_validator := neuron metagraph redis
# All components
COMPONENTS := miner validator
# Get the current branch
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# Get the version script
BUMP_VERSION_SCRIPT = ./scripts/cicd/cicd_bump_version.py
UNBUMP_VERSION_SCRIPT = ./scripts/cicd/cicd_unbump_version.py
DIST_DIR = ./dist
# =============================
# Declare all targets as .PHONY
# =============================
TARGETS += clean build tag untag release prerelease unrelease unprerelease
# ======================
# Declare shared methods
# ======================
get_version_shell = $(shell \
if [ -f $(1)/pyproject.toml ]; then \
grep -E '^version\s*=\s*"([^"]+)"' $(1)/pyproject.toml | awk -F '"' '{print $$2}'; \
elif [ -f $(1)/version.py ]; then \
grep -oE '__version__ *= *["'"'"']([^"'"'"']+)["'"'"']' $(1)/version.py | sed -E 's/__version__ *= *["'"'"']([^"'"'"']+)["'"'"']/\1/'; \
elif [ -f $(1)/VERSION ]; then \
cat $(1)/VERSION | tr -d '\n'; \
else \
echo "VERSION_NOT_FOUND"; \
fi)
define get_version
if [ -f $(1)/version.py ]; then \
grep -oE '__version__ *= *["'"'"']([^"'"'"']+)["'"'"']' $(1)/version.py | sed -E 's/__version__ *= *["'"'"']([^"'"'"']+)["'"'"']/\1/'; \
elif [ -f $(1)/VERSION ]; then \
cat $(1)/VERSION | tr -d '\n'; \
elif [ -f $(1)/pyproject.toml ]; then \
grep -E '^version\s*=\s*"([^"]+)"' $(1)/pyproject.toml | awk -F '"' '{print $$2}'; \
else \
echo "VERSION_NOT_FOUND"; \
fi
endef
define load_env
if [ -f .secrets ]; then \
echo "π¦ Loading environment from .secrets"; \
set -a; \
source .secrets; \
set +a; \
fi
endef
# ==================
# π¨ Version Bumping
# ==================
# Root-level bump targets
TARGETS += bump-alpha bump-rc bump-patch bump-minor bump-major
TARGETS += unbump-alpha unbump-rc unbump-patch unbump-minor unbump-major
define bump_template
bump-$(1):
@echo "π§ bump-$(1) (skip=$(skip), only=$(only))"
@only_root=false; \
skip_root=false; \
if [ -n "$(only)" ]; then \
echo "$(only)" | grep -q -x "\." && only_root=true || only_root=false; \
else \
skip_root=false; \
echo "$(skip)" | grep -q -x "\." && skip_root=true; \
fi; \
if [ "$$$$only_root" = true ] || { [ -z "$(only)" ] && [ "$$$$skip_root" = false ]; }; then \
python3 $(BUMP_VERSION_SCRIPT) . $(1); \
python3 $(BUMP_VERSION_SCRIPT) ./subvortex $(1); \
fi
@for comp in $$(COMPONENTS); do \
if [ -n "$$(only)" ]; then \
echo "$$(only)" | grep -q -x "$$$$comp" || continue; \
elif echo "$$(skip)" | grep -q -x "$$$$comp"; then \
continue; \
fi; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$$$$comp $(1); \
done
@for comp in $$(COMPONENTS); do \
case "$$$$comp" in \
miner) SERVICES="$(SERVICES_miner)";; \
validator) SERVICES="$(SERVICES_validator)";; \
*) echo "Unknown component: $$$$comp"; exit 1;; \
esac; \
for svc in $$$$SERVICES; do \
entry="$$$$comp/$$$$svc"; \
if [ -n "$$(only)" ]; then \
echo "$$(only)" | grep -q -x "$$$$entry" || continue; \
elif echo "$$(skip)" | grep -q -x "$$$$entry"; then \
continue; \
fi; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$$$$entry $(1); \
done \
done
endef
define unbump_template
unbump-$(1):
@echo "π unbump-$(1) (skip=$(skip), only=$(only))"
@only_root=false; \
skip_root=false; \
if [ -n "$(only)" ]; then \
echo "$(only)" | grep -q -x "\." && only_root=true || only_root=false; \
else \
skip_root=false; \
echo "$(skip)" | grep -q -x "\." && skip_root=true; \
fi; \
if [ "$$$$only_root" = true ] || { [ -z "$(only)" ] && [ "$$$$skip_root" = false ]; }; then \
python3 $(UNBUMP_VERSION_SCRIPT) . $(1); \
python3 $(UNBUMP_VERSION_SCRIPT) ./subvortex $(1); \
fi
@for comp in $$(COMPONENTS); do \
if [ -n "$$(only)" ]; then \
echo "$$(only)" | grep -q -x "$$$$comp" || continue; \
elif echo "$$(skip)" | grep -q -x "$$$$comp"; then \
continue; \
fi; \
python3 $(UNBUMP_VERSION_SCRIPT) subvortex/$$$$comp $(1); \
done
@for comp in $$(COMPONENTS); do \
case "$$$$comp" in \
miner) SERVICES="$(SERVICES_miner)";; \
validator) SERVICES="$(SERVICES_validator)";; \
*) echo "Unknown component: $$$$comp"; exit 1;; \
esac; \
for svc in $$$$SERVICES; do \
entry="$$$$comp/$$$$svc"; \
if [ -n "$$(only)" ]; then \
echo "$$(only)" | grep -q -x "$$$$entry" || continue; \
elif echo "$$(skip)" | grep -q -x "$$$$entry"; then \
continue; \
fi; \
python3 $(UNBUMP_VERSION_SCRIPT) subvortex/$$$$entry $(1); \
don
endef
$(foreach level, patch minor major alpha rc,\
$(eval $(call bump_template,$(level)))\
$(eval $(call unbump_template,$(level)))\
)
# Per-component bump shortcuts
$(foreach comp,$(COMPONENTS),\
$(foreach action,patch minor major alpha rc,\
$(eval TARGETS += bump-$(comp)-$(action) unbump-$(comp)-$(action))\
$(eval bump-$(comp)-$(action): ; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$(comp) $(action) \
) \
$(eval unbump-$(comp)-$(action): ; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$(comp) $(action) \
) \
$(foreach svc,$(SERVICES_$(comp)),\
$(eval TARGETS += bump-$(comp)-$(svc)-$(action) unbump-$(comp)-$(svc)-$(action))\
$(eval bump-$(comp)-$(svc)-$(action): ; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$(comp)/$(svc) $(action) \
) \
$(eval unbump-$(comp)-$(svc)-$(action): ; \
python3 $(BUMP_VERSION_SCRIPT) subvortex/$(comp)/$(svc) $(action) \
) \
)\
) \
)
# ===========
# π§Ύ Metadata
# ===========
TARGETS += metadata
metadata:
@echo "π§ Running metadata updater script..."
@.github/scripts/generate_metadata.sh
# ========
# π§ͺ Build
# ========
define clean_github_component
@echo "π§Ή Cleaning GitHub build for $(1)..."
@rm -rf $(DIST_DIR)/subvortex_$(1)* build *.egg-info
@rm -f pyproject.toml
@echo "β
GitHub clean complete for $(1)"
endef
define build_github_component
@$(MAKE) clean-$(1)
@echo "π¦ Building GitHub asset for $(1) with pyproject-$(1).toml..."
@cp pyproject-$(1).toml pyproject.toml
@python3 -m build --sdist --wheel -o dist
@rm pyproject.toml
@for f in dist/subvortex-*; do \
[ -f "$$f" ] || continue; \
newf=$${f/subvortex-/subvortex_$(1)-}; \
echo "β‘οΈ Renaming: $$f -> $$newf"; \
mv "$$f" "$$newf"; \
done
@echo "β
GitHub asset build done for $(1)"
endef
# Build and clean targets per component and category
$(foreach comp,$(COMPONENTS), \
$(eval TARGETS += build-$(comp) clean-${comp}) \
$(eval build-$(comp): ; $$(call build_github_component,$(comp))) \
$(eval clean-$(comp): ; $$(call clean_github_component,$(comp))) \
)
# Global
build: $(foreach comp,$(COMPONENTS),build-$(comp))
clean: $(foreach comp,$(COMPONENTS),clean-$(comp))
# ============
# π·οΈ Tag/Untag
# ============
TARGETS += tag untag
tag:
@VERSION=$(call get_version_shell, .); \
echo "π·οΈ Creating GitHub tag v$$VERSION"; \
git tag -a "v$$VERSION" -m "Release version $$VERSION"; \
git push origin "v$$VERSION";
untag:
@VERSION=$(call get_version_shell, .); \
echo "ποΈ Deleting GitHub tag v$$VERSION"; \
git tag -d "v$$VERSION"; \
git push origin ":refs/tags/v$$VERSION";
# ====================
# π Release/UnRelease
# ====================
TARGETS += release unrelease prerelease unprerelease
unprerelease:
@VERSION=$$(cat VERSION); \
if ! echo "$$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-(alpha|rc)\.[0-9]+$$'; then \
echo "β VERSION must be in format x.x.x-alpha.x or x.x.x-rc.x (got: $$VERSION)"; \
exit 1; \
fi; \
TAG=v$$VERSION; \
$(load_env); \
\
(gh release view "$$TAG" &>/dev/null && \
echo "ποΈ Deleting GitHub prerelease $$TAG..." && \
gh release delete "$$TAG" --yes || \
echo "β οΈ Failed to delete or prerelease not found β continuing..."); \
\
for comp in subvortex/*; do \
[ -d "$$comp" ] || continue; \
comp_name=$$(basename "$$comp"); \
case $$comp_name in \
miner) services="$(SERVICES_miner)" ;; \
validator) services="$(SERVICES_validator)" ;; \
*) services="$$comp_name" ;; \
esac; \
for service in $$services; do \
service_path="$$comp/$$service"; \
if [ -f "$$service_path/pyproject.toml" ] || [ -f "$$service_path/version.py" ]; then \
.github/scripts/on_release_deleted.sh "$$comp_name" "$$service" "$$TAG"; \
fi; \
done; \
done
prerelease:
@VERSION=$$(cat VERSION); \
if ! echo "$$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-(alpha|rc)\.[0-9]+$$'; then \
echo "β VERSION must be in format x.x.x-alpha.x or x.x.x-rc.x (got: $$VERSION)"; \
exit 1; \
fi; \
TAG=v$$VERSION; \
echo "π Creating GitHub prerelease..."; \
gh release create $$TAG \
--title "$$TAG" \
--notes "Pre-release $$TAG" \
--target $(CURRENT_BRANCH) \
--prerelease \
$(DIST_DIR)/*.tar.gz \
$(DIST_DIR)/*.whl || true
unrelease:
@VERSION=$$(cat VERSION); \
if ! echo "$$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "β VERSION must be in format x.x.x (got: $$VERSION)"; \
exit 1; \
fi; \
TAG=v$$VERSION; \
$(load_env); \
\
(gh release view "$$TAG" &>/dev/null && \
echo "ποΈ Deleting GitHub release $$TAG..." && \
gh release delete "$$TAG" --yes || \
echo "β οΈ Failed to delete or release not found β continuing..."); \
\
for comp in subvortex/*; do \
[ -d "$$comp" ] || continue; \
comp_name=$$(basename "$$comp"); \
case $$comp_name in \
miner) services="$(SERVICES_miner)" ;; \
validator) services="$(SERVICES_validator)" ;; \
*) services="$$comp_name" ;; \
esac; \
for service in $$services; do \
service_path="$$comp/$$service"; \
if [ -f "$$service_path/pyproject.toml" ] || [ -f "$$service_path/version.py" ]; then \
.github/scripts/on_release_deleted.sh "$$comp_name" "$$service" "$$TAG"; \
fi; \
done; \
done
release:
@VERSION=$$(cat VERSION); \
if ! echo "$$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "β VERSION must be in format x.x.x (got: $$VERSION)"; \
exit 1; \
fi; \
TAG=v$$VERSION; \
echo "π Creating GitHub release..."; \
gh release create $$TAG \
--title "$$TAG" \
--notes "Release $$TAG" \
--target $(CURRENT_BRANCH) \
$(DIST_DIR)/*.tar.gz \
$(DIST_DIR)/*.whl || true
# =========
# π§ͺ Tests
# =========
TARGETS += test
test:
@echo "π§ͺ Running tests in all components/services..."
@PYTHONPATH=. ; \
for comp in $(COMPONENTS); do \
case "$$comp" in \
miner) SERVICES="$(SERVICES_miner)";; \
validator) SERVICES="$(SERVICES_validator)";; \
*) echo "Unknown component: $$comp"; exit 1;; \
esac; \
for svc in $$SERVICES; do \
svc_path=subvortex/$$comp/$$svc; \
if [ -d "$$svc_path" ]; then \
echo "π Testing $$svc_path..."; \
PYTHONPATH=. pytest "$$svc_path"|| test $$? -eq 5 || exit $$?; \
else \
echo "β οΈ Warning: Path $$svc_path not found, skipping..."; \
fi \
done \
done; \
if [ -d "subvortex/core" ]; then \
echo "π Testing subvortex/core..."; \
PYTHONPATH=. pytest subvortex/core || test $$? -eq 5 || exit $$?; \
else \
echo "β οΈ Warning: subvortex/core not found, skipping..."; \
fi
# ==========
# π Scripts
# ==========
generate:
python3 tools/generate_scripts/src/main.py
# =====================
# Add the last target
# =====================
.PHONY: $(TARGETS) help
# =====================
# Optional: help target
# =====================
help:
@echo "π¦ CI/CD Targets:"
@echo ""
@echo "π§ Version Bump Commands"
@echo ""
@echo " bump-patch β Patch all components"
@echo " bump-minor β Minor bump for all components"
@echo " bump-major β Major bump for all components"
@echo " bump-alpha β Alpha pre-release bump for all"
@echo " bump-rc β RC pre-release bump for all"
@echo " bump-version β New pre-release for all"
@echo ""
@echo "π§ Role-level Bumps"
@echo " bump-[role]-patch β Patch [role] and its services"
@echo " bump-[role]-minor β Minor bump for [role] and its services"
@echo " bump-[role]-major β Major bump for [role] and its services"
@echo " bump-[role]-alpha β Alpha bump for [role] and its services"
@echo " bump-[role]-rc β RC bump for [role] and its services"
@echo ""
@echo "π§ Service-level Bumps"
@echo " bump-[role]-[service]-patch β Patch [role]/[service]"
@echo " bump-[role]-[service]-minor β Minor bump for [role]/[service]"
@echo " bump-[role]-[service]-major β Major bump for [role]/[service]"
@echo " bump-[role]-[service]-alpha β Alpha bump for [role]/[service]"
@echo " bump-[role]-[service]-rc β RC bump for [role]/[service]"
@echo ""
@echo "π§Ύ Metadata:"
@echo " metadata β Update the metadata to add the version"
@echo ""
@echo "π§ͺ Build/Clean:"
@echo ""
@echo " build β Build all components"
@echo " clean β Clean all components"
@echo " test β Run pytest in all service folders"
@echo ""
@echo "π·οΈ Tag/Untag:"
@echo ""
@echo " tag β Tag all components"
@echo " untag β Untag all components"
@echo ""
@echo "π Release/Unrelease:"
@echo ""
@echo " release β Release all components"
@echo " unrelease β Unrelease all components"
@echo " prerelease β Release all components"
@echo " unprerelease β Unrelease all components"
targets:
@echo "π Available Dynamic Targets:"
@echo ""
@printf " %s\n" $(sort $(TARGETS))