From 073f5c03064e811cd75512600c4fac70e0fce1e4 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 2 Jun 2023 13:12:53 +0300 Subject: [PATCH] ci: fix ordering of error output of the cross compilation workflow (#3809) --- .github/workflows/cross-compile.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cross-compile.sh b/.github/workflows/cross-compile.sh index ff5b67fc4..cd526223f 100755 --- a/.github/workflows/cross-compile.sh +++ b/.github/workflows/cross-compile.sh @@ -12,7 +12,22 @@ if [[ "$goos" == "android" ]]; then exit; fi # Cgo would then need a C cross compilation setup. Not worth the hassle. if [[ "$goos" == "ios" ]]; then exit; fi -echo "$dist" +# Write all log output to a temporary file instead of to stdout. +# That allows running this script in parallel, while preserving the correct order of the output. +log_file=$(mktemp) + +error_handler() { + cat "$log_file" >&2 + rm "$log_file" + exit 1 +} + +trap 'error_handler' ERR + +echo "$dist" >> "$log_file" out="main-$goos-$goarch" -GOOS=$goos GOARCH=$goarch go build -o $out example/main.go +GOOS=$goos GOARCH=$goarch go build -o $out example/main.go >> "$log_file" 2>&1 rm $out + +cat "$log_file" +rm "$log_file"