Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
summary.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file summary.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import argparse
5 import re
6 import functools
7 import os
8 import csv
9 
10 HERALD_URL = "https://herald.dokku.paulgessinger.com/view/{repo}/runs/{run_id}/artifacts/{artifact_name}/{path}"
11 IS_CI = "GITHUB_ACTIONS" in os.environ
12 
13 
14 parser = argparse.ArgumentParser()
15 parser.add_argument("results")
16 parser.add_argument("--html")
17 parser.add_argument("--md")
18 args = parser.parse_args()
19 
20 re_title = re.compile(r'<p class="title">\s*(.*)\s*<\/p>', re.RegexFlag.MULTILINE)
21 re_check = re.compile(r'<a.*title="(.*)">\s*(.)\s*<\/a>', re.RegexFlag.MULTILINE)
22 
23 summary = []
24 
25 with open(args.results) as f:
26  reader = csv.reader(f)
27  for title, slug, ec in reader:
28  summary.append(
29  {
30  "title": title,
31  "total": ec == "0",
32  "path": f"{slug}.html",
33  }
34  )
35 
36 if args.html:
37  with open(args.html, mode="w", encoding="utf-8") as f:
38  f.write(
39  """<!DOCTYPE html>
40 <html>
41 <head>
42  <title>physmon summary</title>
43  <meta charset="UTF-8">
44 </head>
45 <body>
46  <h1>physmon summary</h1>
47  <ul>
48  """
49  )
50 
51  for s in summary:
52  f.write(
53  f"""
54  <li>{"✅" if s["total"] else "🔴"} <a href="{s["path"]}">{s["title"]}</a></li>"""
55  )
56 
57  f.write(
58  """
59  </ul>
60  </body>
61  </html>
62  """
63  )
64 
65 if args.md:
66  with open(args.md, mode="w", encoding="utf-8") as f:
67  f.write("# physmon summary\n")
68  for s in summary:
69  if IS_CI:
70  url = HERALD_URL.format(
71  repo=os.environ["GITHUB_REPOSITORY"],
72  run_id=os.environ["GITHUB_RUN_ID"],
73  artifact_name="physmon",
74  path=s["path"],
75  )
76  else:
77  url = s["path"]
78  f.write(f" - {'✅' if s['total'] else '🔴'} [{s['title']}]({url})\n")