From ba79258a4ff1d14c62426c4a4ad6958e19d2b49c Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 29 Sep 2023 12:57:58 +0200 Subject: [PATCH] ci-automation/image-changes: Fix some redirection issues First issue is that on Jenkins, the beginning of the output seems to be eaten, leaving us only the final part of the reports. This looks like an issue stemming from redirecting stdout to stdout with ">/dev/stdout". Special case the stdout by not redirecting anything in such case. Second issue is that errors printed by the tools we use for generating the reports go to stderr, so they don't show in the report. So redirect their stderr to stdout, so the possible errors are visible in the report file too. We do not want to redirect the stderr of the print_image_reports function, because that would also capture debugging stuff from "set -x" that GitHub Actions are using. --- ci-automation/image_changes.sh | 47 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/ci-automation/image_changes.sh b/ci-automation/image_changes.sh index 8f1426a169..16d271b7ca 100644 --- a/ci-automation/image_changes.sh +++ b/ci-automation/image_changes.sh @@ -83,7 +83,7 @@ function image_changes() ( echo "Image URL: http://${BUILDCACHE_SERVER}/images/${arch}/${vernum}/flatcar_production_image.bin.bz2" echo generate_image_changes_report \ - "${arch}" "${channel}" "${vernum}" /dev/stdout "${fbs_repo}" "${work_directory}" \ + "${arch}" "${channel}" "${vernum}" '-' "${fbs_repo}" "${work_directory}" \ "${package_diff_env[@]}" --- "${package_diff_params_b[@]}" -- \ "${size_changes_env[@]}" --- "${size_changes_params_b[@]}" -- \ "${show_changes_env[@]}" --- "${show_changes_params_overrides[@]}" @@ -177,14 +177,21 @@ function generate_image_changes_report() ( "${show_changes_params[@]}" ) - { - # Using "|| :" to avoid failing the job. - print_image_reports \ - "${flatcar_build_scripts_repo}" "${channel_a}" "${version_a}" "${work_directory}" \ - "${package_diff_env[@]}" --- "${package_diff_params[@]}" -- \ - "${size_changes_env[@]}" --- "${size_changes_params[@]}" -- \ - "${show_changes_env[@]}" --- "${show_changes_params[@]}" || : - } >"${report_output}" + local print_image_reports_invocation=( + print_image_reports + "${flatcar_build_scripts_repo}" "${channel_a}" "${version_a}" "${work_directory}" + "${package_diff_env[@]}" --- "${package_diff_params[@]}" -- + "${size_changes_env[@]}" --- "${size_changes_params[@]}" -- + "${show_changes_env[@]}" --- "${show_changes_params[@]}" + ) + # Using "|| :" to avoid failing the job. + if [[ ${report_output} = '-' ]]; then + "${print_image_reports_invocation[@]}" || : + else + { + "${print_image_reports_invocation[@]}" || : + } >"${report_output}" + fi ) # -- @@ -301,25 +308,25 @@ function print_image_reports() { env \ --chdir="${work_directory}" \ "${package_diff_env[@]}" FILE=flatcar_production_image_packages.txt \ - "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" + "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" 2>&1 echo echo "Image file changes, compared to ${channel_a} ${version_a}:" env \ --chdir="${work_directory}" \ "${package_diff_env[@]}" FILE=flatcar_production_image_contents.txt FILESONLY=1 CUTKERNEL=1 \ - "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" + "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" 2>&1 echo echo "Image kernel config changes, compared to ${channel_a} ${version_a}:" env \ --chdir="${work_directory}" \ "${package_diff_env[@]}" FILE=flatcar_production_image_kernel_config.txt \ - "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" + "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" 2>&1 echo echo "Image init ramdisk file changes, compared to ${channel_a} ${version_a}:" env \ --chdir="${work_directory}" \ "${package_diff_env[@]}" FILE=flatcar_production_image_initrd_contents.txt FILESONLY=1 \ - "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" + "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" 2>&1 echo local size_changes_invocation=( @@ -329,13 +336,13 @@ function print_image_reports() { "${flatcar_build_scripts_repo}/size-change-report.sh" ) echo "Image file size changes, compared to ${channel_a} ${version_a}:" - if ! "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:wtd}"; then - "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:old}" + if ! "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:wtd}" 2>&1; then + "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:old}" 2>&1 fi echo echo "Image init ramdisk file size changes, compared to ${channel_a} ${version_a}:" - if ! "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:initrd-wtd}"; then - "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:initrd-old}" + if ! "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:initrd-wtd}" 2>&1; then + "${size_changes_invocation[@]}" "${size_change_report_params[@]/%/:initrd-old}" 2>&1 fi echo "Take the total size difference with a grain of salt as normally initrd is compressed, so the actual difference will be smaller." echo "To see the actual difference in size, see if there was a report for /boot/flatcar/vmlinuz-a." @@ -346,7 +353,7 @@ function print_image_reports() { env \ --chdir="${work_directory}" \ "${package_diff_env[@]}" FILE=flatcar_production_image_contents.txt CALCSIZE=1 \ - "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" + "${flatcar_build_scripts_repo}/package-diff" "${package_diff_params[@]}" 2>&1 echo local param @@ -359,7 +366,7 @@ function print_image_reports() { "${show_changes_env[@]}" \ "${flatcar_build_scripts_repo}/show-changes" \ "${SHOW_CHANGES_NEW_CHANNEL}-${SHOW_CHANGES_NEW_CHANNEL_PREV_VERSION}" \ - "${SHOW_CHANGES_NEW_VERSION}" + "${SHOW_CHANGES_NEW_VERSION}" 2>&1 # See if a channel transition happened and print the changelog against ${channel_a} ${version_a} which is the previous release if [ "${channel_a}" != "${SHOW_CHANGES_NEW_CHANNEL}" ]; then env \ @@ -367,7 +374,7 @@ function print_image_reports() { "${show_changes_env[@]}" \ "${flatcar_build_scripts_repo}/show-changes" \ "${channel_a}-${version_a}" \ - "${SHOW_CHANGES_NEW_VERSION}" + "${SHOW_CHANGES_NEW_VERSION}" 2>&1 fi } # --