Skip to content

Commit 8239cae

Browse files
authored
[Issue 46] Unable to process file command 'output' successfully; Fix: In POSIX sh, local is undefined (#47)
1 parent 205ce7e commit 8239cae

File tree

5 files changed

+298
-37
lines changed

5 files changed

+298
-37
lines changed

.github/workflows/test.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ jobs:
109109
echo "Expected output '1 breaking changes: 1 error, 0 warning' but got '${output}'" >&2
110110
exit 1
111111
fi
112+
oasdiff_breaking_matching_delimiter_not_found:
113+
runs-on: ubuntu-latest
114+
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
115+
steps:
116+
- name: checkout
117+
uses: actions/checkout@v4
118+
- 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
119+
id: test_breaking_changes_matching_delimiter_not_found
120+
uses: ./breaking
121+
with:
122+
base: 'specs/petstore-base.yaml'
123+
revision: 'specs/petstore-revision.yaml'
124+
fail-on-diff: false
125+
- name: Test breaking changes action output
126+
run: |
127+
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
128+
output=$(cat <<-$delimiter
129+
${{ steps.test_breaking_changes_matching_delimiter_not_found.outputs.breaking }}
130+
$delimiter
131+
)
132+
if [ "$output" != "9 breaking changes: 6 error, 3 warning" ]; then
133+
echo "Expected output '9 breaking changes: 6 error, 3 warning' but got '$output'" >&2
134+
exit 1
135+
fi
112136
oasdiff_breaking_composed:
113137
runs-on: ubuntu-latest
114138
name: Test breaking action with composed option

breaking/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ runs:
5252
- ${{ inputs.deprecation-days-stable }}
5353
- ${{ inputs.exclude-elements }}
5454
- ${{ inputs.composed }}
55-
- ${{ inputs.output-to-file }}
55+
- ${{ inputs.output-to-file }}

breaking/entrypoint.sh

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
write_output () {
5-
local output="$1"
6-
if [ -n "$output_to_file" ]; then
7-
local file_output="$2"
8-
if [ -z "$file_output" ]; then
9-
file_output=$output
10-
fi
11-
echo "$file_output" >> "$output_to_file"
12-
fi
13-
# github-action limits output to 1MB
14-
# we count bytes because unicode has multibyte characters
15-
size=$(echo "$output" | wc -c)
16-
if [ "$size" -ge "1000000" ]; then
17-
echo "WARN: diff exceeds the 1MB limit, truncating output..." >&2
18-
output=$(echo "$output" | head -c 1000000)
19-
fi
20-
echo "$output" >>"$GITHUB_OUTPUT"
21-
}
22-
234
readonly base="$1"
245
readonly revision="$2"
256
readonly fail_on_diff="$3"
@@ -31,6 +12,26 @@ readonly exclude_elements="$8"
3112
readonly composed="$9"
3213
readonly output_to_file="${10}"
3314

15+
write_output () {
16+
_write_output_output="$1"
17+
if [ -n "$output_to_file" ]; then
18+
_write_output_file_output="$2"
19+
if [ -z "$_write_output_file_output" ]; then
20+
_write_output_file_output=$_write_output_output
21+
22+
fi
23+
echo "$_write_output_file_output" >> "$output_to_file"
24+
fi
25+
# github-action limits output to 1MB
26+
# we count bytes because unicode has multibyte characters
27+
size=$(echo "$_write_output_output" | wc -c)
28+
if [ "$size" -ge "1000000" ]; then
29+
echo "WARN: diff exceeds the 1MB limit, truncating output..." >&2
30+
_write_output_output=$(echo "$_write_output_output" | head -c 1000000)
31+
fi
32+
echo "$_write_output_output" >>"$GITHUB_OUTPUT"
33+
}
34+
3435
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"
3536

3637
# Build flags to pass in command
@@ -58,33 +59,32 @@ if [ "$composed" = "true" ]; then
5859
fi
5960
echo "flags: $flags"
6061

61-
# *** github action step output ***
62+
# Check for breaking changes
63+
if [ -n "$flags" ]; then
64+
breaking_changes=$(oasdiff breaking "$base" "$revision" $flags)
65+
else
66+
breaking_changes=$(oasdiff breaking "$base" "$revision")
67+
fi
68+
69+
# Updating GitHub Action summary with formatted output
70+
flags_with_githubactions="$flags --format githubactions"
71+
# Writes the summary to log and updates GitHub Action summary
72+
oasdiff breaking "$base" "$revision" $flags_with_githubactions
6273

63-
# output name should be in the syntax of multiple lines:
74+
# *** GitHub Action step output ***
75+
76+
# Output name should be in the syntax of multiple lines:
6477
# {name}<<{delimiter}
6578
# {value}
6679
# {delimiter}
6780
# see: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
6881
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
6982
echo "breaking<<$delimiter" >>"$GITHUB_OUTPUT"
7083

71-
if [ -n "$flags" ]; then
72-
output=$(oasdiff breaking "$base" "$revision" $flags)
73-
else
74-
output=$(oasdiff breaking "$base" "$revision")
75-
fi
76-
77-
if [ -n "$output" ]; then
78-
write_output "$(echo "$output" | head -n 1)" "$output"
84+
if [ -n "$breaking_changes" ]; then
85+
write_output "$(echo "$breaking_changes" | head -n 1)" "$breaking_changes"
7986
else
8087
write_output "No breaking changes"
8188
fi
8289

8390
echo "$delimiter" >>"$GITHUB_OUTPUT"
84-
85-
# *** github action step output ***
86-
87-
# Updating GitHub Action summary with formatted output
88-
flags="$flags --format githubactions"
89-
# Writes the summary to log and updates GitHub Action summary
90-
oasdiff breaking "$base" "$revision" $flags

specs/petstore-base.yaml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
maximum: 100
24+
format: int32
25+
responses:
26+
'200':
27+
description: A paged array of pets
28+
headers:
29+
x-next:
30+
description: A link to the next page of responses
31+
schema:
32+
type: string
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/Pets"
37+
default:
38+
description: unexpected error
39+
content:
40+
application/json:
41+
schema:
42+
$ref: "#/components/schemas/Error"
43+
post:
44+
summary: Create a pet
45+
operationId: createPets
46+
tags:
47+
- pets
48+
requestBody:
49+
content:
50+
application/json:
51+
schema:
52+
$ref: '#/components/schemas/Pet'
53+
required: true
54+
responses:
55+
'201':
56+
description: Null response
57+
default:
58+
description: unexpected error
59+
content:
60+
application/json:
61+
schema:
62+
$ref: "#/components/schemas/Error"
63+
/pets/{petId}:
64+
get:
65+
summary: Info for a specific pet
66+
operationId: showPetById
67+
tags:
68+
- pets
69+
parameters:
70+
- name: petId
71+
in: path
72+
required: true
73+
description: The id of the pet to retrieve
74+
schema:
75+
type: string
76+
responses:
77+
'200':
78+
description: Expected response to a valid request
79+
content:
80+
application/json:
81+
schema:
82+
$ref: "#/components/schemas/Pet"
83+
default:
84+
description: unexpected error
85+
content:
86+
application/json:
87+
schema:
88+
$ref: "#/components/schemas/Error"
89+
components:
90+
schemas:
91+
Pet:
92+
type: object
93+
required:
94+
- id
95+
- name
96+
properties:
97+
id:
98+
type: integer
99+
format: int64
100+
name:
101+
type: string
102+
tag:
103+
type: string
104+
Pets:
105+
type: array
106+
maxItems: 100
107+
items:
108+
$ref: "#/components/schemas/Pet"
109+
Error:
110+
type: object
111+
required:
112+
- code
113+
- message
114+
properties:
115+
code:
116+
type: integer
117+
format: int32
118+
message:
119+
type: string

specs/petstore-revision.yaml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
maximum: 100
24+
format: int32
25+
responses:
26+
'200':
27+
description: A paged array of pets
28+
headers:
29+
x-next:
30+
description: A link to the next page of responses
31+
schema:
32+
type: string
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/Pets"
37+
default:
38+
description: unexpected error
39+
content:
40+
application/json:
41+
schema:
42+
$ref: "#/components/schemas/Error"
43+
post:
44+
summary: Create a pet
45+
operationId: createPets
46+
tags:
47+
- pets
48+
requestBody:
49+
content:
50+
application/json:
51+
schema:
52+
$ref: '#/components/schemas/Pet'
53+
required: true
54+
responses:
55+
'201':
56+
description: Null response
57+
default:
58+
description: unexpected error
59+
content:
60+
application/json:
61+
schema:
62+
$ref: "#/components/schemas/Error"
63+
/pets/{petId}:
64+
get:
65+
summary: Info for a specific pet
66+
operationId: showPetById
67+
tags:
68+
- pets
69+
parameters:
70+
- name: petId
71+
in: path
72+
required: true
73+
description: The id of the pet to retrieve
74+
schema:
75+
type: string
76+
responses:
77+
'200':
78+
description: Expected response to a valid request
79+
content:
80+
application/json:
81+
schema:
82+
$ref: "#/components/schemas/Pet"
83+
default:
84+
description: unexpected error
85+
content:
86+
application/json:
87+
schema:
88+
$ref: "#/components/schemas/Error"
89+
components:
90+
schemas:
91+
Pet:
92+
type: object
93+
required:
94+
- id
95+
- tag2
96+
properties:
97+
id:
98+
type: integer
99+
format: int64
100+
name:
101+
type: string
102+
tag2:
103+
type: string
104+
Pets:
105+
type: array
106+
maxItems: 100
107+
items:
108+
$ref: "#/components/schemas/Pet"
109+
Error:
110+
type: object
111+
required:
112+
- code
113+
properties:
114+
code:
115+
type: integer
116+
format: int32
117+
message:
118+
type: string

0 commit comments

Comments
 (0)