Skip to content

Commit 117070c

Browse files
authored
Merge pull request #31 from cisagov/improvement/add_version_bump_and_tag_scripts
Add Scripts for Bumping Versions and Tagging
2 parents 2fcac8e + 03278ca commit 117070c

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

bump_version.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
# bump_version.sh (show|major|minor|patch|prerelease|build)
4+
5+
set -o nounset
6+
set -o errexit
7+
set -o pipefail
8+
9+
VERSION_FILE=src/example/_version.py
10+
11+
HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"
12+
13+
old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)
14+
15+
if [ $# -ne 1 ]
16+
then
17+
echo "$HELP_INFORMATION"
18+
else
19+
case $1 in
20+
major|minor|patch|prerelease|build)
21+
new_version=$(python -c "import semver; print(semver.bump_$1('$old_version'))")
22+
echo Changing version from "$old_version" to "$new_version"
23+
# A temp file is used to provide compatability with macOS development
24+
# as a result of macOS using the BSD version of sed
25+
tmp_file=/tmp/version.$$
26+
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
27+
mv $tmp_file $VERSION_FILE
28+
git add $VERSION_FILE
29+
git commit -m"Bump version from $old_version to $new_version"
30+
git push
31+
;;
32+
finalize)
33+
new_version=$(python -c "import semver; print(semver.finalize_version('$old_version'))")
34+
echo Changing version from "$old_version" to "$new_version"
35+
# A temp file is used to provide compatability with macOS development
36+
# as a result of macOS using the BSD version of sed
37+
tmp_file=/tmp/version.$$
38+
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
39+
mv $tmp_file $VERSION_FILE
40+
git add $VERSION_FILE
41+
git commit -m"Bump version from $old_version to $new_version"
42+
git push
43+
;;
44+
show)
45+
echo "$old_version"
46+
;;
47+
*)
48+
echo "$HELP_INFORMATION"
49+
;;
50+
esac
51+
fi

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-r requirements-test.txt
22
ipython
3+
semver

tag.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -o nounset
4+
set -o errexit
5+
set -o pipefail
6+
7+
version=$(./bump_version.sh show)
8+
9+
git tag "v$version" && git push --tags

0 commit comments

Comments
 (0)