diff --git a/ci-automation/ci_automation_common.sh b/ci-automation/ci_automation_common.sh index 412bb4ac7a..ac71b04ffe 100644 --- a/ci-automation/ci_automation_common.sh +++ b/ci-automation/ci_automation_common.sh @@ -23,7 +23,7 @@ function check_version_string() { function update_and_push_version() { local version="$1" - local push_to_branch="${2:-false}" + local target_branch="${2:-}" # set up author and email so git does not complain when tagging if ! git config --get user.name >/dev/null 2>&1 ; then @@ -64,9 +64,8 @@ function update_and_push_version() { git tag -f "${TAG_ARGS[@]}" "${version}" - if [ "${push_to_branch}" = "true" ]; then - local branch="$(git rev-parse --abbrev-ref HEAD)" - git push origin "${branch}" + if [[ -n "${target_branch}" ]]; then + git push origin "HEAD:${target_branch}" fi git push origin "${version}" diff --git a/ci-automation/packages-tag.sh b/ci-automation/packages-tag.sh index 2faa0dc8f8..2a7408e817 100644 --- a/ci-automation/packages-tag.sh +++ b/ci-automation/packages-tag.sh @@ -68,11 +68,11 @@ function _packages_tag_impl() { # 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'/'flatcar-MAJOR' branch AND we're definitely ON the respective branch - local push_branch="false" + # build of the 'flatcar-MAJOR' branch AND we're definitely ON the respective branch + local target_branch='' if [[ "${version}" =~ ^(stable|alpha|beta|lts)-[0-9.]+-nightly-[-0-9]+$ ]] \ && [[ "$(git rev-parse --abbrev-ref HEAD)" =~ ^flatcar-[0-9]+$ ]] ; then - push_branch="true" + target_branch="$(git rev-parse --abbrev-ref HEAD)" local existing_tag="" # Check for the existing tag only when we allow shortcutting # the builds. That way we can skip the checks for build @@ -108,7 +108,7 @@ function _packages_tag_impl() { source sdk_lib/sdk_container_common.sh create_versionfile "$sdk_version" "$version" ) - update_and_push_version "${version}" "${push_branch}" + update_and_push_version "${version}" "${target_branch}" apply_local_patches } # -- diff --git a/ci-automation/sdk_bootstrap.sh b/ci-automation/sdk_bootstrap.sh index a270747c04..8b9c719ffc 100644 --- a/ci-automation/sdk_bootstrap.sh +++ b/ci-automation/sdk_bootstrap.sh @@ -78,10 +78,10 @@ function _sdk_bootstrap_impl() { # 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. # This includes intermediate SDKs when doing 2-phase nightly builds. - local push_branch="false" + local target_branch='' if [[ "${version}" =~ ^main-[0-9.]+-nightly-[-0-9]+(-INTERMEDIATE)?$ ]] \ - && [ "$(git rev-parse --abbrev-ref HEAD)" = "main" ] ; then - push_branch="true" + && [ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ] ; then + target_branch='main' local existing_tag="" # Check for the existing tag only when we allow shortcutting # the builds. That way we can skip the checks for build @@ -132,7 +132,7 @@ function _sdk_bootstrap_impl() { source sdk_lib/sdk_container_common.sh create_versionfile "${vernum}" ) - update_and_push_version "${version}" "${push_branch}" + update_and_push_version "${version}" "${target_branch}" apply_local_patches ./bootstrap_sdk_container -x ./ci-cleanup.sh "${seed_version}" "${vernum}"