Skip to content

Commit

Permalink
[Issue 46] Unable to process file command 'output' successfully; Fix:…
Browse files Browse the repository at this point in the history
… In POSIX sh, local is undefined (#47)
  • Loading branch information
effoeffi authored Mar 11, 2024
1 parent 205ce7e commit 8239cae
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 37 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion breaking/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ runs:
- ${{ inputs.deprecation-days-stable }}
- ${{ inputs.exclude-elements }}
- ${{ inputs.composed }}
- ${{ inputs.output-to-file }}
- ${{ inputs.output-to-file }}
72 changes: 36 additions & 36 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -58,33 +59,32 @@ 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}
# 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 "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
119 changes: 119 additions & 0 deletions specs/petstore-base.yaml
Original file line number Diff line number Diff line change
@@ -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
118 changes: 118 additions & 0 deletions specs/petstore-revision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
openapi: "3.0.0"

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

response-property-became-optional

in API GET /pets the response property '/items/name' became optional for the status '200'

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

response-property-became-optional

in API GET /pets the response property 'message' became optional for the status 'default'

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

new-required-request-property

in API POST /pets added the new required request property 'tag2'

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

response-property-became-optional

in API POST /pets the response property 'message' became optional for the status 'default'

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

response-property-became-optional

in API GET /pets/{petId} the response property 'message' became optional for the status 'default'

Check failure on line 1 in specs/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

response-property-became-optional

in API GET /pets/{petId} the response property 'name' became optional for the status '200'

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

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

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/petstore-revision.yaml

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

request-property-removed

in API POST /pets removed the request property 'tag'

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

View workflow job for this annotation

GitHub Actions / Test breaking action with petsotre to validate no error of unable to process file command 'output...

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:
/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

0 comments on commit 8239cae

Please sign in to comment.