Skip to content

Commit

Permalink
[breaking] Align 'fail-on-diff' with oasdiff 'fail-on' (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
effoeffi authored May 9, 2024
1 parent 8239cae commit a2ff668
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 11 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,42 @@ jobs:
echo "Expected output '1 breaking changes: 1 error, 0 warning' but got '${output}'" >&2
exit 1
fi
oasdiff_breaking_fail_on:
runs-on: ubuntu-latest
name: Test fail on breaking changes
steps:
- name: checkout
uses: actions/checkout@v4
- name: Running breaking action
id: test_breaking_changes
uses: ./breaking
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking-warn.yaml'
output-to-file: 'breaking.txt'
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" != "2 breaking changes: 0 error, 2 warning" ]; then
echo "Expected output '2 breaking changes: 0 error, 2 warning' but got '$output'" >&2
exit 1
fi
- name: Test breaking changes action output to file
run: |
if [ ! -s breaking.txt ]; then
echo "Breaking changes file doesn't exist or is empty"
exit 1
fi
output=$(cat breaking.txt | head -n 1)
if [[ "${output}" != "2 breaking changes: 0 error, 2 warning" ]]; then
echo "Expected output '2 breaking changes: 0 error, 2 warning' but got '${output}'" >&2
exit 1
fi
oasdiff_breaking_matching_delimiter_not_found:
runs-on: ubuntu-latest
name: Test breaking action with petsotre to validate no error of unable to process file command 'output' successfully and invalid value and matching delimiter not found
Expand Down Expand Up @@ -236,4 +272,5 @@ jobs:
if [[ ! "$output" =~ "1 changes: 1 error, 0 warning, 0 info" ]]; then
echo "Expected '1 changes: 1 error, 0 warning, 0 info', instead got '$output'" >&2
exit 1
fi
fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Additional arguments:

| CLI | Action input | Default |
| ------------------------- | ----------------------- | ------- |
| --fail-on WARN | fail-on-diff | true |
| --fail-on | fail-on | empty |
| --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 any breaking changes are found at severity level, such as ERR or WARN'
required: false
default: 'true'
default: ''
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
13 changes: 8 additions & 5 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

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 Down Expand Up @@ -32,13 +32,10 @@ write_output () {
echo "$_write_output_output" >>"$GITHUB_OUTPUT"
}

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, composed: $composed, output_to_file: $output_to_file"

# Build flags to pass in command
flags=""
if [ "$fail_on_diff" = "true" ]; then
flags="$flags --fail-on WARN"
fi
if [ "$include_path_params" = "true" ]; then
flags="$flags --include-path-params"
fi
Expand Down Expand Up @@ -88,3 +85,9 @@ else
fi

echo "$delimiter" >>"$GITHUB_OUTPUT"

# First output the changes (above) and then run oasdiff to check --fail-on
if [ -n "$fail_on" ]; then
flags="$flags --fail-on $fail_on"
oasdiff breaking "$base" "$revision" $flags > /dev/null
fi
121 changes: 121 additions & 0 deletions specs/revision-breaking-warn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
openapi: "3.0.0"

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

View workflow job for this annotation

GitHub Actions / Test fail on breaking changes

response-optional-property-removed

in API GET /pets removed the optional property '/items/tag' from the response with the '200' status

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

View workflow job for this annotation

GitHub Actions / Test fail on breaking changes

response-optional-property-removed

in API GET /pets/{petId} removed the optional property 'tag' from the response with the '200' status
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/healthcheck:
get:
summary: Health Check
description: >-
The healthcheck endpoint provides detailed information about the health
of a web service. If each of the components required by the service are
healthy, then the service is considered healthy and will return a 200 OK
response. If any of the components needed by the service are unhealthy,
then a 503 Service Unavailable response will be provided.
responses:
'200':
description: Health Check report
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
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
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string

0 comments on commit a2ff668

Please sign in to comment.