Skip to content

Commit 1b25de8

Browse files
committed
refactor: improve build output handling in axon script
- Streamlined the build process to capture output in real-time while also logging it to a temporary file. - Enhanced error handling by checking the exit code of the build command and cleaning up temporary files afterward. - Updated the method for extracting the detected git SHA from the build log, ensuring more reliable retrieval.
1 parent 32c69a0 commit 1b25de8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

axon

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,30 @@ cmd_run() {
275275
build_args+=("$GIT_SHA")
276276
fi
277277

278-
# Capture build output to extract auto-detected git SHA
279-
BUILD_OUTPUT=$("$SCRIPT_DIR/cmd/build.sh" "${build_args[@]}" 2>&1)
280-
BUILD_EXIT_CODE=$?
281-
282-
# Display build output
283-
echo "$BUILD_OUTPUT"
278+
# Run build and capture output for git SHA extraction while streaming to stdout
279+
# Use a temporary file to capture output without buffering
280+
BUILD_LOG=$(mktemp /tmp/axon-build-XXXXXX)
281+
"$SCRIPT_DIR/cmd/build.sh" "${build_args[@]}" 2>&1 | tee "$BUILD_LOG"
282+
BUILD_EXIT_CODE=${PIPESTATUS[0]}
284283

285284
if [ $BUILD_EXIT_CODE -ne 0 ]; then
285+
rm -f "$BUILD_LOG"
286286
echo -e "${RED}✗ Build failed!${NC}"
287287
exit 1
288288
fi
289289

290290
# Extract auto-detected git SHA if present
291291
if [ -z "$GIT_SHA" ] && [ "$SKIP_GIT" = false ]; then
292-
DETECTED_SHA=$(echo "$BUILD_OUTPUT" | grep "GIT_SHA_DETECTED=" | cut -d'=' -f2)
292+
DETECTED_SHA=$(grep "GIT_SHA_DETECTED=" "$BUILD_LOG" | cut -d'=' -f2)
293293
if [ -n "$DETECTED_SHA" ]; then
294294
GIT_SHA="$DETECTED_SHA"
295295
verbose "Captured git SHA from build: $GIT_SHA"
296296
fi
297297
fi
298298

299+
# Clean up temp file
300+
rm -f "$BUILD_LOG"
301+
299302
echo ""
300303
echo -e "${GREEN}✓ Build completed successfully!${NC}"
301304
echo ""

0 commit comments

Comments
 (0)