-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease
More file actions
executable file
·123 lines (97 loc) · 3.86 KB
/
release
File metadata and controls
executable file
·123 lines (97 loc) · 3.86 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
#!/usr/bin/env bash
# release - tag, build, create GitHub release, and print Homebrew tap info
#
# Usage:
# ./release patch (0.1.0 → 0.1.1)
# ./release minor (0.1.0 → 0.2.0)
# ./release major (0.1.0 → 1.0.0)
# ./release 1.2.3 (explicit version)
set -euo pipefail
REPO="grega/versions"
BINARY_NAME="vrs"
CLI_DIR="$(cd "$(dirname "$0")" && pwd)"
# ── Read current version from latest git tag ────────────────────────────────
current=$(git tag -l 'v*' | sed 's/^v//' | sort -V | tail -1)
current="${current:-0.0.0}"
# ── 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
echo "Releasing: $current → $new ($tag)"
# ── Build all targets ──────────────────────────────────────────────────────
TARGETS=(
"darwin arm64"
"darwin amd64"
"linux arm64"
"linux amd64"
)
assets=()
for target in "${TARGETS[@]}"; do
read -r os arch <<< "$target"
echo "Building $os/$arch..."
outname="$BINARY_NAME-$tag-$os-$arch"
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
go build -C "$CLI_DIR" -ldflags "-s -w -X main.version=$new" -o "$BINARY_NAME" .
tar -czf "/tmp/$outname.tar.gz" -C "$CLI_DIR" "$BINARY_NAME"
rm "$CLI_DIR/$BINARY_NAME"
assets+=("/tmp/$outname.tar.gz")
done
# ── Tag and push ────────────────────────────────────────────────────────────
git tag "$tag"
git push origin HEAD --tags
# ── Create GitHub release with assets ───────────────────────────────────────
gh release create "$tag" "${assets[@]}" \
--repo "$REPO" \
--title "$tag" \
--generate-notes
# ── Print Homebrew tap formula snippet ──────────────────────────────────────
sha_for() { shasum -a 256 "$1" | awk '{print $1}'; }
url_for() { echo "https://github.com/$REPO/releases/download/$tag/$(basename "$1")"; }
echo ""
echo "Done! Update homebrew-tap Formula/vrs.rb:"
echo ""
echo " version \"$new\""
echo ""
echo " on_macos do"
echo " if Hardware::CPU.arm?"
echo " url \"$(url_for "${assets[0]}")\""
echo " sha256 \"$(sha_for "${assets[0]}")\""
echo " else"
echo " url \"$(url_for "${assets[1]}")\""
echo " sha256 \"$(sha_for "${assets[1]}")\""
echo " end"
echo " end"
echo ""
echo " on_linux do"
echo " if Hardware::CPU.arm?"
echo " url \"$(url_for "${assets[2]}")\""
echo " sha256 \"$(sha_for "${assets[2]}")\""
echo " else"
echo " url \"$(url_for "${assets[3]}")\""
echo " sha256 \"$(sha_for "${assets[3]}")\""
echo " end"
echo " end"
rm -f "${assets[@]}"