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

feat: add ability to fail on ERR and other fail-on statuses for breaking changes #43

Conversation

jgill-shipwell
Copy link

Adds the ability to fail the action/build on other statuses such as ERR instead of just WARN.

@jgill-shipwell jgill-shipwell force-pushed the feat/add-fail-on-error-other-cases branch from e18f685 to 6ddd3f7 Compare February 29, 2024 14:59
Comment on lines 17 to 20
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on WARN"
elif [ "$fail_on_diff" != "false" ]
flags="${flags} --fail-on $fail_on_diff"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a best practice.

Copy link
Author

@jgill-shipwell jgill-shipwell Mar 1, 2024

Choose a reason for hiding this comment

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

@effoeffi Is there a way to indicate in the oasdiff breaking change action to only fail on ERR instead of WARN?

This was one way to support/passthrough any status or error level without hardcoding the options in the action:

if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on WARN"
elif [ "$fail_on_diff" != "false" ]
flags="${flags} --fail-on $fail_on_diff"

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand, but it is not best practice to use 'var' as both a boolean and a string. I suggest converting it to a string similar to oasdiff. Additionally, update the documentation, defaults, and create tests accordingly. Please also review other parameters for similar improvements.

Copy link
Author

@jgill-shipwell jgill-shipwell Mar 1, 2024

Choose a reason for hiding this comment

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

@effoeffi Updated the action, README, etc. in oasdiff-action in d96dd2c.

Copy link
Author

Choose a reason for hiding this comment

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

@effoeffi Added a test in 468ff61.

@jgill-shipwell jgill-shipwell force-pushed the feat/add-fail-on-error-other-cases branch 2 times, most recently from cf87137 to e19710d Compare March 1, 2024 20:31
@jgill-shipwell jgill-shipwell force-pushed the feat/add-fail-on-error-other-cases branch from 98ab600 to 468ff61 Compare March 1, 2024 20:38
@jgill-shipwell jgill-shipwell requested a review from effoeffi March 1, 2024 20:43
@tcooper-uk
Copy link
Contributor

Taken from the oasdiff help:

-o, --fail-on string                 exit with return code 1 when output includes errors with this level or higher: ERR or WARN

This means that the behaviour you have described already exists, failing on WARN will also fail on ERR.

Validated this is true with:

oasdiff breaking https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test4.yaml --fail-on WARN || echo $?

@jgill-shipwell
Copy link
Author

jgill-shipwell commented Mar 6, 2024

@tcooper-uk Re: #43 (comment) We want to fail on ERR, but not fail on WARN as the warnings are allowed and should not break the build in our use case so the fail-on-diff that sets the command as fail-on WARN to break the build/fail the action did not work for this use case.

Comment on lines 102 to 113
fail-on: ERR
- name: Test breaking changes action output
run: |
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
output=$(cat <<-$delimiter
${{ steps.test_breaking_changes.outputs.breaking }}
$delimiter
)
if [ "$output" != "1 breaking changes: 1 error, 0 warning" ]; then
echo "Expected output '6 breaking changes: 2 error, 4 warning' but got '$output'" >&2
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

What you are testing?
I suggest taking an example that there is warnings but not errors and set fail-on: ERR and it should not fail

README.md Outdated
| --include-checks | include-checks | csv |
| --include-path-params | include-path-params | false |
| --deprecation-days-beta | deprecation-days-beta | 31 |
| --deprecation-days-stable | deprecation-days-stable | 180 |
| --exclude-elements | exclude-elements | '' |

This action delivers a summary of breaking changes, accessible as a GitHub step output named `breaking`.
This action delivers a summary of breaking changes, accessible as a GitHub step output named `breaking`. Note: `fail-on-diff` takes precedence over `fail-on` when `fail-on-diff` is `true`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets align with oasdiff by having only fail-on. please remove fail-on-diff, we can achieve this by using fail-on: WARN

Comment on lines 18 to 19
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on WARN"
Copy link
Contributor

Choose a reason for hiding this comment

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

should be removed

Copy link
Author

Choose a reason for hiding this comment

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

@effoeffi For #43 (comment), the reason it was not removed was that it would be a breaking change itself if it was removed from the action. If someone relies on the fail_on_diff and it is removed, their workflows will break... of course fail-on is more flexible for any status. Will update the pr to remove fail_on_diff though.

Copy link
Contributor

Choose a reason for hiding this comment

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

@effoeffi For #43 (comment), the reason it was not removed was that it would be a breaking change itself if it was removed from the action. If someone relies on the fail_on_diff and it is removed, their workflows will break... of course fail-on is more flexible for any status. Will update the pr to remove fail_on_diff though.

@jgill-shipwell that is why we are creating a release, and you should rely on it to avoid any breaking changes.

Copy link
Author

Choose a reason for hiding this comment

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

@effoeffi Updated this pr to remove fail_on_diff and match the fail-on param of oasdiff. Updated the tests, etc.

@jgill-shipwell jgill-shipwell force-pushed the feat/add-fail-on-error-other-cases branch from 7e5e023 to 436f539 Compare March 8, 2024 16:10
@jgill-shipwell jgill-shipwell requested a review from effoeffi March 8, 2024 16:13
Comment on lines +38 to 40
if [ -z "$fail_on" ]; then
flags="${flags} --fail-on $fail_on"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to check if it is not empty, right? -n?

Comment on lines 85 to 89
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
fail-on-diff: false
fail-on: 'WARN'
output-to-file: 'breaking.txt'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this test do not fail?
oasdiff docs:

To exit with return code 1 when any breaking changes are found, WARN-level or ERR-level, add the --fail-on WARN flag.

Can you please explain the why you decided to change fail-on-diff: false to fail-on: 'WARN'?

Comment on lines +43 to +44
|---------------------------|-------------------------|---------|
| --fail-on | fail-on | 'ERR' |
Copy link
Contributor

Choose a reason for hiding this comment

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

The default oasdiff exit code is 0 if there is a breaking changes, why do you want to change that?

@@ -31,12 +31,12 @@ readonly exclude_elements="$8"
readonly composed="$9"
readonly output_to_file="${10}"

echo "running oasdiff breaking... base: $base, revision: $revision, fail_on_diff: $fail_on_diff, include_checks: $include_checks, include_path_params: $include_path_params, deprecation_days_beta: $deprecation_days_beta, deprecation_days_stable: $deprecation_days_stable, exclude_elements: $exclude_elements, composed: $composed, output_to_file: $output_to_file"
echo "running oasdiff breaking... base: $base, revision: $revision, fail_on: $fail_on, include_checks: $include_checks, include_path_params: $include_path_params, deprecation_days_beta: $deprecation_days_beta, deprecation_days_stable: $deprecation_days_stable, exclude_elements: $exclude_elements"
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you delete composed: $composed, output_to_file: $output_to_file"?

Copy link
Contributor

@effoeffi effoeffi May 7, 2024

Choose a reason for hiding this comment

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

@jgill-shipwell could you please check this PR and let me know if it resolves your issue?

@effoeffi effoeffi closed this May 10, 2024
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.

3 participants