'''
import argparse
+import json
import os
import shlex
import subprocess
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)