bin/version
#!/usr/bin/env bash
# bail if git staging area is dirty
if ! git diff --cached --exit-code; then
echo "Git staging area is dirty. Please commit or reset first."
exit 1
fi
current_version=$(git describe --tags --abbrev=0 | sed s/^v//)
IFS='.' read -ra current_version_parts <<< "$current_version"
case "$1" in
"bump:major")
current_version_parts[0]=$((current_version_parts[0] + 1))
current_version_parts[1]=0
current_version_parts[2]=0
;;
"bump:minor")
current_version_parts[1]=$((current_version_parts[1] + 1))
current_version_parts[2]=0
;;
"bump:patch")
current_version_parts[2]=$((current_version_parts[2] + 1))
;;
*)
echo "No valid command provided"
exit 1
;;
esac
new_version=$(IFS='.'; echo "${current_version_parts[*]}")
changelog=$(cat CHANGELOG.md)
changelog_new=$(npm run changelog --silent | tail -n +2)
changelog_new=${changelog_new//Unreleased/$new_version}
# Update the changelog with the new version section
echo "$changelog_new
$changelog" > CHANGELOG.md
# Add a version commit and a git tag
git add CHANGELOG.md
git commit -m "version ${new_version}"
git tag "${new_version}"
printf "\n"
echo "✔ Version was bumped from $current_version to $new_version"
printf "\n"
read -rp "👇 Check the commit if the changes are sound, then 'git push && git push --tags'. Press <enter> to continue."
git show