From bf603ded1d0f33577fd481caccd235ba622b5cfc Mon Sep 17 00:00:00 2001 From: Nikolay Akhmetov Date: Mon, 19 Aug 2024 15:54:29 -0400 Subject: [PATCH 1/2] update push script to handle major version tags --- etc/build/push.sh | 62 ++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/etc/build/push.sh b/etc/build/push.sh index 0d149181bf..30bf43a635 100755 --- a/etc/build/push.sh +++ b/etc/build/push.sh @@ -9,31 +9,49 @@ git diff --quiet || die 'Uncommitted changes: Stash or commit' git checkout main git pull -get_minor_version() { - REF_MINOR=$1 - REF_DATE=$2 - REF_EPOCH_DAY=`expr $(date -j -f "%d %b %Y" "$REF_DATE" +%s) / 86400` - NOW_EPOCH_DAY=`expr $(date +%s) / 86400` - DAYS_PAST_REF=`expr $NOW_EPOCH_DAY - $REF_EPOCH_DAY` - echo v0.`expr $REF_MINOR + $DAYS_PAST_REF / 14` - # Integer division truncates toward 0 for both positive and negative, - # so this doesn't work if the reference date is in the future. -} - -EXPECTED_MINOR=`get_minor_version 9 '01 JAN 2021'` - -# The docs say that a git tag will be created by default. -# That would be useful, but it doesn't see to be happening for me. -# Add additional flag to override. -# https://docs.npmjs.com/cli/v6/commands/npm-version -VERSION=`cd context && npm version patch --no-git-tag-version` - -if [[ $VERSION != $EXPECTED_MINOR* ]]; then - echo "End of 2-week cycle. Setting minor version to: $EXPECTED_MINOR" - VERSION=`cd context && npm version $EXPECTED_MINOR.0 --no-git-tag-version` +MAJOR=$1 + +if [[ -z "$MAJOR" ]]; then + get_last_minor_version() { + TAGS=`git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags | tac` + # Iterate over tags to find date of last one with patch of .0 + for TAG in $TAGS; do + if [[ $TAG == refs/tags/v* ]]; then + MINOR=`echo $TAG | perl -pne 's/.*v0\.(\d+)\.\d+/\1/'` + if [[ $MINOR -eq $1 ]]; then + REF_DATE=`echo $TAG | perl -pne 's/.*v0\.\d+\.\d+ //'` + break + fi + fi + done + + REF_EPOCH_DAY=`expr $(date -j -f "%d %b %Y" "$REF_DATE" +%s) / 86400` + NOW_EPOCH_DAY=`expr $(date +%s) / 86400` + DAYS_PAST_REF=`expr $NOW_EPOCH_DAY - $REF_EPOCH_DAY` + + echo "Days since last minor version: $DAYS_PAST_REF" + echo v0.`expr $REF_MINOR + $DAYS_PAST_REF / 14` + # Integer division truncates toward 0 for both positive and negative, + # so this doesn't work if the reference date is in the future. + } + + DAYS_PAST_REF=`get_last_minor_version` + + if [[ $DAYS_PAST_REF -lt 14 ]]; then + VERSION=`cd context && npm version patch --no-git-tag-version` + else + echo "End of 2-week cycle." + VERSION=`cd context && npm version minor --no-git-tag-version` + fi +else + # major version bump, don't need to check for 2-week cycle + VERSION=`cd context && npm version major` fi + echo "Version: $VERSION" +die + ./grab-dependencies.sh git add context/package*.json From 0efd6c35ff9881e76d5516fc45de161538a1b7e1 Mon Sep 17 00:00:00 2001 From: Nikolay Akhmetov Date: Mon, 19 Aug 2024 16:25:24 -0400 Subject: [PATCH 2/2] CAT-842 Extended push script to support major version bumps --- CHANGELOG-push-script-cat-842.md | 1 + etc/build/push.sh | 46 ++++++++++++++------------------ 2 files changed, 21 insertions(+), 26 deletions(-) create mode 100644 CHANGELOG-push-script-cat-842.md diff --git a/CHANGELOG-push-script-cat-842.md b/CHANGELOG-push-script-cat-842.md new file mode 100644 index 0000000000..0146877042 --- /dev/null +++ b/CHANGELOG-push-script-cat-842.md @@ -0,0 +1 @@ +- Extended push script to support major version bumps. diff --git a/etc/build/push.sh b/etc/build/push.sh index 30bf43a635..11f0a8fbf7 100755 --- a/etc/build/push.sh +++ b/etc/build/push.sh @@ -12,30 +12,26 @@ git pull MAJOR=$1 if [[ -z "$MAJOR" ]]; then - get_last_minor_version() { - TAGS=`git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags | tac` - # Iterate over tags to find date of last one with patch of .0 - for TAG in $TAGS; do - if [[ $TAG == refs/tags/v* ]]; then - MINOR=`echo $TAG | perl -pne 's/.*v0\.(\d+)\.\d+/\1/'` - if [[ $MINOR -eq $1 ]]; then - REF_DATE=`echo $TAG | perl -pne 's/.*v0\.\d+\.\d+ //'` - break - fi - fi - done - - REF_EPOCH_DAY=`expr $(date -j -f "%d %b %Y" "$REF_DATE" +%s) / 86400` - NOW_EPOCH_DAY=`expr $(date +%s) / 86400` - DAYS_PAST_REF=`expr $NOW_EPOCH_DAY - $REF_EPOCH_DAY` - - echo "Days since last minor version: $DAYS_PAST_REF" - echo v0.`expr $REF_MINOR + $DAYS_PAST_REF / 14` - # Integer division truncates toward 0 for both positive and negative, - # so this doesn't work if the reference date is in the future. - } - - DAYS_PAST_REF=`get_last_minor_version` + NOW_EPOCH_DAY=`expr $(date +%s) / 86400` + + TAGS=`git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags | tac` + while read -r -d $'\n' TAG DATE; do + if [[ $TAG =~ v0\.([0-9]+)\.0$ ]]; then + echo "Last minor tag: $TAG" + # Strip timezone info (last 6 characters) + DATE=${DATE%??????} + # Convert to epoch day + REF_EPOCH_DAY=`expr $(date --date="$DATE" "+%s") / 86400` + echo "Reference epoch day: $REF_EPOCH_DAY" + break + fi + done <<< "$TAGS" + + echo "Now epoch day: $NOW_EPOCH_DAY" + + DAYS_PAST_REF=`expr $NOW_EPOCH_DAY - $REF_EPOCH_DAY` + + echo "Days since last minor version: $DAYS_PAST_REF" if [[ $DAYS_PAST_REF -lt 14 ]]; then VERSION=`cd context && npm version patch --no-git-tag-version` @@ -50,8 +46,6 @@ fi echo "Version: $VERSION" -die - ./grab-dependencies.sh git add context/package*.json