Skip to content

Commit

Permalink
Merge pull request #46 from cisagov/improvement/list_version_files
Browse files Browse the repository at this point in the history
Add a new option to the `bump-version` script to list files it updates
  • Loading branch information
mcdonnnj authored Sep 27, 2024
2 parents f56abcc + 2f21cbd commit 2621af2
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions bump-version
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
#!/usr/bin/env bash

# bump-version [--push] [--label LABEL] (major | minor | patch | prerelease | build | finalize | show)
# bump-version --list-files

set -o nounset
set -o errexit
set -o pipefail

# Stores the canonical version for the project.
VERSION_FILE=config/version.txt
README_FILE=README.md
# Files that should be updated with the new version.
VERSION_FILES=("$VERSION_FILE" README.md)

USAGE=$(
cat << END_OF_LINE
Update the version of the project.
Usage:
${0##*/} [--push] [--label LABEL] (major | minor | patch | prerelease | build | finalize | show)
${0##*/} --list-files
${0##*/} (-h | --help)
Options:
-h | --help Show this message.
--push Perform a \`git push\` after updating the version.
--label LABEL Specify the label to use when updating the build or prerelease version.
--list-files List the files that will be updated when the version is bumped.
END_OF_LINE
)

Expand Down Expand Up @@ -105,6 +110,10 @@ else
echo "$USAGE"
exit 0
;;
--list-files)
printf '%s\n' "${VERSION_FILES[@]}"
exit 0
;;
*)
invalid_option "Invalid option: $1"
;;
Expand Down Expand Up @@ -146,11 +155,16 @@ if [ "$with_prerelease" = true ]; then
fi

tmp_file=/tmp/version.$$
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
sed "s/$old_version_regex/$new_version/" $README_FILE > $tmp_file
mv $tmp_file $README_FILE
git add $VERSION_FILE $README_FILE
for version_file in "${VERSION_FILES[@]}"; do
if [ ! -f "$version_file" ]; then
echo Missing expected file: "$version_file"
exit 1
fi
sed "s/$old_version_regex/$new_version/" "$version_file" > $tmp_file
mv $tmp_file "$version_file"
done

git add "${VERSION_FILES[@]}"
git commit --message "$commit_prefix version from $old_version to $new_version"

if [ "$with_push" = true ]; then
Expand Down

0 comments on commit 2621af2

Please sign in to comment.