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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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}")
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -300,6 +300,20 @@ Example
internal-be-careful-debug: true
```

#### `internal-be-careful-extra-flags`
**Default**: `""`

The `internal-be-careful-extra-flags` setting passes the specified flags
to `pip-audit`.

Example:

```yaml
- uses: pypa/gh-action-pip-audit@v1.0.5
with:
internal-be-careful-extra-flags: --not-a-real-pip-audit-flag
```

</details>

## Troubleshooting
Expand Down
22 changes: 13 additions & 9 deletions action.py
Expand Up @@ -18,7 +18,7 @@
_GITHUB_STEP_SUMMARY = Path(os.getenv("GITHUB_STEP_SUMMARY")).open("a")
_GITHUB_OUTPUT = Path(os.getenv("GITHUB_OUTPUT")).open("a")
_RENDER_SUMMARY = os.getenv("GHA_PIP_AUDIT_SUMMARY", "true") == "true"
_DEBUG = os.getenv("GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_DEBUG", "false") != "false"
_DEBUG = str(os.getenv("GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_DEBUG", "false")) != "false"


def _template(name):
Expand Down Expand Up @@ -64,7 +64,7 @@ def _fatal_help(msg):
"--desc",
# Write the output to this logfile, which we'll turn into the step summary (if configured).
"--output=/tmp/pip-audit-output.txt",
]
] + os.getenv("GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_EXTRA_FLAGS").split()

if _DEBUG:
pip_audit_args.append("--verbose")
Expand Down Expand Up @@ -135,15 +135,19 @@ def _fatal_help(msg):
else:
_summary("❌ pip-audit found one or more problems")

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

# 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)


_log(status.stdout)
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -50,6 +50,10 @@ inputs:
description: "run with debug logs (default false)"
required: false
default: false
internal-be-careful-extra-flags:
description: "extra flags to be passed in to pip-audit"
required: false
default: ""
outputs:
internal-be-careful-output:
description: "the column-formatted output from pip-audit, wrapped as base64"
Expand Down Expand Up @@ -84,4 +88,5 @@ runs:
GHA_PIP_AUDIT_IGNORE_VULNS: "${{ inputs.ignore-vulns }}"
GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_ALLOW_FAILURE: "${{ inputs.internal-be-careful-allow-failure }}"
GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_DEBUG: "${{ inputs.internal-be-careful-debug }}"
GHA_PIP_AUDIT_INTERNAL_BE_CAREFUL_EXTRA_FLAGS: "${{ inputs.internal-be-careful-extra-flags }}"
shell: bash
Empty file added test/empty.txt
Empty file.