diff --git a/action.py b/action.py index aac0643..8db1c11 100755 --- a/action.py +++ b/action.py @@ -6,18 +6,23 @@ # is a whitespace-separated list of inputs import os +import string import subprocess import sys from base64 import b64encode from pathlib import Path -_OUTPUTS = [sys.stderr] +_HERE = Path(__file__).parent.resolve() +_TEMPLATES = _HERE / "templates" + _SUMMARY = Path(os.getenv("GITHUB_STEP_SUMMARY")).open("a") _RENDER_SUMMARY = os.getenv("GHA_PIP_AUDIT_SUMMARY", "true") == "true" _DEBUG = os.getenv("GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_DEBUG", "false") != "false" -if _RENDER_SUMMARY: - _OUTPUTS.append(_SUMMARY) + +def _template(name): + path = _TEMPLATES / f"{name}.md" + return string.Template(path.read_text()) def _summary(msg): @@ -31,8 +36,7 @@ def _debug(msg): def _log(msg): - for output in _OUTPUTS: - print(msg, file=output) + print(msg, file=sys.stderr) def _pip_audit(*args): @@ -127,9 +131,9 @@ def _fatal_help(msg): _debug(status.stdout) if status.returncode == 0: - _log("🎉 pip-audit exited successfully") + _summary("🎉 pip-audit exited successfully") else: - _log("❌ pip-audit found one or more problems") + _summary("❌ pip-audit found one or more problems") with open("/tmp/pip-audit-output.txt", "r") as io: output = io.read() @@ -140,25 +144,11 @@ def _fatal_help(msg): print(f"::set-output name=output::{b64encode(output.encode()).decode()}") _log(output) + _summary(output) -_summary( - """ -
- - Raw `pip-audit` output - - -``` - """ -) _log(status.stdout) -_summary( - """ -``` -
- """ -) +_summary(_template("pip-audit").substitute(output=status.stdout)) # Normally, we exit with the same code as `pip-audit`, but the user can # explicitly configure the CI to always pass. diff --git a/templates/pip-audit.md b/templates/pip-audit.md new file mode 100644 index 0000000..a46d96e --- /dev/null +++ b/templates/pip-audit.md @@ -0,0 +1,11 @@ +
+ + + Raw pip-audit output + + +``` +$output +``` + +