diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6ffb4a5..0c21ebc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -109,6 +109,30 @@ jobs: echo "Expected output '1 breaking changes: 1 error, 0 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 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Running breaking action with petsotre to validate no error of unable to process file command 'output' successfully and invalid value and matching delimiter not found + id: test_breaking_changes_matching_delimiter_not_found + uses: ./breaking + with: + base: 'specs/petstore-base.yaml' + revision: 'specs/petstore-revision.yaml' + fail-on-diff: false + - name: Test breaking changes action output + run: | + delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-') + output=$(cat <<-$delimiter + ${{ steps.test_breaking_changes_matching_delimiter_not_found.outputs.breaking }} + $delimiter + ) + if [ "$output" != "9 breaking changes: 6 error, 3 warning" ]; then + echo "Expected output '9 breaking changes: 6 error, 3 warning' but got '$output'" >&2 + exit 1 + fi oasdiff_breaking_composed: runs-on: ubuntu-latest name: Test breaking action with composed option diff --git a/breaking/action.yml b/breaking/action.yml index 8238bd9..d0b8e29 100644 --- a/breaking/action.yml +++ b/breaking/action.yml @@ -52,4 +52,4 @@ runs: - ${{ inputs.deprecation-days-stable }} - ${{ inputs.exclude-elements }} - ${{ inputs.composed }} - - ${{ inputs.output-to-file }} + - ${{ inputs.output-to-file }} \ No newline at end of file diff --git a/breaking/entrypoint.sh b/breaking/entrypoint.sh index e5d885d..e52050c 100755 --- a/breaking/entrypoint.sh +++ b/breaking/entrypoint.sh @@ -1,25 +1,6 @@ #!/bin/sh set -e -write_output () { - local output="$1" - if [ -n "$output_to_file" ]; then - local file_output="$2" - if [ -z "$file_output" ]; then - file_output=$output - fi - echo "$file_output" >> "$output_to_file" - fi - # 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: diff exceeds the 1MB limit, truncating output..." >&2 - output=$(echo "$output" | head -c 1000000) - fi - echo "$output" >>"$GITHUB_OUTPUT" -} - readonly base="$1" readonly revision="$2" readonly fail_on_diff="$3" @@ -31,6 +12,26 @@ readonly exclude_elements="$8" readonly composed="$9" readonly output_to_file="${10}" +write_output () { + _write_output_output="$1" + if [ -n "$output_to_file" ]; then + _write_output_file_output="$2" + if [ -z "$_write_output_file_output" ]; then + _write_output_file_output=$_write_output_output + + fi + echo "$_write_output_file_output" >> "$output_to_file" + fi + # github-action limits output to 1MB + # we count bytes because unicode has multibyte characters + size=$(echo "$_write_output_output" | wc -c) + if [ "$size" -ge "1000000" ]; then + echo "WARN: diff exceeds the 1MB limit, truncating output..." >&2 + _write_output_output=$(echo "$_write_output_output" | head -c 1000000) + fi + 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" # Build flags to pass in command @@ -58,9 +59,21 @@ if [ "$composed" = "true" ]; then fi echo "flags: $flags" -# *** github action step output *** +# Check for breaking changes +if [ -n "$flags" ]; then + breaking_changes=$(oasdiff breaking "$base" "$revision" $flags) +else + breaking_changes=$(oasdiff breaking "$base" "$revision") +fi + +# Updating GitHub Action summary with formatted output +flags_with_githubactions="$flags --format githubactions" +# Writes the summary to log and updates GitHub Action summary +oasdiff breaking "$base" "$revision" $flags_with_githubactions -# output name should be in the syntax of multiple lines: +# *** GitHub Action step output *** + +# Output name should be in the syntax of multiple lines: # {name}<<{delimiter} # {value} # {delimiter} @@ -68,23 +81,10 @@ echo "flags: $flags" delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-') echo "breaking<<$delimiter" >>"$GITHUB_OUTPUT" -if [ -n "$flags" ]; then - output=$(oasdiff breaking "$base" "$revision" $flags) -else - output=$(oasdiff breaking "$base" "$revision") -fi - -if [ -n "$output" ]; then - write_output "$(echo "$output" | head -n 1)" "$output" +if [ -n "$breaking_changes" ]; then + write_output "$(echo "$breaking_changes" | head -n 1)" "$breaking_changes" else write_output "No breaking changes" fi echo "$delimiter" >>"$GITHUB_OUTPUT" - -# *** github action step output *** - -# Updating GitHub Action summary with formatted output -flags="$flags --format githubactions" -# Writes the summary to log and updates GitHub Action summary -oasdiff breaking "$base" "$revision" $flags diff --git a/specs/petstore-base.yaml b/specs/petstore-base.yaml new file mode 100644 index 0000000..7ed987f --- /dev/null +++ b/specs/petstore-base.yaml @@ -0,0 +1,119 @@ +openapi: "3.0.0" +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 + parameters: + - name: limit + in: query + description: How many items to return at one time (max 100) + required: false + schema: + type: integer + maximum: 100 + 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 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + required: true + 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 + maxItems: 100 + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/specs/petstore-revision.yaml b/specs/petstore-revision.yaml new file mode 100644 index 0000000..1409f20 --- /dev/null +++ b/specs/petstore-revision.yaml @@ -0,0 +1,118 @@ +openapi: "3.0.0" +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 + parameters: + - name: limit + in: query + description: How many items to return at one time (max 100) + required: false + schema: + type: integer + maximum: 100 + 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 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + required: true + 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 + - tag2 + properties: + id: + type: integer + format: int64 + name: + type: string + tag2: + type: string + Pets: + type: array + maxItems: 100 + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + properties: + code: + type: integer + format: int32 + message: + type: string