ci-automation: Make tagging code testable through env vars

This commit is contained in:
Krzesimir Nowak 2025-07-08 16:31:17 +02:00
parent 890ec0aba6
commit 1aed1b2be4
3 changed files with 45 additions and 9 deletions

View File

@ -72,6 +72,16 @@ function update_and_push_version() {
}
# --
function check_bincache_images_existence() {
case ${CIA_DEBUGIMAGESEXIST:-} in
'yes') return 0;;
'no' ) return 1;;
'') curl --head --fail --fail-early --silent --show-error --location "${@}" || return 1;;
*) echo "Invalid CIA_DEBUGIMAGESEXIST value (${CIA_DEBUGIMAGESEXIST@Q})" >&2; exit 1;;
esac
}
# --
function copy_from_buildcache() {
local what="$1"
local where_to="$2"

View File

@ -66,14 +66,17 @@ function _packages_tag_impl() {
source sdk_container/.repo/manifests/version.txt
local sdk_version="${FLATCAR_SDK_VERSION}"
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set -x
fi
# Create new tag in scripts repo w/ updated versionfile
# Also push the changes to the branch ONLY IF we're doing a nightly
# build of the 'flatcar-MAJOR' branch AND we're definitely ON the respective branch
local target_branch=''
# These variables are here to make it easier to test nightly
# builds without messing with actual release branches.
local flatcar_branch_prefix='flatcar'
local nightly='nightly'
local flatcar_branch_prefix=${CIA_DEBUGFLATCARBRANCHPREFIX:-flatcar}
local nightly=${CIA_DEBUGNIGHTLY:-nightly}
# Patterns used below.
local nightly_pattern_1='^(stable|alpha|beta|lts)-[0-9.]+-'"${nightly}"'-[-0-9]+$'
local nightly_pattern_2='^(stable|alpha|beta|lts)-[0-9.]+(|-'"${nightly}"'-[-0-9]+)$'
@ -95,8 +98,9 @@ function _packages_tag_impl() {
local ret=0
git diff --exit-code "${existing_tag}" || ret=$?
if [[ ret -eq 0 ]]; then
if curl --head --fail --silent --show-error --location "https://${BUILDCACHE_SERVER}/images/amd64/${FLATCAR_VERSION}/flatcar_production_image.bin.bz2" \
&& curl --head --fail --silent --show-error --location "https://${BUILDCACHE_SERVER}/images/arm64/${FLATCAR_VERSION}/flatcar_production_image.bin.bz2"; then
if check_bincache_images_existence \
"https://${BUILDCACHE_SERVER}/images/amd64/${FLATCAR_VERSION}/flatcar_production_image.bin.bz2" \
"https://${BUILDCACHE_SERVER}/images/arm64/${FLATCAR_VERSION}/flatcar_production_image.bin.bz2"; then
touch ./skip-build
echo "Creating ./skip-build flag file, indicating that the build must not to continue because no new tag got created as there are no changes since tag ${existing_tag} and the Flatcar images exist" >&2
return 0
@ -110,13 +114,22 @@ function _packages_tag_impl() {
fi
fi
fi
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set +x
fi
# Create version file
(
source sdk_lib/sdk_container_common.sh
create_versionfile "$sdk_version" "$version"
)
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set -x
fi
update_and_push_version "${version}" "${target_branch}"
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
exit 0
fi
apply_local_patches
}
# --

View File

@ -74,6 +74,9 @@ function _sdk_bootstrap_impl() {
check_version_string "${version}"
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set -x
fi
# Create new tag in scripts repo w/ updated versionfile.
# Also push the changes to the branch ONLY IF we're doing a nightly
# build of the 'main' branch AND we're definitely ON the main branch.
@ -81,8 +84,8 @@ function _sdk_bootstrap_impl() {
local target_branch=''
# These variables are here to make it easier to test nightly
# builds without messing with actual release branches.
local main_branch='main'
local nightly='nightly'
local main_branch=${CIA_DEBUGMAINBRANCH:-main}
local nightly=${CIA_DEBUGNIGHTLY:-nightly}
# Patterns used below.
local nightly_pattern_1='^main-[0-9.]+-'"${nightly}"'-[-0-9]+(-INTERMEDIATE)?$'
local nightly_pattern_2='^main-[0-9.]+-'"${nightly}"'-[-0-9]+$'
@ -115,9 +118,10 @@ function _sdk_bootstrap_impl() {
local flatcar_version="${versions[1]}"
local sdk_docker_vernum=""
sdk_docker_vernum=$(vernum_to_docker_image_version "${flatcar_sdk_version}")
if curl --head --fail --silent --show-error --location "https://${BUILDCACHE_SERVER}/containers/${sdk_docker_vernum}/flatcar-sdk-all-${sdk_docker_vernum}.tar.zst" \
&& curl --head --fail --silent --show-error --location "https://${BUILDCACHE_SERVER}/images/amd64/${flatcar_version}/flatcar_production_image.bin.bz2" \
&& curl --head --fail --silent --show-error --location "https://${BUILDCACHE_SERVER}/images/arm64/${flatcar_version}/flatcar_production_image.bin.bz2"; then
if check_bincache_images_existence \
"https://${BUILDCACHE_SERVER}/containers/${sdk_docker_vernum}/flatcar-sdk-all-${sdk_docker_vernum}.tar.zst" \
"https://${BUILDCACHE_SERVER}/images/amd64/${flatcar_version}/flatcar_production_image.bin.bz2" \
"https://${BUILDCACHE_SERVER}/images/arm64/${flatcar_version}/flatcar_production_image.bin.bz2"; then
echo "Stopping build because there are no changes since tag ${existing_tag}, the SDK container tar ball and the Flatcar images exist" >&2
return 0
fi
@ -130,6 +134,9 @@ function _sdk_bootstrap_impl() {
fi
fi
fi
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set +x
fi
local vernum="${version#*-}" # remove alpha-,beta-,stable-,lts- version tag
local git_vernum="${vernum}"
@ -139,7 +146,13 @@ function _sdk_bootstrap_impl() {
source sdk_lib/sdk_container_common.sh
create_versionfile "${vernum}"
)
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
set -x
fi
update_and_push_version "${version}" "${target_branch}"
if [[ -n ${CIA_DEBUGTESTRUN:-} ]]; then
exit 0
fi
apply_local_patches
./bootstrap_sdk_container -x ./ci-cleanup.sh "${seed_version}" "${vernum}"