Skip to content

Commit 91621b9

Browse files
committed
Add release script
1 parent d12a17f commit 91621b9

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

bin/release

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
cd "$(dirname "${BASH_SOURCE[0]}")/.."
5+
6+
VERSION_FILE="lib/upright/version.rb"
7+
GEMSPEC="upright.gemspec"
8+
9+
usage() {
10+
echo "Usage: bin/release <major|minor|patch|VERSION>"
11+
echo ""
12+
echo "Examples:"
13+
echo " bin/release patch # 0.1.0 -> 0.1.1"
14+
echo " bin/release minor # 0.1.0 -> 0.2.0"
15+
echo " bin/release major # 0.1.0 -> 1.0.0"
16+
echo " bin/release 2.0.0 # Set specific version"
17+
exit 1
18+
}
19+
20+
if [ $# -ne 1 ]; then
21+
usage
22+
fi
23+
24+
current_version=$(grep -oP 'VERSION = "\K[^"]+' "$VERSION_FILE")
25+
echo "Current version: $current_version"
26+
27+
bump_type="$1"
28+
29+
if [[ "$bump_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
30+
new_version="$bump_type"
31+
else
32+
IFS='.' read -r major minor patch <<< "$current_version"
33+
34+
case "$bump_type" in
35+
major)
36+
new_version="$((major + 1)).0.0"
37+
;;
38+
minor)
39+
new_version="$major.$((minor + 1)).0"
40+
;;
41+
patch)
42+
new_version="$major.$minor.$((patch + 1))"
43+
;;
44+
*)
45+
usage
46+
;;
47+
esac
48+
fi
49+
50+
echo "New version: $new_version"
51+
echo ""
52+
53+
read -p "Continue with release? [y/N] " -n 1 -r
54+
echo ""
55+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
56+
echo "Aborted."
57+
exit 1
58+
fi
59+
60+
echo "Updating version..."
61+
sed -i "s/VERSION = \"$current_version\"/VERSION = \"$new_version\"/" "$VERSION_FILE"
62+
63+
echo "Building gem..."
64+
gem build "$GEMSPEC"
65+
66+
gem_file="upright-$new_version.gem"
67+
68+
echo "Getting OTP from 1Password..."
69+
otp=$(op item get "RubyGems.org" --otp)
70+
71+
echo "Pushing gem..."
72+
gem push "$gem_file" --otp "$otp"
73+
74+
echo "Cleaning up gem file..."
75+
rm "$gem_file"
76+
77+
echo "Committing version bump..."
78+
git add "$VERSION_FILE"
79+
git commit -m "Bump version to $new_version"
80+
81+
echo "Creating GitHub release..."
82+
gh release create "v$new_version" --title "v$new_version" --generate-notes
83+
84+
echo ""
85+
echo "Released upright $new_version"

0 commit comments

Comments
 (0)