-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version.sh
executable file
·114 lines (95 loc) · 2.83 KB
/
bump_version.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
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
get_git_tag() {
git describe --tags $(git rev-list --tags='v[0-9].[0-9]*' --max-count=1) 2> /dev/null
}
get_git_commit() {
git rev-parse --short HEAD
}
error () {
echo -e "${RED}$1${NOCOLOR}"
}
okay () {
echo -e "${GREEN}$1${NOCOLOR}"
}
on_failure () {
if [ $1 -ne 0 ]; then
error "$2 [Return code was not zero but $1.]"
exit
fi
}
######### SEMVER VALIDATION
# https://github.com/fsaintjacques/semver-tool/blob/master/src/semver
# SEMVER_REGEX=""
function validate-version {
if [[ $1 =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo ""
else
error "Version '$1' does not follow correct semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'."
exit
fi
}
#####################################
if [[ $(git diff --stat) != '' ]]; then
error "Repo has unclean state"
exit
fi
OLD_VERSION=$(get_git_tag | cut -d 'v' -f 2)
exec 3>&1;
VERSION=$(dialog --title "Bump Version" --inputbox "New Version (Tag)" 0 0 "${OLD_VERSION} <old>" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
VERSION=$(echo $VERSION | xargs) # strip white spaces
# check if roughly correct semver
validate-version "$VERSION"
if [ $exitcode -eq 0 ]
then
if [ "$VERSION" = "$OLD_VERSION" ] || [ "$VERSION" = "${OLD_VERSION} <old>" ]; then
error "Please use a new version (following semver)"
exit
fi
okay "Bumping version to: $VERSION "
else
error "Could not get tag" >&2
exit
fi
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
SCR="/home/$USER/miniforge3/bin/conda"
__conda_setup="$($SCR 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/$USER/miniforge3/etc/profile.d/conda.sh" ]; then
. "/home/$USER/miniforge3/etc/profile.d/conda.sh"
else
export PATH="/home/$USER/miniforge3/bin:$PATH"
fi
fi
unset __conda_setup
if [ -f "/home/$USER/miniforge3/etc/profile.d/mamba.sh" ]; then
. "/home/$USER/miniforge3/etc/profile.d/mamba.sh"
fi
# <<< conda initialize <<<
mamba activate zest
on_failure $? "Couldn't activate zest environment"
cd $SCRIPT_DIR
cd backend
poetry version ${VERSION}
echo "__version__ = '${VERSION}'" > zest/version.py
cd ../frontend
cider version ${VERSION}+$(($(git rev-list --count HEAD) + 1148))
sed -i "s/pkgver=.*$/pkgver=${VERSION}/g" PKGBUILD
cd ..
git add backend/pyproject.toml
git add backend/zest/version.py
git add frontend/pubspec.yaml
git add frontend/PKGBUILD
git commit -m "Bumping version to ${VERSION}" --no-verify
git tag v${VERSION}
git push
git push --tags