Skip to content

Commit

Permalink
action, templates: switch to a template
Browse files Browse the repository at this point in the history
Closes #23.

Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw committed Aug 2, 2022
1 parent cce8844 commit 6ee583e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
30 changes: 12 additions & 18 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# is a whitespace-separated list of inputs

import os
import string
import subprocess
import sys
from base64 import b64encode
from pathlib import Path

_HERE = Path(__file__).parent.resolve()
_TEMPLATES = _HERE / "templates"

_OUTPUTS = [sys.stderr]
_SUMMARY = Path(os.getenv("GITHUB_STEP_SUMMARY")).open("a")
_RENDER_SUMMARY = os.getenv("GHA_PIP_AUDIT_SUMMARY", "true") == "true"
Expand All @@ -20,6 +24,11 @@
_OUTPUTS.append(_SUMMARY)


def _template(name):
path = _TEMPLATES / f"{name}.md"
return string.Template(path.read_text())


def _summary(msg):
if _RENDER_SUMMARY:
print(msg, file=_SUMMARY)
Expand Down Expand Up @@ -127,9 +136,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()
Expand All @@ -142,23 +151,8 @@ def _fatal_help(msg):
_log(output)


_summary(
"""
<details>
<summary>
Raw `pip-audit` output
</summary>
```
"""
)
_log(status.stdout)
_summary(
"""
```
</details>
"""
)
_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.
Expand Down
11 changes: 11 additions & 0 deletions templates/pip-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<details>

<summary>
Raw <code>pip-audit</code> output
</summary>

```
$output
```

</details>

0 comments on commit 6ee583e

Please sign in to comment.