-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease
More file actions
executable file
·105 lines (81 loc) · 3.27 KB
/
release
File metadata and controls
executable file
·105 lines (81 loc) · 3.27 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
#!/usr/bin/env bash
# release - bump version, tag, push, and print the sha256 for the Homebrew tap
#
# Usage:
# ./release 0.1.0
# ./release patch (0.1.0 → 0.1.1)
# ./release minor (0.1.0 → 0.2.0)
# ./release major (0.1.0 → 1.0.0)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SRC_HEADER="$SCRIPT_DIR/src/header.sh"
# ── Read current version ────────────────────────────────────────────────────
current=$(grep -m1 '^VERSION=' "$SRC_HEADER" | sed 's/VERSION="//;s/"//')
if [[ -z "$current" ]]; then
echo "Error: could not read VERSION from src/header.sh" >&2
exit 1
fi
# ── Resolve new version ─────────────────────────────────────────────────────
if [[ -z "${1:-}" ]]; then
echo "Usage: ./release <version|patch|minor|major>" >&2
echo "Current version: $current" >&2
exit 1
fi
IFS='.' read -r major minor patch <<< "$current"
case "$1" in
patch) new="$major.$minor.$((patch + 1))" ;;
minor) new="$major.$((minor + 1)).0" ;;
major) new="$((major + 1)).0.0" ;;
*) new="$1" ;;
esac
tag="v$new"
# ── Safety checks ───────────────────────────────────────────────────────────
if [[ "$new" == "$current" ]]; then
echo "Error: version is already $current" >&2
exit 1
fi
if git tag -l "$tag" | grep -q .; then
echo "Error: tag $tag already exists" >&2
exit 1
fi
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: working tree is not clean - commit or stash first" >&2
exit 1
fi
# ── Bump, benchmark, commit, tag, push ────────────────────────────────────
echo "Releasing: $current → $new ($tag)"
sed -i.bak "s/^VERSION=\"$current\"/VERSION=\"$new\"/" "$SRC_HEADER" && rm -f "$SRC_HEADER.bak"
# Rebuild hdi from source
"$SCRIPT_DIR/build"
# Run benchmarks against the new version
if [[ -x "$SCRIPT_DIR/bench/run" ]]; then
echo ""
"$SCRIPT_DIR/bench/run" --log
"$SCRIPT_DIR/bench/chart"
fi
git add src/header.sh hdi bench/results.csv bench/results.svg demo/demo-latte.gif demo/demo-mocha.gif
git commit -m "Bump version to $new"
git tag "$tag"
git push origin HEAD --tags
# ── Print info needed for Homebrew tap ───────────────────────────────────────────
echo ""
echo "Waiting for release tarball to be available..."
tarball_url="https://github.com/grega/hdi/releases/download/$tag/hdi-$tag.tar.gz"
# Retry until the release workflow finishes and the asset is available
for i in $(seq 1 30); do
if curl -sfL "$tarball_url" -o /tmp/hdi-release.tar.gz 2>/dev/null; then
sha=$(shasum -a 256 /tmp/hdi-release.tar.gz | awk '{print $1}')
rm -f /tmp/hdi-release.tar.gz
echo ""
echo "Update homebrew-tap Formula/hdi.rb with..."
echo "url":
echo $tarball_url
echo "sha256":
echo $sha
exit 0
fi
printf "."
sleep 10
done
echo "Warning: could not fetch tarball - check $tarball_url manually" >&2
exit 1