Skip to content

Commit

Permalink
GitHub Action Output Part 2: breaking changes github step output (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
effoeffi authored Dec 4, 2023
1 parent ec6556e commit 4ad4737
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test OpenAPI Spec Diff Action'
name: 'Test oasdiff actions'
on:
pull_request:
push:
Expand Down Expand Up @@ -29,6 +29,17 @@ 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
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.outputs.breaking }}
$delimiter
)
if [ "$output" != "6 breaking changes: 2 error, 4 warning" ]; then
echo "Expected output '6 breaking changes: 2 error, 4 warning' but got '$output'" >&2
exit 1
fi
oasdiff_breaking_deprecation:
runs-on: ubuntu-latest
name: Test breaking changes with deprecation
Expand Down Expand Up @@ -58,7 +69,7 @@ jobs:
uses: actions/checkout@v3
- name: Running changelog action
id: test_changelog
uses: oasdiff/oasdiff-action/changelog@v0.0.10
uses: ./changelog
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
GitHub actions for comparing OpenAPI specs and detect breaking changes, based on [oasdiff](https://github.com/Tufin/oasdiff) tool

## How to use?
Depends on your use case:
Depending on your use case, refer below for instructions on generating reports for differences, breaking changes and changelog.

### Generate a diff report
Copy and paste the following snippet into your build .yml file:
Expand Down Expand Up @@ -44,6 +44,7 @@ Additional arguments:
| --deprecation-days-beta | deprecation-days-beta | 31 |
| --deprecation-days-stable | deprecation-days-stable | 180 |

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

### Generate a changelog
Copy and paste the following snippet into your build .yml file:
Expand Down
6 changes: 3 additions & 3 deletions breaking/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'OpenAPI Spec: check for breaking API changes'
description: 'Detect breaking changes in OpenAPI Specification 3'
name: 'Check for API breaking changes'
description: 'Detect breaking changes'
inputs:
base:
description: 'Path of original OpenAPI spec in YAML or JSON format'
Expand All @@ -26,7 +26,7 @@ inputs:
required: false
outputs:
breaking:
description: 'Output summary of API Breaking Changes, encompassing both warnings and errors'
description: 'Output summary of API breaking changes, encompassing both warnings and errors'
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
35 changes: 31 additions & 4 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readonly include_path_params="$5"
readonly deprecation_days_beta="$6"
readonly deprecation_days_stable="$7"

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"

# Build flags to pass in command
flags=""
Expand All @@ -28,8 +28,35 @@ fi
if [ -n "$deprecation_days_stable" ]; then
flags="${flags} --deprecation-days-stable $deprecation_days_stable"
fi
flags="${flags} --format githubactions"
echo "flags: $flags"

output=$(oasdiff breaking "$base" "$revision" $flags)
echo $output
# *** 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 | head -n 1)
else
output=$(oasdiff breaking "$base" "$revision" | head -n 1)
fi
if [ -n "$output" ]; then
echo "$output" >>$GITHUB_OUTPUT
else
echo "No breaking changes" >>$GITHUB_OUTPUT
fi

echo "$delimiter" >>$GITHUB_OUTPUT

# *** github action step output ***

# Updating GitHub Action summary with formatted output
flags="${flags} --format githubactions"
output_github_action_summary=$(oasdiff breaking "$base" "$revision" $flags)
# Writes the summary to log and updates GitHub Action summary
echo $output_github_action_summary

0 comments on commit 4ad4737

Please sign in to comment.