-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
executable file
·118 lines (101 loc) · 3.2 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
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
#!/bin/bash
# Copyright 2016-2024 Nitor Creations Oy
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
USAGE="Usage: $0 [OPTIONS] [MESSAGE]
Create new release for ndt.
Arguments:
[MESSAGE] Optional commit message for git commit (default is the new version).
OPTIONS: All options are optional
-h | --help Display these instructions.
-d | --dryrun Only print commands instead of executing them.
-m | --major Increment major version and reset minor version to 0.
--message Message for git version tag.
-v | --version [VERSION] Set the new version explicitly.
-x | --verbose Display commands being executed."
init_options() {
DRYRUN=false
INCREMENT_MAJOR=false
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
echo "$USAGE"
exit 1
;;
-d | --dryrun)
DRYRUN=true
;;
-m | --major)
INCREMENT_MAJOR=true
;;
--message)
MESSAGE="$2"
shift
;;
-v | --version)
NEW_VERSION="$2"
shift
;;
-x | --verbose)
set -x
;;
*)
MESSAGE="$1"
;;
esac
shift
done
}
init_options "$@"
# Import common functions
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=./common.sh
source "$DIR/common.sh"
VERSION=$(grep -E '^VERSION' n_utils/__init__.py | cut -d\" -f 2)
MAJOR=${VERSION//.*/}
MINOR=${VERSION##*.}
if [ "$INCREMENT_MAJOR" = true ]; then
echo "Incrementing major version"
MAJOR=$(($MAJOR + 1))
MINOR="0"
NEW_VERSION=$MAJOR.$MINOR
elif [ -z "$NEW_VERSION" ]; then
echo "Incrementing minor version"
MINOR=$(($MINOR + 1))
NEW_VERSION=$MAJOR.$MINOR
fi
echo "Current version: $VERSION"
print_green "New version: $NEW_VERSION"
if [ -z "$MESSAGE" ]; then
print_yellow "No message given, using new version"
MESSAGE="$NEW_VERSION"
fi
print_magenta "Updating command list..."
./update-commandlist.sh
"${SED_COMMAND[@]}" "s/$VERSION/$NEW_VERSION/g" pyproject.toml
"${SED_COMMAND[@]}" "s/## Released version.*/## Released version $NEW_VERSION/g" README.md
"${SED_COMMAND[@]}" "s/^VERSION.*=.*/VERSION\ =\ \"$NEW_VERSION\"/" n_utils/__init__.py
print_magenta "Version tagging release..."
run_command git commit -m "$MESSAGE" pyproject.toml README.md docs/commands.md n_utils/__init__.py
run_command git tag "$NEW_VERSION" -m "$MESSAGE"
run_command git push
run_command git push origin "$NEW_VERSION"
print_magenta "Building package..."
rm -rf dist/*
check_and_set_python
# https://pypa-build.readthedocs.io/en/stable/
$PYTHON -m build
print_magenta "Uploading package..."
$PYTHON -m twine check dist/*
run_command $PYTHON -m twine upload dist/*