]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ci: Print a helpful link to download and view a failed test's journal
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 7 May 2024 10:24:51 +0000 (12:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 7 May 2024 17:06:39 +0000 (19:06 +0200)
test/integration-test-wrapper.py

index 25b903c4e6a3d75d8508e3bc6c00685c68361ed1..fcdc9b6352f745dd90568baab50b304459404ee0 100755 (executable)
@@ -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)