-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
347 lines (310 loc) Β· 10.9 KB
/
Makefile
File metadata and controls
347 lines (310 loc) Β· 10.9 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
# =====================
# Config
# =====================
# Actions per component
ACTIONS := bump-major bump-minor bump-patch bump-alpha bump-rc
# All components
COMPONENTS := auto_upgrader
# 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
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
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) \
) \
) \
)
# ========
# π§ͺ Build
# ========
define clean_github_component
@echo "π§Ή Cleaning GitHub build for $(1)..."
@rm -rf $(DIST_DIR)/subvortex_$(1)* build *.egg-info
@echo "β
GitHub clean complete for $(1)"
endef
define build_github_component
@$(MAKE) clean-$(1)
@echo "π¦ Building GitHub asset for $(1) with pyproject-$(1).toml..."
@python3 -m build --sdist --wheel -o dist
@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))) \
)
build: build-auto_upgrader
clean: clean-auto_upgrader
# ============
# π·οΈ Tag/Untag
# ============
define create_github_tag
@VERSION=$$($(call get_version, .)); \
echo "π·οΈ Creating GitHub tag v$$VERSION"; \
git tag -a "v$$VERSION" -m "Release version $$VERSION"; \
git push origin "v$$VERSION";
endef
define delete_github_tag
@VERSION=$$($(call get_version, .)); \
echo "π·οΈ Creating GitHub tag v$$VERSION"; \
git tag -d "v$$VERSION"; \
git push origin ":refs/tags/v$$VERSION";
endef
$(foreach comp,$(COMPONENTS), \
$(eval TARGETS += tag-$(comp) untag-${comp}) \
$(eval tag-$(comp): ; $$(call create_github_tag,$(comp))) \
$(eval untag-$(comp): ; $$(call delete_github_tag,$(comp))) \
)
tag: tag-auto_upgrader
untag: untag-auto_upgrader
# ====================
# π Release/UnRelease
# ====================
define github_release
@VERSION=$$($(call get_version, .)); \
TAG=v$$VERSION; \
echo "π Creating GitHub release $$TAG..."; \
gh release create $$TAG \
--title "$$TAG" \
--notes "Pre-release $$TAG" \
--target $(CURRENT_BRANCH) \
$(DIST_DIR)/*.tar.gz \
$(DIST_DIR)/*.whl || true
endef
define github_unrelease
@VERSION=$$($(call get_version, .)); \
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; \
if [ -f "$$comp/pyproject.toml" ] || [ -f "$$comp/version.py" ]; then \
comp_name=$$(basename "$$comp"); \
.github/scripts/on_release_deleted.sh "$$comp_name" "$$TAG"; \
fi; \
done
endef
define github_prerelease
@VERSION=$$($(call get_version, .)); \
TAG=v$$VERSION; \
echo "π Creating GitHub prerelease $$TAG..."; \
gh release create $$TAG \
--title "$$TAG" \
--notes "Pre-release $$TAG" \
--target $(CURRENT_BRANCH) \
--prerelease \
$(DIST_DIR)/*.tar.gz \
$(DIST_DIR)/*.whl || true
endef
define github_unprerelease
@VERSION=$$($(call get_version, .)); \
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; \
if [ -f "$$comp/pyproject.toml" ] || [ -f "$$comp/version.py" ]; then \
comp_name=$$(basename "$$comp"); \
.github/scripts/on_release_deleted.sh "$$comp_name" "$$TAG"; \
fi; \
done
endef
# Auto-generate rules per component
$(foreach comp,$(COMPONENTS), \
$(eval TARGETS += release-$(comp) prerelease-$(comp) unrelease-$(comp) unprerelease-$(comp)) \
$(eval release-$(comp): ; $$(call github_release,$(comp))) \
$(eval prerelease-$(comp): ; $$(call github_prerelease,$(comp))) \
$(eval unrelease-$(comp): ; $$(call github_unrelease,$(comp))) \
$(eval unprerelease-$(comp): ; $$(call github_unprerelease,$(comp))) \
)
# Global release/unrelease
release: release-auto_upgrader
prerelease: prerelease-auto_upgrader
unrelease: unrelease-auto_upgrader
unprerelease: unprerelease-auto_upgrader
# ========
# π§ͺ Tests
# ========
test:
@PYTHONPATH=. venv/bin/pytest --ignore=subvortex $(ARGS)
# =====================
# 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-[service]-patch β Patch [service]"
@echo " bump-[service]-minor β Minor bump for [service]"
@echo " bump-[service]-major β Major bump for [service]"
@echo " bump-[service]-alpha β Alpha bump for [service]"
@echo " bump-[service]-rc β RC bump for [service]"
@echo ""
@echo "π§ͺ Build/Clean:"
@echo " build β Build all components"
@echo " clean β Clean all components"
@echo ""
@echo " build-[service] β Build [service]"
@echo " clean-[service] β Clean [service]"
@echo ""
@echo "π·οΈ Tag/Untag:"
@echo " tag β Tag all components"
@echo " untag β Untag all components"
@echo ""
@echo " tag-[service] β Tag [service]"
@echo " untag-[service] β Untag [service]"
@echo ""
@echo "π Release/Unrelease:"
@echo " release β Release all components"
@echo " prerelease β Release all components"
@echo " unrelease β Unrelease all components"
@echo " unprerelease β Unrelease all components"
@echo ""
@echo " release-[service] β Release [service]"
@echo " prerelease-[service] β Prerelease [service]"
@echo " unrelease-[service] β Unrelease [service]"
@echo " preunrelease-[service] β Unprerelease [service]"
targets:
@echo "π Available Dynamic Targets:"
@echo ""
@printf " %s\n" $(sort $(TARGETS))