-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
61 lines (46 loc) · 1.62 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
#!/bin/bash
set -e
if ! [[ $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
echo "Version number must be in x.y.z format" >&2
exit 1
fi
# branch with the code which will be released
releaseBranch=$1
# v1.0.0, v1.5.2, etc.
versionLabel=v$2
# establish branch and tag name variables
masterBranch=master
# checkout to master and gets its last version
git checkout $masterBranch || exit 1
git pull origin $masterBranch || exit 1
printf "\n"
echo "Switched to branch $masterBranch and pulled the last version."
printf "\n"
# checkout to release branch, gets its last version and merge master into it to resolve conflicts
git checkout $releaseBranch || exit 1
git pull origin $releaseBranch || exit 1
git merge $masterBranch -m "Merge $masterBranch into $releaseBranch" || exit 1
printf "\n"
echo "Switched to branch $releaseBranch and merged $masterBranch into it"
printf "\n"
# checkout to master and merge release branch into it
git checkout $masterBranch || exit 1
git merge --no-ff $releaseBranch -m "Merge $releaseBranch into $masterBranch" || exit 1
printf "\n"
echo "Switched to branch $masterBranch and merged $releaseBranch into it"
printf "\n"
# create tag for new version from -master
git tag $versionLabel || exit 1
git push --tags || exit 1
git push origin $masterBranch || exit 1
printf "\n"
echo "Created tag $versionLabel into $masterBranch"
printf "\n"
# remove release branch remotely and locally
git push -d origin $releaseBranch || exit 1
git branch -D $releaseBranch || exit 1
printf "\n"
echo "Deleted release $releaseBranch remotely and locally, you're in branch $masterBranch now!"
echo "Congrats on your new release!"
exit 0