-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·102 lines (88 loc) · 2.95 KB
/
release.sh
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
#!/bin/bash
set -Euo pipefail
# 0. Check that there's no changes and that we're on the v1 branch
if [ -n "$(git status --porcelain)" ]; then
echo "please commit or stash changes before trying to create a new release"
exit 1
fi
if [ "$(git branch --show-current)" != "v1" ]; then
echo "You can only release this action from the v1 branch"
exit 1
fi
echo "⭕️ finding location of github CLI:"
if ! which gh; then
echo "❌ couldn't find github CLI... installing from homebrew"
brew install gh
else
echo "✅ found github CLI!"
fi
echo "⭕️ finding location of jq:"
if ! which jq; then
echo "couldn't find jq... installing from homebrew"
brew install jq
else
echo "✅ found jq!"
fi
echo "⭕️ checking github CLI auth status:"
if ! gh auth status; then
echo "you need to be logged into github with the github cli tool to run this script"
gh auth login
fi
# 1. if package.json is the same as the latest tag, update package.json & create PR
package_version="$(jq -r .version <package.json)"
latest_tag="$(git tag | grep "^v" | sort | tail -n 1)"
IFS=. read major minor patch <<<"${package_version}"
if [ "v$package_version" == $latest_tag ]; then
echo "current version is $package_version"
PS3='what version would you like to update?: '
next_patch="$major.$minor.$(($patch + 1))"
patch_msg="patch (bug fixes or improvements) $next_patch"
next_minor="$major.$(($minor + 1)).$patch"
minor_msg="minor (enhancements) $next_minor"
next_major="$(($major + 1)).$minor.$patch"
major_msg="major (breaking changes) $next_major"
options=("$patch_msg" "$minor_msg" "$major_msg")
select opt in "${options[@]}"; do
case $opt in
"$patch_msg")
bump_version="patch"
next_version=$next_patch
break
;;
"$minor_msg")
bump_version="minor"
next_version=$next_minor
break
;;
"$major_msg")
bump_version="major"
next_version=$next_major
break
;;
*) echo "invalid option $REPLY" ;;
esac
done
npm version --no-git-tag-version "$bump_version"
git checkout -b release-$next_version
git commit -m "bump version to $next_version"
gh pr create --title "prepare release v$next_version" --fill
git checkout v1
echo "✅ Please merge the v1 branch and call this script again"
exit 0
fi
# 2. Create github release with new tag
release_notes=$(
cat <<RELEASE_TEMPLATE
# 🙈 $package_version Title of Github Release Prefixed By Version and Fun Emoji!
PLEASE REPLACE THIS RELEASE TEMPLATE. IT WILL POPULATE THE GITHUB RELEASE !
In This Release, we did some excellent things.
# 🪙 Changelog 🪵
## Bugs
- fixed a cool bug [#123] (thanks @Janice !)
## Enhancements
- now we can do spacetravel[#1337] (cheers to @Bobak ! )
RELEASE_TEMPLATE
)
echo "releasing draft version $package_version"
gh release create "v$package_version" --title "v$package_version" --draft --notes "$release_notes"
echo "✅ Draft release pushed to github. Edit the changelog and release it in the github UI!"