From b6f919cabaf1056ca9763c31c66e180d46622f7d Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Wed, 2 Apr 2025 14:11:59 -0700 Subject: [PATCH] Fix build script outside of CI --- scripts/build.mjs | 50 ++++++++++++++++++++++++----------------------- scripts/utils.mjs | 3 +++ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 38da226cec..0b195674f8 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -267,35 +267,37 @@ async function spawn(command, args, options, label) { return; } - let annotated; - try { - const { annotations } = parseAnnotations(stdoutBuffer); - for (const annotation of annotations) { - const content = formatAnnotationToHtml(annotation); + if (isBuildkite()) { + let annotated; + try { + const { annotations } = parseAnnotations(stdoutBuffer); + for (const annotation of annotations) { + const content = formatAnnotationToHtml(annotation); + reportAnnotationToBuildKite({ + priority: 10, + label: annotation.title || annotation.filename, + content, + }); + annotated = true; + } + } catch (error) { + console.error(`Failed to parse annotations:`, error); + } + + if (!annotated) { + const content = formatAnnotationToHtml({ + filename: relative(process.cwd(), import.meta.filename), + title: "build failed", + content: stdoutBuffer, + source: "build", + level: "error", + }); reportAnnotationToBuildKite({ priority: 10, - label: annotation.title || annotation.filename, + label: "build failed", content, }); - annotated = true; } - } catch (error) { - console.error(`Failed to parse annotations:`, error); - } - - if (!annotated) { - const content = formatAnnotationToHtml({ - filename: relative(process.cwd(), import.meta.filename), - title: "build failed", - content: stdoutBuffer, - source: "build", - level: "error", - }); - reportAnnotationToBuildKite({ - priority: 10, - label: "build failed", - content, - }); } if (signalCode) { diff --git a/scripts/utils.mjs b/scripts/utils.mjs index a4ab086229..a4ad1875fe 100755 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -2637,6 +2637,9 @@ export function parseAnnotations(content, options = {}) { * @param {BuildkiteAnnotation} annotation */ export function reportAnnotationToBuildKite({ context, label, content, style = "error", priority = 3, attempt = 0 }) { + if (!isBuildkite) { + return; + } const { error, status, signal, stderr } = nodeSpawnSync( "buildkite-agent", ["annotate", "--append", "--style", `${style}`, "--context", `${context || label}`, "--priority", `${priority}`],