Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that output file exists before opening #33

Merged
merged 4 commits into from Feb 16, 2023
Merged

Conversation

tnytown
Copy link
Member

@tnytown tnytown commented Feb 15, 2023

Resolves #32.

The action crashes when pip-audit exits without writing anything to /tmp/pip-audit-output.txt. We now check that the file exists before opening it, which should allow the action to run to completion and write the pip-audit stderr to the summary. This is a quick band-aid to fix the immediate crash, maybe in the future we will want special diagnostics in the summary for when there is no pip-audit output?

action.py Outdated
Comment on lines 138 to 148
with open("/tmp/pip-audit-output.txt", "r") as io:
output = io.read()
p = Path("/tmp/pip-audit-output.txt")
if p.exists():
with p.open() 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)
# 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(output)
_summary(output)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than check-and-skip, let's try-and-fail:

try:
    # open
except OSError as exc:
   # log an explicit error here, before the full stdout log

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit!

Also, let's add a self-test for this: a CI step that passes invalid flags to pip-audit or something else that will always cause it to fail should be sufficient.

Signed-off-by: Andrew Pan <a@tny.town>
Signed-off-by: Andrew Pan <a@tny.town>
@tnytown
Copy link
Member Author

tnytown commented Feb 16, 2023

Let me know if this is what you had in mind!

I'm not sure of the wording of pip-audit did not return any output, or if that should be printed in the summary. There should still be (raw) output in the log just below. I just needed something to grep for in the selftest.

@tnytown
Copy link
Member Author

tnytown commented Feb 16, 2023

This is how a new summary looks: https://github.com/tnytown/gh-action-pip-audit/actions/runs/4196817469/attempts/1#summary-11396846157

Also, do we want to restrict the internal interface to pass a fixed invalid flag, like internal-be-careful-pass-invalid-flag? I'll doc internal-be-careful-extra-flags now.

@woodruffw
Copy link
Member

I'm not sure of the wording of pip-audit did not return any output, or if that should be printed in the summary. There should still be (raw) output in the log just below. I just needed something to grep for in the selftest.

This works for me! The only real constraint is that it needs to be valid Markdown, so this is fine.

Also, do we want to restrict the internal interface to pass a fixed invalid flag, like internal-be-careful-pass-invalid-flag? I'll doc internal-be-careful-extra-flags now.

I'm good with this approach: it's explicitly an internal option, and it's not a change in the action's security posture.

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@woodruffw woodruffw merged commit 666b1b8 into pypa:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when pip-audit fails without creating /tmp/pip-audit-output.txt
2 participants