-
Notifications
You must be signed in to change notification settings - Fork 245
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
fix: Set env var if it differs from actual value #437
base: master
Are you sure you want to change the base?
fix: Set env var if it differs from actual value #437
Conversation
I am also seeing this - it would be great if the fix could be merged and released ASAP. |
@DmitriyLewen could you take a look? |
if [ ! -z "$input_value" ] && [ "$input_value" != "$default_value" ]; then | ||
local value="${!var_name}" | ||
|
||
if [ ! -z "$input_value" ] && [ "$input_value" != "$default_value" ] || [ "$value" != "$default_value" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps in your case, but breaks logic for config file (if default value != "").
Let's look at an example - if we don't set format
in inputs
- we should use format from config file (json
in this example):
- master branch -
json
format - https://github.com/DmitriyLewen/test-trivy-action/actions/runs/12134369796/job/33831459219#step:3:130 - your changes -
table
format - https://github.com/DmitriyLewen/test-trivy-action/actions/runs/12134373819/job/33831470667#step:3:146
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we will unset
all TRIVY_*
envs after run Trivy?
Hello @david-marconis I suggest saving and loading envs to a file (to use them locally in trivy-action). Let me know if you have time to test this and update my pr. Best regards, Dmitriy |
Problem
There is an issue with the current action if you run multiple Trivy actions in a row. It will not respect the inputs as it will not set the env var if the env var if the input value is a different value. However, if the env var already has a different value than the default and you try to set it to a default value, it will not work.
Scenario
Here is a scenario: You first run Trivy scan with sarif format, and then you run with table format:
Then then the second scan will not use format table, as it uses the previously set env var: TRIVY_FORMAT: sarif.
Tests
Here is a workflow run that shows the issue:
input format: table
https://github.com/david-marconis/trivy-ignore-bug/actions/runs/12065562387/job/33644593462#step:3:6
env TRIVY_FORMAT: sarif
https://github.com/david-marconis/trivy-ignore-bug/actions/runs/12065562387/job/33644593462#step:3:20
log indicating sarif mode:
https://github.com/david-marconis/trivy-ignore-bug/actions/runs/12065562387/job/33644593462#step:3:159
Fix
The fix is to check if the actual value differs from the wanted value. You could also remove the check if it is the same as the default, IDK if this has any other implications.
Here is a workflow run with the fix implemented:
https://github.com/david-marconis/trivy-ignore-bug/actions/runs/12065669260/job/33644932663#step:3:217
Fixes
Fixes this issue #438
Might also fix this #435 and #422