Skip to content

Commit ceef546

Browse files
committed
Annotate first build failure in workflow
1 parent 374f58d commit ceef546

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/build-android-arm64.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787
cat tensorflow-core/tensorflow-core-api/.tf_configure.bazelrc
8888
8989
- name: Build Android ARM64 Native Libraries
90+
id: build_android
9091
shell: bash
9192
run: |
9293
set -o pipefail
@@ -114,6 +115,62 @@ jobs:
114115
-am \
115116
package 2>&1 | tee "${GITHUB_WORKSPACE}/artifacts/build.log"
116117
118+
- name: Summarize First Build Failure
119+
if: failure() && steps.build_android.outcome == 'failure'
120+
shell: bash
121+
run: |
122+
python3 - <<'PY'
123+
import re
124+
from pathlib import Path
125+
126+
log_path = Path("artifacts/build.log")
127+
if not log_path.exists():
128+
print("::error::build.log was not produced")
129+
raise SystemExit(0)
130+
131+
lines = log_path.read_text(encoding="utf-8", errors="ignore").splitlines()
132+
patterns = [
133+
re.compile(r"^(ERROR: .+)$"),
134+
re.compile(r"^(FAILED: .+)$"),
135+
re.compile(r"^(.+?:\d+(?::\d+)?: (?:fatal )?error: .+)$"),
136+
re.compile(r"^(.+?UnsatisfiedLinkError.+)$"),
137+
re.compile(r"^(.+?NoSuch.+)$"),
138+
]
139+
140+
skip = (
141+
"Failed to execute goal org.bytedeco:javacpp",
142+
"Execution javacpp-build of goal",
143+
"Process exited with an error: 1",
144+
"BUILD FAILURE",
145+
)
146+
147+
hit = None
148+
for i, line in enumerate(lines):
149+
if any(token in line for token in skip):
150+
continue
151+
if any(p.search(line) for p in patterns):
152+
hit = i
153+
break
154+
155+
if hit is None:
156+
hit = max(0, len(lines) - 80)
157+
158+
start = max(0, hit - 8)
159+
end = min(len(lines), hit + 20)
160+
snippet = "\n".join(lines[start:end]).strip()
161+
if not snippet:
162+
snippet = "\n".join(lines[-40:]).strip()
163+
164+
summary_path = Path("artifacts/first_failure_summary.txt")
165+
summary_path.write_text(snippet + "\n", encoding="utf-8")
166+
167+
headline = lines[hit].strip() if lines else "Build failed without captured output"
168+
headline = headline.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
169+
print(f"::error::{headline[:400]}")
170+
print("First failure summary:")
171+
print(snippet)
172+
PY
173+
117174
- name: Collect Artifacts
118175
if: always()
119176
shell: bash

0 commit comments

Comments
 (0)