From 2b1a3cf9cdb4cde92d14217b743545eccdcb2991 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 7 Jul 2023 06:38:03 -0400 Subject: SL-18837: Use multi-line GitHub outputs to upload artifacts. Having observed installer upload failures, I discovered the warning in actions/upload-artifact/README.md about multiple concurrent jobs trying to post the same pathname to the same artifact name. Try to disambiguate artifacts not only for different platforms, but for different jobs running on the same platform. This change also reflects my understanding that an artifact is (effectively) a distinct zip file that can contain multiple uploaded files. Because we'll want to download metadata without having to download enormous installers, create a separate metadata artifact per platform. Similarly, symbol files can get large: use a third distinct artifact for symbol files. But with those artifacts defined, leverage actions/upload-artifact's ability to upload multiple paths to the same artifact. In build.sh, define bash arrays installer, metadata, symbolfile and set up so that, on exit, each is written to a GITHUB_OUTPUT variable with the corresponding name. This involves a little magic to get macOS bash 3 to indirectly access an array. These multi-line output variables are then used to drive the upload-artifact step for each of the defined artifacts. --- build.sh | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index c50bf1df9d..bd3e84d7bd 100755 --- a/build.sh +++ b/build.sh @@ -16,6 +16,8 @@ # * The special style in which python is invoked is intentional to permit # use of a native python install on windows - which requires paths in DOS form +cleanup="true" + retry_cmd() { max_attempts="$1"; shift @@ -111,24 +113,28 @@ installer_CYGWIN() } [[ -n "$GITHUB_OUTPUT" ]] || fatal "Need to export GITHUB_OUTPUT" - -addoutput() -{ - local varname="$1" - local value="$2" - echo "${varname}_name=$(basename "$value")" >> "$GITHUB_OUTPUT" - echo "${varname}_path=$value" >> "$GITHUB_OUTPUT" -} - -# For variable numbers of output values, separate them one per line. -addarrayoutput() +# The following is based on the Warning for GitHub multiline output strings: +# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings +EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + +# Build up these arrays as we go +installer=() +metadata=() +symbolfile=() +# and dump them to GITHUB_OUTPUT when done +cleanup="$cleanup ; arrayoutput installer ; arrayoutput metadata ; arrayoutput symbolfile" +trap "$cleanup" EXIT + +arrayoutput() { - local varname="$1" - # indirection: specify the *name* of the array to emit - local -n arrayname="$2" + local outputname="$1" + # append "[*]" to the array name so array indirection works + local array="$1[*]" local IFS=' ' - echo "$varname=${arrayname[*]}" >> "$GITHUB_OUTPUT" + echo "$outputname<<$EOF +${!array} +$EOF" >> "$GITHUB_OUTPUT" } pre_build() @@ -216,7 +222,8 @@ package_llphysicsextensions_tpv() # capture the package file name for use in upload later... PKGTMP=`mktemp -t pgktpv.XXXXXX` - trap "rm $PKGTMP* 2>/dev/null" 0 + cleanup="$cleanup ; rm $PKGTMP* 2>/dev/null" + trap "$cleanup" EXIT "$autobuild" package --quiet --config-file "$tpvconfig" --results-file "$(native_path $PKGTMP)" || fatal "failed to package llphysicsextensions_tpv" tpv_status=$? if [ -r "${PKGTMP}" ] @@ -390,7 +397,7 @@ do begin_section "Autobuild metadata" python_cmd "$helpers/codeticket.py" addoutput "Autobuild Metadata" "$build_dir/autobuild-package.xml" --mimetype text/xml \ || fatal "Upload of autobuild metadata failed" - addoutput autobuild_package "$build_dir/autobuild-package.xml" + metadata+=("$build_dir/autobuild-package.xml") if [ "$arch" != "Linux" ] then record_dependencies_graph "$build_dir/autobuild-package.xml" # defined in buildscripts/hg/bin/build.sh @@ -406,7 +413,7 @@ do begin_section "Viewer Version" python_cmd "$helpers/codeticket.py" addoutput "Viewer Version" "$(<"$build_dir/newview/viewer_version.txt")" --mimetype inline-text \ || fatal "Upload of viewer version failed" - addoutput viewer_version "$(<"$build_dir/newview/viewer_version.txt")" + metadata+=("$build_dir/newview/viewer_version.txt") end_section "Viewer Version" fi ;; @@ -415,14 +422,14 @@ do then record_event "Doxygen warnings generated; see doxygen_warnings.log" python_cmd "$helpers/codeticket.py" addoutput "Doxygen Log" "$build_dir/doxygen_warnings.log" --mimetype text/plain ## TBD - addoutput doxygen_log "$build_dir/doxygen_warnings.log" + metadata+=("$build_dir/doxygen_warnings.log") fi if [ -d "$build_dir/doxygen/html" ] then tar -c -f "$build_dir/viewer-doxygen.tar.bz2" --strip-components 3 "$build_dir/doxygen/html" python_cmd "$helpers/codeticket.py" addoutput "Doxygen Tarball" "$build_dir/viewer-doxygen.tar.bz2" \ || fatal "Upload of doxygen tarball failed" - addoutput doxygen_tarball "$build_dir/viewer-doxygen.tar.bz2" + metadata+=("$build_dir/viewer-doxygen.tar.bz2") fi ;; *) @@ -538,7 +545,7 @@ then retry_cmd 4 30 python_cmd "$helpers/codeticket.py" addoutput Installer "$package" \ || fatal "Upload of installer failed" wait_for_codeticket - packages=("$package") + installer+=("$package") # Upload additional packages. for package_id in $additional_packages @@ -549,14 +556,12 @@ then retry_cmd 4 30 python_cmd "$helpers/codeticket.py" addoutput "Installer $package_id" "$package" \ || fatal "Upload of installer $package_id failed" wait_for_codeticket - packages+=("$package") + installer+=("$package") else record_failure "Failed to find additional package for '$package_id'." fi done - addarrayoutput viewer_packages packages - if [ "$last_built_variant" = "Release" ] then # nat 2016-12-22: without RELEASE_CRASH_REPORTING, we have no symbol file. @@ -566,7 +571,7 @@ then retry_cmd 4 30 python_cmd "$helpers/codeticket.py" addoutput "Symbolfile" "$VIEWER_SYMBOL_FILE" \ || fatal "Upload of symbolfile failed" wait_for_codeticket - addoutput symbolfile "$VIEWER_SYMBOL_FILE" + symbolfile+=("$VIEWER_SYMBOL_FILE") fi # Upload the llphysicsextensions_tpv package, if one was produced -- cgit v1.2.3