ci: Print a helpful link to download and view a failed test's journal

This commit is contained in:
Daan De Meyer 2024-05-07 12:24:51 +02:00
parent ca2e19f2b7
commit a77f65d0c9

View file

@ -9,6 +9,7 @@ with the expectation that as part of formally defining the API it will be tidy.
'''
import argparse
import json
import os
import shlex
import subprocess
@ -154,16 +155,34 @@ def main():
exit(0 if result.returncode == 123 else 77)
if journal_file:
cmd = [
'journalctl',
'--no-hostname',
'-o', 'short-monotonic',
'--file', journal_file,
'-u', test_unit,
'-p', 'info',
]
ops = []
if os.getenv("GITHUB_ACTIONS"):
id = os.environ["GITHUB_RUN_ID"]
iteration = os.environ["GITHUB_RUN_ATTEMPT"]
j = json.loads(
subprocess.run(
[
"mkosi",
"--directory", os.fspath(args.meson_source_dir),
"--json",
"summary",
],
stdout=subprocess.PIPE,
text=True,
).stdout
)
images = {image["Image"]: image for image in j["Images"]}
distribution = images["system"]["Distribution"]
release = images["system"]["Release"]
artifact = f"ci-mkosi-{id}-{iteration}-{distribution}-{release}-failed-test-journals"
ops += [f"gh run download {id} --name {artifact} -D ci/{artifact}"]
journal_file = Path(f"ci/{artifact}/test/journal/{name}.journal")
ops += [f"journalctl --file {journal_file} --no-hostname -o short-monotonic -u {test_unit} -p info"]
print("Test failed, relevant logs can be viewed with: \n\n"
f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
f"{(' && '.join(ops))}\n", file=sys.stderr)
# 0 also means we failed so translate that to a non-zero exit code to mark the test as failed.
exit(result.returncode or 1)