Skip to content

Commit

Permalink
ci: Create job summaries in python (#2339)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger authored Aug 3, 2023
1 parent 271cbf8 commit b5babcb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ jobs:
- name: Python level tests
shell: bash
env:
PYTEST_MD_REPORT: true
PYTEST_MD_REPORT_VERBOSE: 0
PYTEST_MD_REPORT_OUTPUT: pytest.md
run: >
/usr/local/bin/geant4-config --install-datasets
&& source /usr/local/bin/thisroot.sh
Expand All @@ -266,7 +270,9 @@ jobs:
&& export PYTHONPATH=/usr/local/python:$PYTHONPATH
&& export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH
&& pip3 install -r Examples/Python/tests/requirements.txt
&& pip3 install pytest-md-report
&& pytest -rFsv -k "not exatrkx" -v
&& cat ${PYTEST_MD_REPORT_OUTPUT} >> $GITHUB_STEP_SUMMARY
linux_physmon:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -314,6 +320,7 @@ jobs:
&& echo "::endgroup::"
&& export PYTHONPATH="${PYTHONPATH}":"${GITHUB_WORKSPACE}/Examples/Scripts/Python"
&& CI/physmon/phys_perf_mon.sh all physmon
&& cat physmon/summary.md >> $GITHUB_STEP_SUMMARY
- uses: actions/upload-artifact@v3
if: always()
Expand Down
5 changes: 4 additions & 1 deletion CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ if [[ "$mode" == "all" || "$mode" == "simulation" ]]; then
simulation geant4
fi

CI/physmon/summary.py $outdir/*.html $outdir/summary.html
CI/physmon/summary.py $outdir/*.html \
--base $outdir \
--md $outdir/summary.md \
--html $outdir/summary.html
ec=$(($ec | $?))

exit $ec
60 changes: 42 additions & 18 deletions CI/physmon/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import functools
import os

HERALD_URL = "https://herald.dokku.paulgessinger.com/view/{repo}/runs/{run_id}/artifacts/{artifact_name}/{path}"
IS_CI = "GITHUB_ACTIONS" in os.environ


parser = argparse.ArgumentParser()
parser.add_argument("html", nargs="+")
parser.add_argument("output")
parser.add_argument("inputs", nargs="+")
parser.add_argument("--base", required=True)
parser.add_argument("--html")
parser.add_argument("--md")
args = parser.parse_args()

re_title = re.compile(r'<p class="title">\s*(.*)\s*<\/p>', re.RegexFlag.MULTILINE)
re_check = re.compile(r'<a.*title="(.*)">\s*(.)\s*<\/a>', re.RegexFlag.MULTILINE)

summary = {}

for h in args.html:
for h in args.inputs:
with open(h, mode="r", encoding="utf-8") as f:
try:
content = f.read()
Expand All @@ -34,29 +39,48 @@
except Exception as e:
print(r"could not parse {h}", e)

with open(args.output, mode="w", encoding="utf-8") as f:
f.write(
"""<!DOCTYPE html>
if args.html:
with open(args.html, mode="w", encoding="utf-8") as f:
f.write(
"""<!DOCTYPE html>
<html>
<head>
<title>physmon summary</title>
<meta charset="UTF-8">
</head>
<body>
<h1>physmon summary</h1>
<ul>"""
)
<ul>
"""
)

for h, s in summary.items():
path = os.path.relpath(h, args.base)
f.write(
f"""
<li>{"✅" if s["total"] else "🔴"} <a href="{path}">{s["title"]}</a></li>"""
)

for h, s in summary.items():
path = os.path.relpath(h, os.path.dirname(args.output))
f.write(
f"""
<li>{"✅" if s["total"] else "🔴"} <a href="{path}">{s["title"]}</a></li>"""
"""
</ul>
</body>
</html>
"""
)

f.write(
"""
</ul>
</body>
</html>"""
)
if args.md:
with open(args.md, mode="w", encoding="utf-8") as f:
f.write("# physmon summary\n")
for h, s in summary.items():
path = os.path.relpath(h, args.base)
if IS_CI:
url = HERALD_URL.format(
repo=os.environ["GITHUB_REPOSITORY"],
run_id=os.environ["GITHUB_RUN_ID"],
artifact_name="physmon",
path=path,
)
else:
url = path
f.write(f" - {'✅' if s['total'] else '🔴'} [{s['title']}]({url})\n")

0 comments on commit b5babcb

Please sign in to comment.