From 214d1e01182df52cccea6b4652b3a75233a72529 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 2 Jul 2023 16:33:32 +0300 Subject: [PATCH 1/4] support oasdiff with subcommands --- README.md | 4 ++-- check-breaking/action.yml | 2 +- check-breaking/entrypoint.sh | 4 ++-- diff/action.yml | 2 +- diff/entrypoint.sh | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5aadb1f..c72b910 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ GitHub actions for comparing OpenAPI specs and detect breaking changes, based on [oasdiff](https://github.com/Tufin/oasdiff) tool ## How to use? -Depend on your use case: +Depends on your use case: -### Find diff +### Generate a diff report Copy and paste the following snippet into your build .yml file: ``` - name: Running OpenAPI Spec diff action diff --git a/check-breaking/action.yml b/check-breaking/action.yml index 482a9a9..768ef9f 100644 --- a/check-breaking/action.yml +++ b/check-breaking/action.yml @@ -14,7 +14,7 @@ inputs: fail-on-warns: description: "Fail with exit code 1 if any WARN-level breaking changes are found" required: false - default: false + default: 'false' runs: using: "docker" image: "Dockerfile" diff --git a/check-breaking/entrypoint.sh b/check-breaking/entrypoint.sh index 2f9c000..0c7ffb9 100755 --- a/check-breaking/entrypoint.sh +++ b/check-breaking/entrypoint.sh @@ -7,9 +7,9 @@ readonly fail_on_warns="$4" echo "running oasdiff check for breaking-changes... base: $base, revision: $revision, fail_on_diff: $fail_on_diff, fail_on_warns: $fail_on_warns" -readonly fail_on_warns_argument=$(if [ "$fail_on_warns" = "true" ]; then echo "-fail-on-warns"; fi) +readonly fail_on_argument=$(if [ "$fail_on_warns" = "true" ]; then echo "--fail-on WARN"; fi) -oasdiff -check-breaking -fail-on-diff -base "$base" -revision "$revision" "$fail_on_warns_argument" +oasdiff breaking "$base" "$revision" "$fail_on_argument" if [ $? != 0 ] && [ "$fail_on_diff" = "true" ]; then exit 1 fi diff --git a/diff/action.yml b/diff/action.yml index 416afdd..b8fc9d5 100644 --- a/diff/action.yml +++ b/diff/action.yml @@ -14,7 +14,7 @@ inputs: fail-on-diff: description: 'Fail with exit code 1 if a difference is found' required: false - default: false + default: 'false' runs: using: 'docker' image: 'Dockerfile' diff --git a/diff/entrypoint.sh b/diff/entrypoint.sh index 69da3b2..739581a 100755 --- a/diff/entrypoint.sh +++ b/diff/entrypoint.sh @@ -10,7 +10,7 @@ echo "running oasdiff... base: $base, revision: $revision, format: $format, fail if [ "$fail_on_diff" = "true" ] then - oasdiff -fail-on-diff -format "$format" -base "$base" -revision "$revision" + oasdiff diff "$base" "$revision" --fail-on-diff --format "$format" else - oasdiff -format "$format" -base "$base" -revision "$revision" + oasdiff diff "$base" "$revision" --format "$format" fi From c62454781edd9f43a0816627945acc14f79195c8 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 2 Jul 2023 16:56:05 +0300 Subject: [PATCH 2/4] simplify --- check-breaking/action.yml | 9 ++------- check-breaking/entrypoint.sh | 12 ++++++------ diff/entrypoint.sh | 7 ++++--- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/check-breaking/action.yml b/check-breaking/action.yml index 768ef9f..4b7ac3b 100644 --- a/check-breaking/action.yml +++ b/check-breaking/action.yml @@ -8,13 +8,9 @@ inputs: description: "Path of revised OpenAPI spec in YAML or JSON format" required: true fail-on-diff: - description: "Fail with exit code 1 if any ERR-level breaking changes are found" + description: "Fail with exit code 1 if any breaking changes are found" required: false - default: true - fail-on-warns: - description: "Fail with exit code 1 if any WARN-level breaking changes are found" - required: false - default: 'false' + default: 'true' runs: using: "docker" image: "Dockerfile" @@ -22,4 +18,3 @@ runs: - ${{ inputs.base }} - ${{ inputs.revision }} - ${{ inputs.fail-on-diff }} - - ${{ inputs.fail-on-warns }} diff --git a/check-breaking/entrypoint.sh b/check-breaking/entrypoint.sh index 0c7ffb9..2551c13 100755 --- a/check-breaking/entrypoint.sh +++ b/check-breaking/entrypoint.sh @@ -3,13 +3,13 @@ readonly base="$1" readonly revision="$2" readonly fail_on_diff="$3" -readonly fail_on_warns="$4" -echo "running oasdiff check for breaking-changes... base: $base, revision: $revision, fail_on_diff: $fail_on_diff, fail_on_warns: $fail_on_warns" +echo "running oasdiff check for breaking-changes... base: $base, revision: $revision, fail_on_diff: $fail_on_diff" -readonly fail_on_argument=$(if [ "$fail_on_warns" = "true" ]; then echo "--fail-on WARN"; fi) +set -o pipefail -oasdiff breaking "$base" "$revision" "$fail_on_argument" -if [ $? != 0 ] && [ "$fail_on_diff" = "true" ]; then - exit 1 +if [[ $fail_on_diff = "true" ]]; then + oasdiff breaking "$base" "$revision" --fail-on WARN +else + oasdiff breaking "$base" "$revision" fi diff --git a/diff/entrypoint.sh b/diff/entrypoint.sh index 739581a..49b5880 100755 --- a/diff/entrypoint.sh +++ b/diff/entrypoint.sh @@ -8,9 +8,10 @@ readonly fail_on_diff="$4" echo "running oasdiff... base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff" -if [ "$fail_on_diff" = "true" ] -then +set -o pipefail + +if [[ $fail_on_diff" == "true" ]]; then oasdiff diff "$base" "$revision" --fail-on-diff --format "$format" else - oasdiff diff "$base" "$revision" --format "$format" + oasdiff diff "$base" "$revision" --format "$format" fi From e0e0cfa345caba86613d737a7eec47971f0edc89 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 2 Jul 2023 16:57:44 +0300 Subject: [PATCH 3/4] fix quote --- diff/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff/entrypoint.sh b/diff/entrypoint.sh index 49b5880..58b6d7e 100755 --- a/diff/entrypoint.sh +++ b/diff/entrypoint.sh @@ -10,7 +10,7 @@ echo "running oasdiff... base: $base, revision: $revision, format: $format, fail set -o pipefail -if [[ $fail_on_diff" == "true" ]]; then +if [[ $fail_on_diff == "true" ]]; then oasdiff diff "$base" "$revision" --fail-on-diff --format "$format" else oasdiff diff "$base" "$revision" --format "$format" From 57c6729ca1617bde40754d8e89d0e724f5876a63 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 2 Jul 2023 17:02:54 +0300 Subject: [PATCH 4/4] use new tag --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c13e50..146fd1e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v3 - name: Running OpenAPI Spec check breaking tag action id: test_breaking_changes - uses: oasdiff/oasdiff-action/check-breaking@v0.0.6 + uses: oasdiff/oasdiff-action/check-breaking@v0.0.9 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 \ No newline at end of file