diff --git a/.github/actions/okd-version/action.yaml b/.github/actions/okd-version/action.yaml index 63a0bfb1..57503590 100644 --- a/.github/actions/okd-version/action.yaml +++ b/.github/actions/okd-version/action.yaml @@ -14,8 +14,8 @@ runs: shell: bash run: | sudo apt-get install -y jq - # Get the latest OKD version tag - okd_version_tag="$(curl -s --max-time 60 https://quay.io/api/v1/repository/okd/scos-release/tag/ | jq -r ".tags[].name" | sort | tail -1)" + # Compute the latest OKD version tag + okd_version_tag="$(./src/okd/get_version.sh latest)" if [ -z "${okd_version_tag}" ]; then echo "ERROR: No OKD version tag found" exit 1 diff --git a/Makefile b/Makefile index 1c851773..f625cd68 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # Options used in the 'rpm' target USHIFT_GITREF ?= main -OKD_VERSION_TAG ?= $$(curl -s --max-time 60 https://quay.io/api/v1/repository/okd/scos-release/tag/ | jq -r ".tags[].name" | sort | tail -1) +OKD_VERSION_TAG ?= $$(./src/okd/get_version.sh latest) RPM_OUTDIR ?= # Options used in the 'image' target BOOTC_IMAGE_URL ?= quay.io/centos-bootc/centos-bootc diff --git a/src/deb/convert.sh b/src/deb/convert.sh index 7dfa737a..d50ba4dd 100755 --- a/src/deb/convert.sh +++ b/src/deb/convert.sh @@ -47,7 +47,7 @@ for rpm in $(find /mnt -type f -iname "*.rpm" -not -iname "*.src.rpm" | sort -u) exit 1 fi # Save cri-o dependency to a file - crio_ver="$(rpm -qpR "${rpm}" | awk '/cri-o/ {print $3}' | sort -u | head -1 | cut -d. -f1,2)" + crio_ver="$(rpm -qpR "${rpm}" | awk '/cri-o/ {print $3}' | sort -uV | head -1 | cut -d. -f1,2)" [ -n "${crio_ver}" ] && echo "CRIO_VERSION=${crio_ver}" >> "dependencies.txt" done diff --git a/src/okd/get_version.sh b/src/okd/get_version.sh new file mode 100755 index 00000000..4f5e04a1 --- /dev/null +++ b/src/okd/get_version.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -euo pipefail + +function usage() { + echo "Usage: $(basename "$0") " >&2 + echo "" >&2 + echo "Get the latest OKD version tag based on the specified 'x.y' or 'latest' command line argument" >&2 + exit 1 +} + +function get_okd_version_tags() { + local -r query_file="$1" + + local npage=1 + local more_pages=true + + while [ "${more_pages}" = "true" ]; do + local query_url="https://quay.io/api/v1/repository/okd/scos-release/tag/?limit=100&page=${npage}" + local query_response + + if ! query_response="$(curl -s --max-time 60 "${query_url}")" ; then + echo "ERROR: Failed to query the OKD version tags from '${query_url}'" >&2 + exit 1 + fi + + # Save the current page content to the query file + if ! echo "${query_response}" | jq -r ".tags[].name" >> "${query_file}" ; then + echo "ERROR: Failed to save the current page content to '${query_file}'" >&2 + exit 1 + fi + # Check if there are more pages to query + if ! more_pages="$(echo "${query_response}" | jq -r '.has_additional')" ; then + echo "ERROR: Failed to check if there are more pages to query from '${query_url}'" >&2 + exit 1 + fi + # Increment the page number + npage=$(( npage + 1 )) + done +} + +# +# Main +# +if [ $# -ne 1 ]; then + usage +fi +OKD_XY="$1" + +version_file="$(mktemp /tmp/okd-version-XXXXXX)" +query_file="$(mktemp /tmp/okd-query-XXXXXX)" +trap 'rm -f "${version_file}" "${query_file}"' EXIT + +# Read all version tags from the Quay repository +get_okd_version_tags "${query_file}" + +# Compute the latest OKD x.y base version if 'latest' is specified +if [ "${OKD_XY}" = "latest" ]; then + OKD_XY="$(cat "${query_file}" | sort -V | tail -1)" + OKD_XY="${OKD_XY%.*}" +fi + +# Filter the version tags for the specified 'x.y' base version +cat "${query_file}" | grep "^${OKD_XY}" | sort -V > "${version_file}" || true +if [ ! -s "${version_file}" ]; then + echo "ERROR: No OKD version tags found for the specified '${OKD_XY}' base version" >&2 + exit 1 +fi + +# Get the latest version tag giving priority to the released versions +OKD_TAG="$(grep -Ev '\.rc\.|\.ec\.' "${version_file}" | tail -1 || true)" +# If no released version tag is found, use the latest version tag +if [ -z "${OKD_TAG}" ]; then + OKD_TAG="$(tail -1 "${version_file}")" +fi + +echo "${OKD_TAG}"