Skip to content

Commit

Permalink
Resolve TODO: human-readable image-suffixes
Browse files Browse the repository at this point in the history
This conditional was required temporarily so PR #247 could merge.  Remove
and replace it with a version that avoids modifying any files and only
checks if `IMG_SFX` changes were made.

Signed-off-by: Chris Evich <[email protected]>
  • Loading branch information
cevich committed Jan 27, 2023
1 parent 3c24076 commit 6950877
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions ci/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ REPO_DIRPATH=$(realpath "$SCRIPT_DIRPATH/../")
# shellcheck source=./lib.sh
source "$REPO_DIRPATH/lib.sh"

req_env_vars CIRRUS_PR CIRRUS_BASE_SHA
req_env_vars CIRRUS_PR CIRRUS_BASE_SHA CIRRUS_CHANGE_TITLE

# die() will add a reference to this file and line number.
[[ "$CIRRUS_CI" == "true" ]] || \
Expand All @@ -28,24 +28,24 @@ done

# Variable is defined by Cirrus-CI at runtime
# shellcheck disable=SC2154
if ! git diff --name-only ${CIRRUS_BASE_SHA}..HEAD | grep -q IMG_SFX; then
die "Every PR must include an updated IMG_SFX file.
if [[ ! "$CIRRUS_CHANGE_TITLE" =~ CI:DOCS ]] && \
[[ ! "$CIRRUS_CHANGE_TITLE" =~ CI:TOOLING ]] && \
! git diff --name-only ${CIRRUS_BASE_SHA}..HEAD | grep -q IMG_SFX; then

die "Every PR that builds images must include an updated IMG_SFX file.
Simply run 'make IMG_SFX', commit the result, and re-push."
fi

# Verify new IMG_SFX value always sorts later than previous value. This prevents
# screwups due to local timezone, bad, or unset clocks, etc.
cd $REPO_DIRPATH
# Automation requires the date and time components sort properly
# as if they were version-numbers regardless of distro-version component.
new_img_ver=$(awk -F '-' '{print $1"."$2}' ./IMG_SFX)
# TODO: Conditional checkout not needed after the PR which added IMG_SFX file.
if git checkout ${CIRRUS_BASE_SHA} IMG_SFX; then
old_img_ver=$(awk -F '-' '{print $1"."$2}' ./IMG_SFX)
else # IMG_SFX was modified vs PR's base-branch, confirm version moved forward
# shellcheck disable=SC2154
v_prev=$(git show ${CIRRUS_BASE_SHA}:IMG_SFX 2>&1 || true)
# Verify new IMG_SFX value always version-sorts later than previous value.
# This prevents screwups due to local timezone, bad, or unset clocks, etc.
new_img_ver=$(awk -F 't' '{print $1"."$2}' ./IMG_SFX | cut -dz -f1)
old_img_ver=$(awk -F 't' '{print $1"."$2}'<<<"$v_prev" | cut -dz -f1)
# Version-sorting of date/time mimics the way renovate will compare values
# see https://github.com/containers/automation/blob/main/renovate/defaults.json5
latest_img_ver=$(echo -e "$old_img_ver\n$new_img_ver" | sort -V | tail -1)
[[ "$latest_img_ver" == "$new_img_ver" ]] || \
die "Date/time stamp appears to have gone backwards! Please commit
an 'IMG_SFX' change with a value later than '$(<IMG_SFX)'"
else
warn "Could not find previous version of IMG_SFX, ignoring."
die "Updated IMG_SFX '$(<IMG_SFX)' appears to have gone backwards!
Please commit an 'IMG_SFX' change with a value later than '$(v_prev)'"
fi

0 comments on commit 6950877

Please sign in to comment.