-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.sh
78 lines (66 loc) · 2.26 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
# Example: bash ./release.sh 1.0.1 patch
if [ -z "$1" ]
then
echo "🔴 Enter release version! 🚫"
echo "🔴 Command should be in the format 'bash ./release.sh <version> <version_method (like patch, minor, major, etc)>' 🚫"
exit 1
fi
if [ -z "$2" ]
then
echo "🔴 Enter version method like patch, minor, major, etc! 🚫"
echo "🔴 Command should be in the format 'bash ./release.sh <version> <version_method (like patch, minor, major, etc)>' 🚫"
exit 1
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ $BRANCH = "main" ]]
then
echo "🟢 You are on the main branch. 👍"
else
echo "🔴 Aborting!!! You are not on the main branch! 🚫"
exit 1
fi
if [ -z "$(git log origin/main..HEAD)" ]
then
echo "🟢 Your main branch does not have commits that have not been pushed. ✨"
else
echo "🔴 Aborting!!! Your main branch has commits that have not been pushed! 🔥"
exit 1
fi
RELEASE_BRANCH_NAME="release-v$1"
if [ -z "$(git status --porcelain)" ]
then
echo "🟢 Your working directory is clean. 👌"
echo "🟢 Creating new git branch $RELEASE_BRANCH_NAME... 🌵"
git switch -c "$RELEASE_BRANCH_NAME"
git push --set-upstream origin "$RELEASE_BRANCH_NAME"
else
echo "🔴 Aborting!!! Your working directory is not clean! ✋"
exit 1
fi
DESIRED_UPDATE_METHOD="patch"
if [ "$2" = "major" ] || [ "$2" = "minor" ] || [ "$2" = "patch" ] || [ "$2" = "prerelease" ]
then
DESIRED_UPDATE_METHOD=$2
echo "🟢 Starting $DESIRED_UPDATE_METHOD version update... 🕓"
elif [ -z "$2" ]
then
echo "🟢 Starting $DESIRED_UPDATE_METHOD version update... 🕓"
else
echo "🔴 Aborting!!! The second argument must be 'major', 'minor', 'patch' or 'prerelease', or left blank. [Default is 'patch'] 🩹"
exit 1
fi
VERSION_FROM_NPM=$(npm version "$DESIRED_UPDATE_METHOD")
VERSION_FROM_NPM_WITHOUT_THE_V=${VERSION_FROM_NPM:1}
echo "Supplied Version - $1"
echo "NPM Version - $VERSION_FROM_NPM_WITHOUT_THE_V"
if [ "$1" = "$VERSION_FROM_NPM_WITHOUT_THE_V" ]
then
git add .
git commit -m "Release $VERSION_FROM_NPM"
git tag "v$1"
git push --atomic origin "$RELEASE_BRANCH_NAME"
git push --tags
else
echo "🔴 Aborting!!! Desired version and version from npm are different! 🙄"
exit 1
fi