Skip to content

Commit

Permalink
workflows/selftest: regression test for no output
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Pan <a@tny.town>
  • Loading branch information
tnytown committed Feb 16, 2023
1 parent 1b8f253 commit 6a1ff7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/selftest.yml
Expand Up @@ -88,3 +88,21 @@ jobs:
PIP_AUDIT_OUTPUT: "${{ steps.pip-audit.outputs.internal-be-careful-output }}"
run: |
grep -E 'pyyaml\s+\|\s+5.1' <<< $(base64 -d <<< "${PIP_AUDIT_OUTPUT}")
selftest-pipaudit-fail:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
id: pip-audit
with:
# we do not care about pip-audit's actual output in this test, we just need a file to pass
# in so as to not exercise `pip list` mode.
inputs: ./test/empty.txt
# pass in a fake flag here to reliably trigger the failure we're looking for.
internal-be-careful-extra-flags: --not-a-real-pip-audit-flag
internal-be-careful-allow-failure: true
- name: assert expected output
env:
PIP_AUDIT_OUTPUT: "${{ steps.pip-audit.outputs.internal-be-careful-output }}"
run: |
grep 'pip-audit did not return any output' <<< $(base64 -d <<< "${PIP_AUDIT_OUTPUT}")
18 changes: 10 additions & 8 deletions action.py
Expand Up @@ -135,18 +135,20 @@ def _fatal_help(msg):
else:
_summary("❌ pip-audit found one or more problems")

output = "⚠️ pip-audit did not return any output"
try:
with open("/tmp/pip-audit-output.txt") as io:
with open("/tmp/pip-audit-output.txt", "r") as io:
output = io.read()

# This is really nasty: our output contains multiple lines,
# so we can't naively stuff it into an output.
print(f"output={b64encode(output.encode()).decode()}", file=_GITHUB_OUTPUT)

_log(output)
_summary(output)
except OSError as ex:
_log(ex)
_summary("❌ pip-audit did not return any output")

# This is really nasty: our output contains multiple lines,
# so we can't naively stuff it into an output.
print(f"output={b64encode(output.encode()).decode()}", file=_GITHUB_OUTPUT)

_log(output)
_summary(output)


_log(status.stdout)
Expand Down
Empty file added test/empty.txt
Empty file.

0 comments on commit 6a1ff7b

Please sign in to comment.