Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output to file option #44

Merged
merged 10 commits into from
Mar 7, 2024
53 changes: 42 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -7,15 +7,22 @@ jobs:
runs-on: ubuntu-latest
name: Test diff action
steps:
- name: checkout
uses: actions/checkout@v4
- name: Running diff action
id: test_ete
uses: ./diff
with:
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'
- name: checkout
uses: actions/checkout@v4
- name: Running diff action
id: test_ete
uses: ./diff
with:
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'
output-to-file: 'diff.txt'
- name: Test diff action output to file
run: |
if [ ! -s diff.txt ]; then
echo "Diff file doesn't exist or is empty"
exit 1
fi
oasdiff_diff_exclude_elements:
runs-on: ubuntu-latest
name: Test diff action with exclude-elements option
@@ -54,6 +61,7 @@ jobs:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
fail-on-diff: false
output-to-file: 'breaking.txt'
- name: Test breaking changes action output
run: |
delimiter=$(cat /proc/sys/kernel/random/uuid | tr -d '-')
@@ -62,7 +70,18 @@ jobs:
$delimiter
)
if [ "$output" != "1 breaking changes: 1 error, 0 warning" ]; then
echo "Expected output '6 breaking changes: 2 error, 4 warning' but got '$output'" >&2
echo "Expected output '1 breaking changes: 1 error, 0 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)
if [[ "${output}" != "1 breaking changes: 1 error, 0 warning" ]]; then
echo "Expected output '1 breaking changes: 1 error, 0 warning' but got '${output}'" >&2
exit 1
fi
oasdiff_breaking_deprecation:
@@ -98,11 +117,23 @@ jobs:
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
output-to-file: "changelog.txt"
- name: Test changelog action output
run: |
readonly expected_output="20 changes: 2 error, 4 warning, 14 info"
output=$(echo "${{steps.test_changelog.outputs.changelog}}" | head -n 1)
if [[ "${output}" != "${expected_output}" ]]; then
echo "Expected output '20 changes: 2 error, 4 warning, 14 info' but got '${output}'" >&2
exit 1
fi
fi
- name: Test changelog action output to file
run: |
if [ ! -s changelog.txt ]; then
echo "Changelog file doesn't exist or is empty"
exit 1
fi
output=$(cat changelog.txt | head -n 1)
if [[ "${output}" != "20 changes: 2 error, 4 warning, 14 info" ]]; then
echo "Expected output '20 changes: 2 error, 4 warning, 14 info' but got '${output}'" >&2
exit 1
fi
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,14 +16,15 @@ Copy and paste the following snippet into your build .yml file:
revision: 'specs/revision.yaml'
```

This action supports additional arguments that are converted to parameters for the `oasdiff` CLI.
This action supports additional arguments. Most are converted to parameters for the `oasdiff` CLI.

| CLI | Action input | Default |
|--------|--------|--------|
| --fail-on-diff | fail-on-diff | false |
| --format | format | yaml |
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |
| CLI | Action input | Default |
| --------------------- | ------------------- | ------- |
| --fail-on-diff | fail-on-diff | false |
| --format | format | yaml |
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |
| N/A | output-to-file | '' |

### Check for breaking API changes, and fail if any are found
Copy and paste the following snippet into your build .yml file:
@@ -38,13 +39,14 @@ Copy and paste the following snippet into your build .yml file:
Additional arguments:

| CLI | Action input | Default |
|---------------------------|-------------------------|---------|
| ------------------------- | ----------------------- | ------- |
| --fail-on WARN | fail-on-diff | true |
| --include-checks | include-checks | csv |
| --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 | '' |
| N/A | output-to-file | '' |

This action delivers a summary of breaking changes, accessible as a GitHub step output named `breaking`.

@@ -60,7 +62,8 @@ Copy and paste the following snippet into your build .yml file:

Additional arguments:

| CLI | Action input | Default |
|--------|--------|--------|
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |
| CLI | Action input | Default |
| --------------------- | ------------------- | ------- |
| --include-path-params | include-path-params | false |
| --exclude-elements | exclude-elements | '' |
| N/A | output-to-file | '' |
5 changes: 5 additions & 0 deletions breaking/action.yml
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ inputs:
description: 'Exclude certain kinds of changes'
required: false
default: ''
output-to-file:
description: 'Output to a file at the given path'
required: false
default: ''
outputs:
breaking:
description: 'Output summary of API breaking changes, encompassing both warnings and errors'
@@ -43,3 +47,4 @@ runs:
- ${{ inputs.deprecation-days-beta }}
- ${{ inputs.deprecation-days-stable }}
- ${{ inputs.exclude-elements }}
- ${{ inputs.output-to-file }}
34 changes: 15 additions & 19 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
set -e

source $GITHUB_WORKSPACE/common/common.sh

readonly base="$1"
readonly revision="$2"
readonly fail_on_diff="$3"
@@ -9,28 +11,29 @@ readonly include_path_params="$5"
readonly deprecation_days_beta="$6"
readonly deprecation_days_stable="$7"
readonly exclude_elements="$8"
readonly output_to_file="$9"

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=""
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on WARN"
flags="$flags --fail-on WARN"
fi
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
flags="$flags --include-path-params"
fi
if [ -n "$include_checks" ]; then
flags="${flags} --include-checks $include_checks"
flags="$flags --include-checks $include_checks"
fi
if [ -n "$deprecation_days_beta" ]; then
flags="${flags} --deprecation-days-beta $deprecation_days_beta"
flags="$flags --deprecation-days-beta $deprecation_days_beta"
fi
if [ -n "$deprecation_days_stable" ]; then
flags="${flags} --deprecation-days-stable $deprecation_days_stable"
flags="$flags --deprecation-days-stable $deprecation_days_stable"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
if [ -n "$exclude_elements" ]; then
flags="$flags --exclude-elements $exclude_elements"
fi
echo "flags: $flags"

@@ -42,7 +45,7 @@ echo "flags: $flags"
# {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
echo "breaking<<$delimiter" >>"$GITHUB_OUTPUT"

if [ -n "$flags" ]; then
output=$(oasdiff breaking "$base" "$revision" $flags | head -n 1)
@@ -51,23 +54,16 @@ else
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
write_output "$output"
else
echo "No breaking changes" >>$GITHUB_OUTPUT
write_output "No breaking changes"
fi

echo "$delimiter" >>$GITHUB_OUTPUT
echo "$delimiter" >>"$GITHUB_OUTPUT"

# *** github action step output ***

# Updating GitHub Action summary with formatted output
flags="${flags} --format githubactions"
flags="$flags --format githubactions"
# Writes the summary to log and updates GitHub Action summary
oasdiff breaking "$base" "$revision" $flags
5 changes: 5 additions & 0 deletions changelog/action.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ inputs:
description: 'Exclude certain kinds of changes'
required: false
default: ''
output-to-file:
description: 'Output to a file at the given path'
required: false
default: ''
outputs:
changelog:
description: 'Output summary of API changelog'
@@ -26,3 +30,4 @@ runs:
- ${{ inputs.revision }}
- ${{ inputs.include-path-params }}
- ${{ inputs.exclude-elements }}
- ${{ inputs.output-to-file }}
24 changes: 10 additions & 14 deletions changelog/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#!/bin/sh
set -e

source $GITHUB_WORKSPACE/common/common.sh

readonly base="$1"
readonly revision="$2"
readonly include_path_params="$3"
readonly exclude_elements="$4"
readonly output_to_file="$5"

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"
flags="$flags --include-path-params"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
if [ -n "$exclude_elements" ]; then
flags="$flags --exclude-elements $exclude_elements"
fi
echo "flags: $flags"

@@ -28,7 +31,7 @@ set -o pipefail
# {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 "changelog<<$delimiter" >>$GITHUB_OUTPUT
echo "changelog<<$delimiter" >>"$GITHUB_OUTPUT"

if [ -n "$flags" ]; then
output=$(oasdiff changelog "$base" "$revision" $flags)
@@ -37,19 +40,12 @@ else
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: changelog exceeds the 1MB limit, truncating output..." >&2
output=$(echo "$output" | head -c 1000000)
fi
echo "$output" >>$GITHUB_OUTPUT
write_output "$output"
else
echo "No changelog changes" >>$GITHUB_OUTPUT
write_output "No changelog changes"
fi

echo "$delimiter" >>$GITHUB_OUTPUT
echo "$delimiter" >>"$GITHUB_OUTPUT"

# *** github action step output ***

14 changes: 14 additions & 0 deletions common/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
write_output () {
local output="$1"
if [ -n "$output_to_file" ]; then
echo "$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"
}
5 changes: 5 additions & 0 deletions diff/action.yml
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@ inputs:
description: 'Exclude certain kinds of changes'
required: false
default: ''
output-to-file:
description: 'Output to a file at the given path'
required: false
default: ''
outputs:
diff:
description: 'Output summary of API diff'
@@ -36,3 +40,4 @@ runs:
- ${{ inputs.fail-on-diff }}
- ${{ inputs.include-path-params }}
- ${{ inputs.exclude-elements }}
- ${{ inputs.output-to-file }}
28 changes: 12 additions & 16 deletions diff/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#!/bin/sh
set -e

source $GITHUB_WORKSPACE/common/common.sh

readonly base="$1"
readonly revision="$2"
readonly format="$3"
readonly fail_on_diff="$4"
readonly include_path_params="$5"
readonly exclude_elements="$6"
readonly output_to_file="$7"

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=""
if [ "$format" != "yaml" ]; then
flags="${flags} --format ${format}"
flags="$flags --format $format"
fi
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on-diff"
flags="$flags --fail-on-diff"
fi
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
flags="$flags --include-path-params"
fi
if [ "$exclude_elements" != "" ]; then
flags="${flags} --exclude-elements ${exclude_elements}"
if [ -n "$exclude_elements" ]; then
flags="$flags --exclude-elements $exclude_elements"
fi
echo "flags: $flags"

@@ -34,7 +37,7 @@ echo "flags: $flags"
# {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
echo "diff<<$delimiter" >>"$GITHUB_OUTPUT"

set -o pipefail

@@ -45,16 +48,9 @@ else
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: diff exceeds the 1MB limit, truncating output..." >&2
output=$(echo "$output" | head -c $1000000)
fi
echo "$output" >>$GITHUB_OUTPUT
write_output "$output"
else
echo "No changes" >>$GITHUB_OUTPUT
write_output "No changes"
fi

echo "$delimiter" >>$GITHUB_OUTPUT
echo "$delimiter" >>"$GITHUB_OUTPUT"

Unchanged files with check annotations Beta

openapi: "3.0.0"

Check failure on line 1 in specs/base.yaml

GitHub Actions / Test breaking changes

api-removed-without-deprecation

in API GET /pets api removed without deprecation
info:
version: 1.0.0
title: Swagger Petstore