-
Notifications
You must be signed in to change notification settings - Fork 16
/
revert_release.sh
executable file
·79 lines (63 loc) · 1.91 KB
/
revert_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
#!/bin/bash
set -e
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -f "${SCRIPT_PATH}/.version.sh" ]; then
# shellcheck source=.version.sh
source "${SCRIPT_PATH}/.version.sh"
else
VERSION="UNKNOWN VERSION"
fi
echo "Release scripts (revert-release, version: ${VERSION})"
if [[ $# -ne 1 && $# -ne 2 ]]
then
echo 'Usage: revert_release.sh <release-version>'
echo 'For example: revert_release.sh 0.1.0'
exit 2
fi
RELEASE_VERSION=$1
if [ -f "${SCRIPT_PATH}/.common-util.sh" ]; then
# shellcheck source=.common-util.sh
source "${SCRIPT_PATH}/.common-util.sh"
else
echo 'Missing file .common-util.sh. Aborting'
exit 1
fi
RELEASE_BRANCH=$(format_release_branch_name "${RELEASE_VERSION}")
check_local_workspace_state "revert_release"
if [ $# -eq 1 ]
then
echo "Warning! This script will delete every local commit on branches ${DEVELOP_BRANCH} and ${MASTER_BRANCH} !"
echo "Only continue if you know what you are doing with following command:"
echo "$ revert_release.sh ${RELEASE_VERSION} --iknowwhatimdoing"
exit 2
fi
DOES_HE_KNOW_WHAT_HE_IS_DOING=$2
if [ ! "${DOES_HE_KNOW_WHAT_HE_IS_DOING}" = '--iknowwhatimdoing' ]
then
echo 'Usage: revert_release.sh <release-version>'
echo 'For example: revert_release.sh 0.1.0'
exit 2
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# revert master branch
git checkout "${MASTER_BRANCH}"
git reset "${REMOTE_REPO}/${MASTER_BRANCH}" --hard
# revert develop branch
git checkout "${DEVELOP_BRANCH}"
git reset "${REMOTE_REPO}/${DEVELOP_BRANCH}" --hard
# delete release branch
if git rev-parse --verify "${RELEASE_BRANCH}"
then
git branch -D "${RELEASE_BRANCH}"
fi
# delete release tag
RELEASE_TAG=$(format_release_tag "${RELEASE_VERSION}")
if git rev-parse --verify "${RELEASE_TAG}"
then
git tag -d "${RELEASE_TAG}"
fi
# return to previous branch
if [[ ! $(git rev-parse --abbrev-ref HEAD) = "${CURRENT_BRANCH}" ]]
then
git checkout "${CURRENT_BRANCH}"
fi