@@ -115,29 +115,36 @@ function RunXcodebuild() {
115
115
116
116
local xcbeautify_cmd=(xcbeautify --renderer github-actions --disable-logging)
117
117
118
- local result=0
119
- NSUnbufferedIO=YES xcodebuild " $@ " 2>&1 | tee " $log_filename " | \
120
- " ${xcbeautify_cmd [@]} " && CheckUnexpectedFailures " $log_filename " \
121
- || result=$?
118
+ # Run xcodebuild and capture the exit status of each command in the pipeline.
119
+ NSUnbufferedIO=YES xcodebuild " $@ " 2>&1 | tee " $log_filename " | " ${xcbeautify_cmd[@]} "
120
+ local pipe_statuses=( " ${PIPESTATUS [@]} " )
121
+ local result=${pipe_statuses[0]}
122
122
123
+ # If the first try failed with a potentially transient error (65), retry once.
123
124
if [[ $result == 65 ]]; then
124
125
ExportLogs " $@ "
125
-
126
126
echo " xcodebuild exited with 65, retrying" 1>&2
127
127
sleep 5
128
128
129
- result=0
130
- NSUnbufferedIO=YES xcodebuild " $@ " 2>&1 | tee " $log_filename " | \
131
- " ${xcbeautify_cmd[@]} " && CheckUnexpectedFailures " $log_filename " \
132
- || result=$?
129
+ NSUnbufferedIO=YES xcodebuild " $@ " 2>&1 | tee " $log_filename " | " ${xcbeautify_cmd[@]} "
130
+ pipe_statuses=(" ${PIPESTATUS[@]} " )
131
+ result=${pipe_statuses[0]}
133
132
fi
134
133
134
+ # If the command failed, print the relevant part of the raw log to avoid noise.
135
135
if [[ $result != 0 ]]; then
136
- echo " xcodebuild exited with $result " 1>&2
137
-
136
+ echo " xcodebuild exited with $result . Showing relevant part of the raw log:" 1>&2
137
+ # This awk script finds the first line matching one of the error patterns
138
+ # and prints from that line to the end of the file. This avoids duplicating
139
+ # successful build output.
140
+ awk ' /error:|fatal:|terminated|\*\* (BUILD|TEST) FAILED \*\*/ {f=1} f' " $log_filename " 1>&2
138
141
ExportLogs " $@ "
139
142
return $result
140
143
fi
144
+
145
+ # If the command succeeded, check for unexpected test failures which don't
146
+ # always cause xcodebuild to return a non-zero exit code.
147
+ CheckUnexpectedFailures " $log_filename " || return $?
141
148
}
142
149
143
150
# Exports any logs output captured in the xcresult
0 commit comments