-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
128 lines (108 loc) · 3.39 KB
/
Copy pathrelease.sh
File metadata and controls
128 lines (108 loc) · 3.39 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# SPDX-FileCopyrightText: © 2022 ELABIT GmbH <mail@elabit.de>
# SPDX-License-Identifier: GPL-3.0-or-later
# This file is part of the Robotmk project (https://www.robotmk.org)
devbranch="v1/dev"
stablebranch="v1/stable"
function main (){
MODE=$1
TAG=$2
if [ $(basename $(pwd)) != 'robotmk' ]; then
echo "ERROR: You seem to be not in the project root dir. Exiting."
exit 1
fi
if [[ ! "$MODE" =~ release ]]; then
echo "ERROR: Param 1 must be either 'release' or 'unrelease'. Exiting."
exit 1
fi
if [ "x$TAG" == "x" ]; then
echo "ERROR: Param 2 must be a version name without 'v', e.g. 1.0.1. Exiting."
exit 1
fi
if [ ! -x $(which chag) ]; then
echo "ERROR: chag not found."
echo "-> https://github.com/mtdowling/chag"
exit 1
fi
export TAG
export VTAG="$TAG"
export preVTAG="pre-$VTAG"
if [ $MODE == 'release' ]; then
release
elif [ $MODE == 'unrelease' ]; then
unrelease
fi
}
function release() {
assert_gh_login
assert_tag_unique $VTAG
assert_branch $devbranch
assert_notdirty
header "Setting pre-release tag $preVTAG ..."
git tag $preVTAG
header "Moving changelog entries from Unreleased to $TAG ..."
chag update $TAG
header "Committing: 'CHANGELOG: $VTAG'"
git add . && git commit -m "CHANGELOG: $VTAG"
header "Replacing Robotmk version in repository ..."
grep -Hlr 'ROBOTMK_VERSION =' * | grep -v release | xargs sed -i '' -e "s/ROBOTMK_VERSION =.*/ROBOTMK_VERSION = '$VTAG'/"
header "Committing: 'Version bump $VTAG'"
git add . && git commit -m "Version bump: $VTAG"
echo "Workflow result and artifacts are on https://github.com/elabit/robotmk/actions/workflows/mkp-artifact.yml!"
header "Merging $devbranch into $stablebranch..."
git checkout $stablebranch
git merge $devbranch --no-ff --no-edit --strategy-option theirs
header "Create annotated git tag from Changelog entry ..."
chag tag
header "Pushing ..."
git push origin $stablebranch
git push origin $VTAG
git checkout $devbranch
}
function unrelease() {
assert_gh_login
assert_branch $devbranch
header "Removing the release with tag $VTAG ..."
gh release delete $VTAG -y
header "Removing tags ..."
git push origin :refs/tags/$VTAG
header "Removing tags ..."
git tag -d $VTAG
read -p "Do you want to reset the '$devbranch' branch to the tag $preVTAG? (y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
git reset --hard $preVTAG
git tag -d $preVTAG
fi
}
function assert_branch {
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$BRANCH" != $1 ]]; then
echo "ERROR: You are not in branch '$1'. Exiting."
exit 1
fi
}
function assert_notdirty {
if [ -n "$(git status --porcelain)" ]; then
echo "ERROR: The working area is dirty; please commit first! Exiting."
exit 1
fi
}
function header() {
echo "========================="
echo "$1"
}
function assert_gh_login() {
gh auth status 2>&1 > /dev/null
if [ $? -gt 0 ]; then
echo "ERROR: you do not seem to be logged in with gh CLI. Exiting."
exit 1
fi
}
function assert_tag_unique(){
git tag | egrep -q "^$1$"
if [ $? -eq 0 ]; then
echo "ERROR: Tag $1 exists already. Exiting."
exit 1
fi
}
main $@