Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NickAkhmetov/CAT-842 Update push script to handle major version bumps #3510

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-push-script-cat-842.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Extended push script to support major version bumps.
52 changes: 32 additions & 20 deletions etc/build/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,41 @@ 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`
MAJOR=$1

if [[ -z "$MAJOR" ]]; then
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 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`

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`
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"

./grab-dependencies.sh
Expand Down
Loading