-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (131 loc) · 4.84 KB
/
Makefile
File metadata and controls
139 lines (131 loc) · 4.84 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
# SPDX-FileCopyrightText: 2026 Alexander R. Croft
# SPDX-License-Identifier: GPL-3.0-or-later
SHELL := /bin/sh
APP_NAME := rally
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')
DIST_DIR := dist/$(OS)-$(ARCH)
DIST_BIN_DIR := dist/$(OS)-$(ARCH)/bin
DIST_USER_GUIDE := $(DIST_DIR)/USER_GUIDE.md
DIST_README := $(DIST_DIR)/README.md
DIST_LICENSE := $(DIST_DIR)/LICENSE
DIST_EXAMPLE_CONFIG := $(DIST_DIR)/rally.toml.example
RELEASE_BIN := target/release/$(APP_NAME)
.PHONY: bump dist clean distclean release
bump:
@current_version="$$(cat VERSION)"; \
case "$$current_version" in \
''|*[!0-9.]*) \
echo "VERSION must contain only digits and dots" >&2; \
exit 1; \
;; \
esac; \
new_version="$$(printf '%s\n' "$$current_version" | awk -F. 'BEGIN { OFS = "." } { $$NF += 1; print }')"; \
awk -v version="$$new_version" 'BEGIN { in_package = 0; updated = 0 } \
/^\[package\][[:space:]]*$$/ { in_package = 1; print; next } \
/^\[/ && $$0 !~ /^\[package\][[:space:]]*$$/ { in_package = 0 } \
in_package && /^version[[:space:]]*=/ && !updated { print "version = \"" version "\""; updated = 1; next } \
{ print } \
END { if (!updated) exit 1 }' Cargo.toml > Cargo.toml.tmp; \
mv Cargo.toml.tmp Cargo.toml; \
printf '%s\n' "$$new_version" > VERSION; \
echo "VERSION $$current_version -> $$new_version"; \
echo "Cargo.toml package version -> $$new_version"
dist:
@version="$$(cat VERSION)"; \
case "$$version" in \
''|*[!0-9.]*) \
echo "VERSION must contain only digits and dots" >&2; \
exit 1; \
;; \
esac; \
awk -v version="$$version" 'BEGIN { in_package = 0; updated = 0 } \
/^\[package\][[:space:]]*$$/ { in_package = 1; print; next } \
/^\[/ && $$0 !~ /^\[package\][[:space:]]*$$/ { in_package = 0 } \
in_package && /^version[[:space:]]*=/ && !updated { print "version = \"" version "\""; updated = 1; next } \
{ print } \
END { if (!updated) exit 1 }' Cargo.toml > Cargo.toml.tmp; \
mv Cargo.toml.tmp Cargo.toml; \
echo "Cargo.toml package version -> $$version"
@current_build="$$(cat BUILD)"; \
case "$$current_build" in \
''|*[!0-9]*) \
echo "BUILD must contain only digits" >&2; \
exit 1; \
;; \
esac; \
new_build="$$((current_build + 1))"; \
printf '%s\n' "$$new_build" > BUILD; \
echo "BUILD $$current_build -> $$new_build"
@cargo build --release
@mkdir -p "$(DIST_BIN_DIR)"
@cp "$(RELEASE_BIN)" "$(DIST_BIN_DIR)/$(APP_NAME)"
@cp "USER_GUIDE.md" "$(DIST_USER_GUIDE)"
@cp "README.md" "$(DIST_README)"
@cp "LICENSE" "$(DIST_LICENSE)"
@cp "rally.toml.example" "$(DIST_EXAMPLE_CONFIG)"
@echo "Copied $(RELEASE_BIN) to $(DIST_BIN_DIR)/$(APP_NAME)"
@echo "Copied USER_GUIDE.md to $(DIST_USER_GUIDE)"
@echo "Copied README.md to $(DIST_README)"
@echo "Copied LICENSE to $(DIST_LICENSE)"
@echo "Copied rally.toml.example to $(DIST_EXAMPLE_CONFIG)"
clean:
@rm -rf target
@echo "Removed target"
distclean:
@rm -rf target dist
@echo "Removed target and dist"
release:
@version="$$(cat VERSION)"; \
case "$$version" in \
''|*[!0-9.]*) \
echo "VERSION must contain only digits and dots" >&2; \
exit 1; \
;; \
esac; \
tag="v$$version"; \
branch="$$(git branch --show-current)"; \
if [ -z "$$branch" ]; then \
echo "release requires a checked out branch" >&2; \
exit 1; \
fi; \
if ! git remote get-url origin >/dev/null 2>&1; then \
echo "release requires a git remote named origin" >&2; \
exit 1; \
fi; \
if [ -n "$$(git status --porcelain)" ]; then \
echo "release requires a clean working tree" >&2; \
exit 1; \
fi; \
if git rev-parse -q --verify "refs/tags/$$tag" >/dev/null; then \
echo "tag $$tag already exists locally" >&2; \
exit 1; \
fi; \
if git ls-remote --exit-code --tags origin "refs/tags/$$tag" >/dev/null 2>&1; then \
echo "tag $$tag already exists on origin" >&2; \
exit 1; \
fi; \
current_build="$$(cat BUILD)"; \
case "$$current_build" in \
''|*[!0-9]*) \
echo "BUILD must contain only digits" >&2; \
exit 1; \
;; \
esac; \
new_build="$$((current_build + 1))"; \
awk -v version="$$version" 'BEGIN { in_package = 0; updated = 0 } \
/^\[package\][[:space:]]*$$/ { in_package = 1; print; next } \
/^\[/ && $$0 !~ /^\[package\][[:space:]]*$$/ { in_package = 0 } \
in_package && /^version[[:space:]]*=/ && !updated { print "version = \"" version "\""; updated = 1; next } \
{ print } \
END { if (!updated) exit 1 }' Cargo.toml > Cargo.toml.tmp; \
mv Cargo.toml.tmp Cargo.toml; \
printf '%s\n' "$$new_build" > BUILD; \
echo "Prepared release $$tag (build $$new_build) on branch $$branch"; \
cargo test; \
git add VERSION BUILD Cargo.toml; \
git commit -m "Release $$tag"; \
git tag -a "$$tag" -m "Release $$tag"; \
git push origin "$$branch"; \
git push origin "$$tag"; \
echo "Pushed $$tag to origin; GitHub Actions will build and publish the release."