From a19e457c81c35f0fa76f9d1cc13049590d20f9c7 Mon Sep 17 00:00:00 2001 From: Ray Douglass <3107146+raydouglass@users.noreply.github.com> Date: Tue, 10 May 2022 15:34:28 -0400 Subject: [PATCH] Update update-version.sh --- ci/release/update-version.sh | 54 ++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index 7a58b2d..ce1709f 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -4,42 +4,30 @@ ######################## ## Usage -# bash update-version.sh -# where is either `major`, `minor`, `patch` +# bash update-version.sh -set -e -# Grab argument for release type -RELEASE_TYPE=$1 +# Format is YY.MM.PP - no leading 'v' or trailing 'a' +NEXT_FULL_TAG=$1 -# Get current version and calculate next versions -CURRENT_TAG=`git tag | grep -xE 'v[0-9\.]+' | sort --version-sort | tail -n 1 | tr -d 'v'` -CURRENT_MAJOR=`echo $CURRENT_TAG | awk '{split($0, a, "."); print a[1]}'` -CURRENT_MINOR=`echo $CURRENT_TAG | awk '{split($0, a, "."); print a[2]}'` -CURRENT_PATCH=`echo $CURRENT_TAG | awk '{split($0, a, "."); print a[3]}'` +# Get current version +CURRENT_TAG=$(git tag --merged HEAD | grep -xE '^v.*' | sort --version-sort | tail -n 1 | tr -d 'v') +CURRENT_MAJOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[1]}') +CURRENT_MINOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[2]}') +CURRENT_PATCH=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[3]}') CURRENT_SHORT_TAG=${CURRENT_MAJOR}.${CURRENT_MINOR} -NEXT_MAJOR=$((CURRENT_MAJOR + 1)) -NEXT_MINOR=$((CURRENT_MINOR + 1)) -NEXT_PATCH=$((CURRENT_PATCH + 1)) -NEXT_FULL_TAG="" -NEXT_SHORT_TAG="" - -# Determine release type -if [ "$RELEASE_TYPE" == "major" ]; then - NEXT_FULL_TAG="${NEXT_MAJOR}.0.0" - NEXT_SHORT_TAG="${NEXT_MAJOR}.0" -elif [ "$RELEASE_TYPE" == "minor" ]; then - NEXT_FULL_TAG="${CURRENT_MAJOR}.${NEXT_MINOR}.0" - NEXT_SHORT_TAG="${CURRENT_MAJOR}.${NEXT_MINOR}" -elif [ "$RELEASE_TYPE" == "patch" ]; then - NEXT_FULL_TAG="${CURRENT_MAJOR}.${CURRENT_MINOR}.${NEXT_PATCH}" - NEXT_SHORT_TAG="${CURRENT_MAJOR}.${CURRENT_MINOR}" -else - echo "Incorrect release type; use 'major', 'minor', or 'patch' as an argument" - exit 1 -fi - -echo "Preparing '$RELEASE_TYPE' release [$CURRENT_TAG -> $NEXT_FULL_TAG]" + +#Get . for next version +NEXT_MAJOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[1]}') +NEXT_MINOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[2]}') +NEXT_SHORT_TAG=${NEXT_MAJOR}.${NEXT_MINOR} + +echo "Preparing release $CURRENT_TAG => $NEXT_FULL_TAG" + +# Inplace sed replace; workaround for Linux and Mac +function sed_runner() { + sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak +} jq -e --arg tag "$NEXT_FULL_TAG" '.version=$tag' package.json > package.json.tmp -mv package.json.tmp package.json \ No newline at end of file +mv package.json.tmp package.json