Created
September 12, 2019 00:15
-
-
Save haggen/e264288ebef92c45bd49b2470fa63565 to your computer and use it in GitHub Desktop.
Parse and bump version strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
if test -z "$*"; then | |
echo "Missing argument, e.g. $0 classic/Fastbind" >&2 | |
exit 1 | |
fi | |
if ! test -d "$1"; then | |
echo "$1 is not a directory" >&2 | |
exit 1 | |
fi | |
platform="$(dirname "$1")" | |
name="$(basename "$1")" | |
toc="$platform/$name/$name.toc" | |
if ! test -f "$toc"; then | |
echo "$toc is not a file" >&2 | |
exit 1 | |
fi | |
version="$(grep -Po "Version: \K.+" "$toc")" | |
major="$(echo "$version" | cut -f1 -d.)" | |
minor="$(echo "$version" | cut -f2 -d.)" | |
patch="$(echo "$version" | cut -f3 -d.)" | |
if test $# -eq 1 || test "$2" = "patch"; then | |
patch=$((patch + 1)) | |
elif test "$2" = "minor"; then | |
patch=0 | |
minor=$((minor + 1)) | |
elif test "$2" = "major"; then | |
patch=0 | |
minor=0 | |
major=$((major + 1)) | |
fi | |
if echo sed -i "'s/Version: $version/Version: $major.$minor.$patch/'" "$toc"; then | |
echo "Bumping $1 from $version to $major.$minor.$patch" | |
git commit -m "Bumping $1 from $version to $major.$minor.$patch" "$toc" | |
git tag "$platform/$name/$major.$minor.$patch" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment