-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbump_version.sh
executable file
·65 lines (58 loc) · 2.26 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
#!/usr/bin/env bash
# bump_version.sh (show|major|minor|patch|prerelease|build)
# The nix commands used in this file require the installation of Nix: https://nixos.org
set -o nounset
set -o errexit
set -o pipefail
FLAKE_FILE=flake.nix
FLAKE_LOCK_FILE=flake.lock
VERSION_FILE=src/awssh/_version.py
HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"
old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)
# Comment out periods so they are interpreted as periods and don't
# just match any character
old_version_regex=${old_version//\./\\\.}
if [ $# -ne 1 ]; then
echo "$HELP_INFORMATION"
else
case $1 in
major | minor | patch | prerelease | build)
new_version=$(python -c "import semver; print(semver.bump_$1('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
# A temp file is used to provide compatability with macOS development
# as a result of macOS using the BSD version of sed
tmp_file=/tmp/version.$$
tmp_flake=/tmp/flake.tmp
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
sed "s/$old_version_regex/$new_version/" $FLAKE_FILE > $tmp_flake
mv $tmp_flake $FLAKE_FILE
# Run flake update to update the flake.lock file
nix flake update
git add $FLAKE_FILE $FLAKE_LOCK_FILE $VERSION_FILE
git commit -m"Bump version from $old_version to $new_version"
git push
;;
finalize)
new_version=$(python -c "import semver; print(semver.finalize_version('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
# A temp file is used to provide compatability with macOS development
# as a result of macOS using the BSD version of sed
tmp_file=/tmp/version.$$
tmp_flake=/tmp/flake.tmp
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
sed "s/$old_version_regex/$new_version/" $FLAKE_FILE > $tmp_flake
mv $tmp_flake $FLAKE_FILE
git add $FLAKE_FILE $VERSION_FILE
git commit -m"Finalize version from $old_version to $new_version"
git push
;;
show)
echo "$old_version"
;;
*)
echo "$HELP_INFORMATION"
;;
esac
fi