Skip to content

Commit

Permalink
Support exclude-elements option (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuyaHayashi committed Jan 15, 2024
1 parent 6b8986e commit 349892f
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ jobs:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
format: 'text'
oasdiff_diff_exclude_elements:
runs-on: ubuntu-latest
name: Test diff action with exclude-elements option
steps:
- name: checkout
uses: actions/checkout@v3
- name: Running diff action with exclude-elements option
id: test_exclude_elements
uses: ./diff
with:
base: 'specs/base.yaml'
revision: 'specs/base-exclude-elements.yaml'
format: 'text'
exclude-elements: 'description,title,summary'
- name: Test diff action output
run: |
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
output=$(cat <<-$delimiter
${{ steps.test_exclude_elements.outputs.diff }}
$delimiter
)
if [ "$output" != "No changes" ]; then
echo "Expected output 'No changes' but got '$output'" >&2
exit 1
fi
oasdiff_breaking:
runs-on: ubuntu-latest
name: Test breaking changes
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This action supports additional arguments that are converted to parameters for t
| --fail-on-diff | fail-on-diff | false |
| --format | format | yaml |
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |

### Check for breaking API changes, and fail if any are found
Copy and paste the following snippet into your build .yml file:
Expand All @@ -43,6 +44,7 @@ Additional arguments:
| --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`.

Expand All @@ -60,4 +62,5 @@ Additional arguments:

| CLI | Action input | Default |
|--------|--------|--------|
| --include-path-params | include-path-params | false |
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |
5 changes: 5 additions & 0 deletions breaking/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
deprecation-days-stable:
description: 'Consider minimum sunset period for deprecation of stable API endpoints'
required: false
exclude-elements:
description: 'Exclude certain kinds of changes'
required: false
default: ''
outputs:
breaking:
description: 'Output summary of API breaking changes, encompassing both warnings and errors'
Expand All @@ -38,3 +42,4 @@ runs:
- ${{ inputs.include-path-params }}
- ${{ inputs.deprecation-days-beta }}
- ${{ inputs.deprecation-days-stable }}
- ${{ inputs.exclude-elements }}
6 changes: 5 additions & 1 deletion breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ readonly include_checks="$4"
readonly include_path_params="$5"
readonly deprecation_days_beta="$6"
readonly deprecation_days_stable="$7"
readonly exclude_elements="$8"

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"
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"

# Build flags to pass in command
flags=""
Expand All @@ -28,6 +29,9 @@ fi
if [ -n "$deprecation_days_stable" ]; then
flags="${flags} --deprecation-days-stable $deprecation_days_stable"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
fi
echo "flags: $flags"

# *** github action step output ***
Expand Down
5 changes: 5 additions & 0 deletions changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ inputs:
description: 'Include path parameter names in endpoint matching'
required: false
default: 'false'
exclude-elements:
description: 'Exclude certain kinds of changes'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.base }}
- ${{ inputs.revision }}
- ${{ inputs.include-path-params }}
- ${{ inputs.exclude-elements }}
6 changes: 5 additions & 1 deletion changelog/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ set -e
readonly base="$1"
readonly revision="$2"
readonly include_path_params="$3"
readonly exclude_elements="$4"

echo "running oasdiff changelog base: $base, revision: $revision, include_path_params: $include_path_params"
echo "running oasdiff changelog base: $base, revision: $revision, include_path_params: $include_path_params, exclude_elements: $exclude_elements"

# Build flags to pass in command
flags=""
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
fi
echo "flags: $flags"

set -o pipefail
Expand Down
8 changes: 8 additions & 0 deletions diff/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ inputs:
description: 'Include path parameter names in endpoint matching'
required: false
default: 'false'
exclude-elements:
description: 'Exclude certain kinds of changes'
required: false
default: ''
outputs:
diff:
description: 'Output summary of API diff'
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -28,3 +35,4 @@ runs:
- ${{ inputs.format }}
- ${{ inputs.fail-on-diff }}
- ${{ inputs.include-path-params }}
- ${{ inputs.exclude-elements }}
35 changes: 32 additions & 3 deletions diff/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ readonly revision="$2"
readonly format="$3"
readonly fail_on_diff="$4"
readonly include_path_params="$5"
readonly exclude_elements="$6"

echo "running oasdiff diff base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff, include_path_params: $include_path_params"
echo "running oasdiff diff base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff, include_path_params: $include_path_params, exclude_elements: $exclude_elements"

# Build flags to pass in command
flags=""
Expand All @@ -20,12 +21,40 @@ fi
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
fi
echo "flags: $flags"

# *** github action step output ***

# output name should be in the syntax of multiple lines:
# {name}<<{delimiter}
# {value}
# {delimiter}
# see: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
echo "diff<<$delimiter" >>$GITHUB_OUTPUT

set -o pipefail

if [ -n "$flags" ]; then
oasdiff diff "$base" "$revision" $flags
output=$(oasdiff diff "$base" "$revision" $flags | head -n 1)
else
oasdiff diff "$base" "$revision"
output=$(oasdiff diff "$base" "$revision" | head -n 1)
fi

if [ -n "$output" ]; then
# github-action limits output to 1MB
# we count bytes because unicode has multibyte characters
size=$(echo "$output" | wc -c)
if [ "$size" -ge "1000000" ]; then
echo "WARN: breaking exceeds the 1MB limit, truncating output..." >&2
output=$(echo "$output" | head -c $1000000)
fi
echo "$output" >>$GITHUB_OUTPUT
else
echo "No changes" >>$GITHUB_OUTPUT
fi

echo "$delimiter" >>$GITHUB_OUTPUT
111 changes: 111 additions & 0 deletions specs/base-exclude-elements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore API
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets data
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 1000)
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
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

0 comments on commit 349892f

Please sign in to comment.