diff --git a/operations/update-version.sh b/operations/update-version.sh new file mode 100755 index 0000000..a6907d2 --- /dev/null +++ b/operations/update-version.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Script to update the version number, commit the changes to the version files, +# and tag the new commit. + +set -e + +origDir=$(pwd) +rootDir=$(git rev-parse --show-toplevel) +cd "$rootDir" + +currentBranch=$(git rev-parse --abbrev-ref HEAD) +if [ "$currentBranch" != "develop" ]; then + printf "You are currently on the '%s' branch. Is this intended (yes/no)? " "$currentBranch" + read -r confirmation + + if [ "$confirmation" != "yes" ]; then exit 1; fi +fi + +lastVersion=$(jq -r .version web/package.json) +printf "Last version: %s\n" "$lastVersion" +printf "New version: " +read -r newVersion + +printf "New version will be \"%s\". Is this correct (yes/no)? " "$newVersion" +read -r confirmation + +if [ "$confirmation" != "yes" ]; then + printf "\n" + "$origDir/$0" + exit +fi + +printf ">> Updating /web/package.json with \"version\": \"%s\"\n" "$newVersion" +printf "jq \".version = \\\"%s\\\"\" web/package.json > temp.json\n" "$newVersion" +jq ".version = \"${newVersion}\"" web/package.json > temp.json +printf "mv temp.json web/package.json\n" +mv temp.json web/package.json + +printf ">> Updating /api/src/main/nim/personal_measure_apipkg/version.nim with PM_API_VERSION* = \"%s\"" "$newVersion" +printf "sed -i \"s/%s/%s/\" api/src/main/nim/personal_measure_apipkg/version.nim" "$lastVersion" "$newVersion" +sed -i "s/${lastVersion}/${newVersion}/" api/src/main/nim/personal_measure_apipkg/version.nim + +printf ">> Committing new version.\n" +printf "git add web/package.json api/src/main/nim/personal_measure_apipkg/version.nim" +git add web/package.json api/src/main/nim/personal_measure_apipkg/version.nim +printf "git commit -m \"Update package version to %s\"\n" "$newVersion" +git commit -m "Update package version to ${newVersion}" + +printf ">> Tagging commit.\n" +printf "git tag -m \"Version %s\" \"%s\"\n" "$newVersion" "$newVersion" +git tag -m "Version ${newVersion}" "${newVersion}" +