Skip to content

Commit

Permalink
ci: refactor docker rolling tags logic [skip ci] (#18486)
Browse files Browse the repository at this point in the history
Signed-off-by: Rado <radoslav@dhis2.org>
  • Loading branch information
radnov authored Aug 29, 2024
1 parent 8cefa15 commit 4786ea6
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions dhis-2/build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,47 @@ function create_rolling_tags() {
minor="${image_tag_segments[1]}"
patch="${image_tag_segments[2]}"

# Always create M.m.p and 2.M.m.p
# Always create M.m.p tags.
rolling_tags=(
"$image_tag"
"$old_version_schema_prefix.$image_tag"
)

# If patch(hotfix) is the latest for given minor(patch) create M.m + 2.M.m
latest_hotfix_version="$(
latest_patch_version="$(
echo "$stable_versions_json" |
jq -r --argjson major "$major" --argjson minor "$minor" \
'.versions[] | select(.version == $major) .patchVersions[] | select(.version == $minor) .hotfixVersion' |
sort -n |
tail -1
jq -r --argjson major "$major" \
'.versions[] | select(.version == $major) .latestHotfixVersion'
)"

latest_minor_version="$(
echo "$stable_versions_json" |
jq -r --argjson major "$major" \
'.versions[] | select(.version == $major) | .latestPatchVersion'
)"

latest_major_version="$(
echo "$stable_versions_json" |
jq -r '.versions[] | select(.latest == true) .version'
)"
if [[ "$patch" == "$latest_hotfix_version" ]]; then
echo "The patch version $patch is the latest for the minor version $minor"

if [[ "$major" -gt "$latest_major_version" ]] || \
[[ "$minor" -gt "$latest_minor_version" && "$major" -eq "$latest_major_version" ]] || \
[[ "$patch" -ge "$latest_patch_version" && "$minor" -eq "$latest_minor_version" ]]; then
echo "New major, new minor or new/existing patch for the latest minor version, creating M.m and M tags."
rolling_tags+=(
"$major.$minor"
"$major"
"$old_version_schema_prefix.$major.$minor"
"$old_version_schema_prefix.$major"
)
fi

# If version is the latest create M + 2.M
latest_version="$(
echo "$stable_versions_json" |
jq -r --argjson major "$major" \
'.versions[] | select(.version == $major) | "\(.version).\(.latestPatchVersion).\(.latestHotfixVersion)"'
)"
if [[ "$image_tag" == "$latest_version" ]]; then
echo "Version $image_tag is the latest version for the supported major version $major"
rolling_tags+=(
"$major"
"$old_version_schema_prefix.$major"
)
if [[ "$patch" -gt "$latest_patch_version" && "$minor" -lt "$latest_minor_version" ]]; then
echo "New patch for a non-latest minor version, creating M.m tags."
rolling_tags+=(
"$major.$minor"
"$old_version_schema_prefix.$major.$minor"
)
fi
}

Expand Down

0 comments on commit 4786ea6

Please sign in to comment.