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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
fail-on-diff: false
fail-on: 'WARN'
output-to-file: 'breaking.txt'
Comment on lines 85 to 89
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'?

- name: Test breaking changes action output
run: |
Expand Down Expand Up @@ -153,9 +153,57 @@ jobs:
with:
base: specs/base.yaml
revision: specs/base-deprecation.yaml
fail-on-diff: true
fail-on: 'WARN'
deprecation-days-beta: 14
deprecation-days-stable: 21
oasdiff_breaking_fail_on_err:
runs-on: ubuntu-latest
name: Test breaking changes fail-on (ERR)
steps:
- name: checkout
uses: actions/checkout@v4
- name: Running breaking action
id: test_breaking_changes_err
uses: ./breaking
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
fail-on: 'ERR'
- name: Test breaking changes action output (ERR)
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 '1 breaking changes: 1 error, 0 warning' but got '$output'" >&2
exit 1
fi
oasdiff_breaking_fail_on_warn:
runs-on: ubuntu-latest
name: Test breaking changes fail-on (WARN)
steps:
- name: checkout
uses: actions/checkout@v4
- name: Running breaking action
id: test_breaking_changes_err
uses: ./breaking
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking-warning.yaml'
fail-on: 'ERR'
- name: Test breaking changes action output (WARN) - Expecting No Output
run: |
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
output=$(cat <<-$delimiter
${{ steps.test_breaking_changes.outputs.breaking }}
$delimiter
)
if [ -n "$output" ]; then
echo "Expected no breaking output as the fail-on level is set to ERR (error) and there should only be warnings' but got '$output'" >&2
exit 1
fi
oasdiff_changelog:
runs-on: ubuntu-latest
name: Test generation of changelog
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Copy and paste the following snippet into your build .yml file:
Additional arguments:

| CLI | Action input | Default |
| ------------------------- | ----------------------- | ------- |
| --fail-on WARN | fail-on-diff | true |
|---------------------------|-------------------------|---------|
| --fail-on | fail-on | 'ERR' |
Comment on lines +43 to +44
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?

| --include-checks | include-checks | csv |
| --include-path-params | include-path-params | false |
| --deprecation-days-beta | deprecation-days-beta | 31 |
Expand Down
8 changes: 4 additions & 4 deletions breaking/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ inputs:
revision:
description: 'Path of revised OpenAPI spec in YAML or JSON format'
required: true
fail-on-diff:
description: 'Fail with exit code 1 if any breaking changes are found'
fail-on:
description: 'Fail with exit code 1 if breaking changes are found at a particular status or severity level, e.g. ERR or WARN'
required: false
default: 'true'
default: 'ERR'
include-checks:
description: 'Include any of the defined optional breaking changes checks'
required: false
Expand Down Expand Up @@ -45,7 +45,7 @@ runs:
args:
- ${{ inputs.base }}
- ${{ inputs.revision }}
- ${{ inputs.fail-on-diff }}
- ${{ inputs.fail-on }}
- ${{ inputs.include-checks }}
- ${{ inputs.include-path-params }}
- ${{ inputs.deprecation-days-beta }}
Expand Down
8 changes: 4 additions & 4 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ write_output () {

readonly base="$1"
readonly revision="$2"
readonly fail_on_diff="$3"
readonly fail_on="$3"
readonly include_checks="$4"
readonly include_path_params="$5"
readonly deprecation_days_beta="$6"
Expand All @@ -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?


# Build flags to pass in command
flags=""
if [ "$fail_on_diff" = "true" ]; then
flags="$flags --fail-on WARN"
if [ -z "$fail_on" ]; then
flags="${flags} --fail-on $fail_on"
fi
Comment on lines +38 to 40
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?

if [ "$include_path_params" = "true" ]; then
flags="$flags --include-path-params"
Expand Down
103 changes: 103 additions & 0 deletions specs/revision-breaking-warning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
openapi: "3.0.0"

Check warning on line 1 in specs/revision-breaking-warning.yaml

View workflow job for this annotation

GitHub Actions / Test breaking changes fail-on (WARN)

request-parameter-removed

in API GET /pets deleted the 'query' request parameter 'limit'
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Loading