Skip to content

Commit

Permalink
Validate release date on continuous queues manager
Browse files Browse the repository at this point in the history
Before performing the job tasks, we need to make sure that the release
date is properly configured. This can be simply done by making sure
that the current date is not well past the end of the on-sync date,
which is calculated by adding 4 weeks to the configured release date.
(Normally, on-sync ends 2 weeks after the release, but it's set to 4
weeks in this patch just in case we have an unusually longer on-sync
period.)

This commit also moves the parameter validation part to its own
function, so it can be tested on its own.

Additional validation to ensure that the `lastweekdate` is not set
after the `releasedate` has also been added.
  • Loading branch information
junpataleta committed Mar 13, 2024
1 parent 8399dca commit 601e6fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,11 @@ movemax=${movemax:-3}
lastweekdate=${lastweekdate:-$(date -d "${releasedate} -7day" +%Y-%m-%d)}
dryrun=${dryrun:-}

# Verify that $releasedata has a correct YYYY-MM-DD format
if [[ ! ${releasedate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
exit 1
fi

# Verify that $lastweekdate has a correct YYYY-MM-DD format
if [[ ! ${lastweekdate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
exit 1
fi

# Today
nowdate=$(date +%Y%m%d)

run_param_validation $releasedate $lastweekdate

# Decide if we are going to proceed with behaviour A (before release) or behaviour B (after release)
behaviorAB=
if [ $nowdate -lt $(date -d "${releasedate}" +%Y%m%d) ]; then
Expand Down
35 changes: 35 additions & 0 deletions tracker_automations/continuous_manage_queues/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,38 @@ function run_C() {
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} moved out from current: held" >> "${logfile}"
done
}

function run_param_validation() {
releasedate=$1
lastweekdate=$2

# Verify that $releasedate has a correct YYYY-MM-DD format
if [[ ! ${releasedate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
exit 1
fi

# Verify that $lastweekdate has a correct YYYY-MM-DD format
if [[ ! ${lastweekdate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
exit 1
fi

# Verify that the last week date is not after the release date.
releasedateint=$(date -d "${releasedate}" +%Y%m%d)
lastweekdateint=$(date -d "${lastweekdate}" +%Y%m%d)
if [ $releasedateint -lt $lastweekdateint ]; then
echo "ERROR: The value set for \$lastweekdate ($lastweekdate) is after the \$releasedate ($releasedate)"
exit 1
fi

# Verify that the current date is not well past the on-sync period. (Normally 2 weeks but making it 4 weeks just in case).
nowdate=$(date +%Y%m%d)
onsyncenddate=$(date -d "${releasedate} +28day" +%Y%m%d)
if [ $nowdate -gt $onsyncenddate ]; then
echo "ERROR: The current date is already past the on-sync period. Please make sure the Release date ($releasedate) is configured correctly"
exit 1
fi

echo "Parameters validated"
}

0 comments on commit 601e6fb

Please sign in to comment.