-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (110 loc) Β· 3.55 KB
/
Makefile
File metadata and controls
122 lines (110 loc) Β· 3.55 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
VERSION ?= v0.1.0
BRANCH_DEV = dev
BRANCH_MAIN = main
RETRIES ?= 3
SLEEP ?= 2
.PHONY: help release commit push push_main merge tag test changelog return_dev
help:
@echo "Available commands:"
@echo " make commit - Add and commit all files (on $(BRANCH_DEV) branch)"
@echo " make push - Push the $(BRANCH_DEV) branch (with retry)"
@echo " make push_main - Push the $(BRANCH_MAIN) branch (with retry)"
@echo " make merge - Merge $(BRANCH_DEV) into $(BRANCH_MAIN) and push"
@echo " make tag VERSION=vX.Y.Z - Create and push a Git tag (default: $(VERSION), with retry)"
@echo " make release VERSION=vX.Y.Z - Full release workflow"
@echo " make test - Run tests"
@echo " make changelog - Update CHANGELOG.md"
return_dev:
@current=$$(git rev-parse --abbrev-ref HEAD); \
if [ "$$current" != "$(BRANCH_DEV)" ]; then \
echo "β©οΈ Returning to $(BRANCH_DEV)..."; \
git checkout $(BRANCH_DEV); \
fi
commit:
@git checkout $(BRANCH_DEV)
@if [ -n "$$(git status --porcelain)" ]; then \
echo "π Committing changes on $(BRANCH_DEV)..."; \
git add .; \
git commit -m "chore(release): prepare $(VERSION)"; \
else \
echo "β
Nothing to commit on $(BRANCH_DEV)."; \
fi
@$(MAKE) return_dev
push:
@echo "β¬οΈ Pushing $(BRANCH_DEV) to origin (with retry, $(RETRIES)x max)..."
@git checkout $(BRANCH_DEV)
@n=0; \
until [ $$n -ge $(RETRIES) ]; do \
if git push origin $(BRANCH_DEV); then \
echo "β
Push of $(BRANCH_DEV) succeeded."; \
break; \
fi; \
n=$$((n+1)); \
echo "β οΈ Push failed. Retry $$n/$(RETRIES) in $(SLEEP)s..."; \
sleep $(SLEEP); \
done; \
if [ $$n -ge $(RETRIES) ]; then \
echo "β Push of $(BRANCH_DEV) failed after $(RETRIES) attempts."; \
exit 1; \
fi
@$(MAKE) return_dev
push_main:
@echo "β¬οΈ Pushing $(BRANCH_MAIN) to origin (with retry, $(RETRIES)x max)..."
@git checkout $(BRANCH_MAIN)
@n=0; \
until [ $$n -ge $(RETRIES) ]; do \
if git push origin $(BRANCH_MAIN); then \
echo "β
Push of $(BRANCH_MAIN) succeeded."; \
break; \
fi; \
n=$$((n+1)); \
echo "β οΈ Push failed. Retry $$n/$(RETRIES) in $(SLEEP)s..."; \
sleep $(SLEEP); \
done; \
if [ $$n -ge $(RETRIES) ]; then \
echo "β Push of $(BRANCH_MAIN) failed after $(RETRIES) attempts."; \
exit 1; \
fi
@$(MAKE) return_dev
merge:
@echo "π Merging $(BRANCH_DEV) into $(BRANCH_MAIN)..."
@git checkout $(BRANCH_MAIN)
@git merge --no-ff --no-edit $(BRANCH_DEV)
@$(MAKE) push_main
@$(MAKE) return_dev
tag:
@if git rev-parse $(VERSION) >/dev/null 2>&1; then \
echo "β Tag $(VERSION) already exists."; \
exit 1; \
else \
echo "π·οΈ Creating annotated tag $(VERSION)..."; \
git tag -a $(VERSION) -m "Release version $(VERSION)"; \
echo "β¬οΈ Pushing tag $(VERSION) (with retry)..."; \
n=0; \
until [ $$n -ge $(RETRIES) ]; do \
if git push origin $(VERSION); then \
echo "β
Tag $(VERSION) pushed successfully."; \
break; \
fi; \
n=$$((n+1)); \
echo "β οΈ Push tag failed. Retry $$n/$(RETRIES) in $(SLEEP)s..."; \
sleep $(SLEEP); \
done; \
if [ $$n -ge $(RETRIES) ]; then \
echo "β Pushing tag $(VERSION) failed after $(RETRIES) attempts."; \
exit 1; \
fi; \
fi
@$(MAKE) return_dev
release:
@$(MAKE) changelog
@$(MAKE) commit
@$(MAKE) push
@$(MAKE) merge
@$(MAKE) tag VERSION=$(VERSION)
@$(MAKE) return_dev
test:
cd build && ctest --output-on-failure
changelog:
bash scripts/update_changelog.sh
@$(MAKE) return_dev