diff --git a/README.md b/README.md index 14f7ea0..3844f14 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ projects using [Packer](https://www.packer.io/). ```yaml repos: - repo: https://github.com/cisagov/pre-commit-packer - rev: # Version from https://github.com/cisagov/pre-commit-packer/releases + rev: v0.0.2 hooks: - id: packer_validate args: diff --git a/bump_version.sh b/bump_version.sh new file mode 100755 index 0000000..b42c578 --- /dev/null +++ b/bump_version.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# bump_version.sh (show|major|minor|patch|prerelease|build|finalize) + +set -o nounset +set -o errexit +set -o pipefail + +VERSION_FILE=config/version.txt +README_FILE=README.md + +HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)" + +old_version=$(<"$VERSION_FILE") + +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" + tmp_file=/tmp/version.$$ + sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file + mv $tmp_file $VERSION_FILE + sed "s/$old_version/$new_version/" $README_FILE > $tmp_file + mv $tmp_file $README_FILE + git add $VERSION_FILE $README_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" + tmp_file=/tmp/version.$$ + sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file + mv $tmp_file $VERSION_FILE + sed "s/$old_version/$new_version/" $README_FILE > $tmp_file + mv $tmp_file $README_FILE + git add $VERSION_FILE $README_FILE + git commit -m"Bump version from $old_version to $new_version" + git push + ;; + show) + echo "$old_version" + ;; + *) + echo "$HELP_INFORMATION" + ;; + esac +fi diff --git a/config/version.txt b/config/version.txt new file mode 100644 index 0000000..4e379d2 --- /dev/null +++ b/config/version.txt @@ -0,0 +1 @@ +0.0.2 diff --git a/requirements-dev.txt b/requirements-dev.txt index d84ee68..cb51627 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ --requirement requirements-test.txt ipython +semver diff --git a/tag.sh b/tag.sh new file mode 100755 index 0000000..e1f7447 --- /dev/null +++ b/tag.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -o nounset +set -o errexit +set -o pipefail + +version=$(./bump_version.sh show) + +git tag "v$version" && git push --tags