From 0b89b3d5bdd1e2d6d70d2289a9473a3a13a47ac9 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 4 Aug 2023 14:02:32 +0200 Subject: [PATCH] Implement exit codes correctly --- .github/workflows/tests.yaml | 14 ++++++---- action.yaml | 26 ++++++++++++++----- ...hecks_incorrect.yaml => checks_error.yaml} | 0 ...ks_fail_on_check.yaml => checks_fail.yaml} | 0 testing/checks_warn.yaml | 3 +++ 5 files changed, 31 insertions(+), 12 deletions(-) rename testing/{checks_incorrect.yaml => checks_error.yaml} (100%) rename testing/{checks_fail_on_check.yaml => checks_fail.yaml} (100%) create mode 100644 testing/checks_warn.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d8b85aa..2e0a42d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,14 +23,18 @@ jobs: data_source: reporting_api__marts checks: ./testing/checks_p*.yaml expected_exit_code: 0 - - name: failing scan on check + - name: scan with check warnings data_source: reporting_api__marts - checks: ./testing/checks_fail_on_check.yaml + checks: ./testing/checks_warn.yaml + expected_exit_code: 1 + - name: scan with check failures + data_source: reporting_api__marts + checks: ./testing/checks_fail.yaml expected_exit_code: 2 - - name: failing scan on error + - name: scan with errors data_source: MISSING_DS - checks: ./testing/checks_pass.yaml - expected_exit_code: 1 + checks: ./testing/checks_error.yaml + expected_exit_code: 3 steps: - name: Checkout uses: actions/checkout@v3 diff --git a/action.yaml b/action.yaml index 21d0e9a..e3839b2 100644 --- a/action.yaml +++ b/action.yaml @@ -122,7 +122,7 @@ runs: shell: bash - name: Scan results link - if: env.SCAN_EXIT_CODE == 0 || env.SCAN_EXIT_CODE == 2 + if: env.SCAN_EXIT_CODE <= 2 run: | echo -e "\033[36;1m-----------------------------\033[0m" echo -e "\033[36;1m View the full scan results -> \033[0m ${{ env.SCAN_CLOUD_LINK }}" @@ -151,7 +151,19 @@ runs: [View the full scan results](${{ env.SCAN_CLOUD_LINK }}) - - name: Comment PR on failure with results + - name: Comment PR on warning + uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3 + continue-on-error: true + if: env.SCAN_EXIT_CODE == 1 + with: + message: | + 🟠 Soda scan completed with the following results: + + ${{ steps.table.outputs.table }} + + [View the full scan results](${{ env.SCAN_CLOUD_LINK }}) + + - name: Comment PR on failure uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3 continue-on-error: true if: env.SCAN_EXIT_CODE == 2 @@ -163,23 +175,23 @@ runs: [View the full scan results](${{ env.SCAN_CLOUD_LINK }}) - - name: Comment PR on fatal failure + - name: Comment PR on scan errors uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3 continue-on-error: true - if: env.SCAN_EXIT_CODE == 1 || env.SCAN_EXIT_CODE == 3 + if: env.SCAN_EXIT_CODE == 3 with: message: | - 🔴 Soda scan failed. Check logs for more details. + 🔴 Soda scan failed. Check the logs for more details. # 6. Post additional message to make it clear scan failed or not - - name: Fail Job if Soda Scan Failed + - name: Fail job if Soda scan failed shell: bash if: env.SCAN_EXIT_CODE != 0 run: | echo -e "\033[31;1;4mSoda Scan failed\033[0m" && exit ${{ env.SCAN_EXIT_CODE }} - - name: Fail Job if Soda Scan Succeeded + - name: Exit job if Soda scan succeeded shell: bash if: env.SCAN_EXIT_CODE == 0 run: | diff --git a/testing/checks_incorrect.yaml b/testing/checks_error.yaml similarity index 100% rename from testing/checks_incorrect.yaml rename to testing/checks_error.yaml diff --git a/testing/checks_fail_on_check.yaml b/testing/checks_fail.yaml similarity index 100% rename from testing/checks_fail_on_check.yaml rename to testing/checks_fail.yaml diff --git a/testing/checks_warn.yaml b/testing/checks_warn.yaml new file mode 100644 index 0000000..2eeb637 --- /dev/null +++ b/testing/checks_warn.yaml @@ -0,0 +1,3 @@ +checks for incidents: + - row_count: + warn: when > 0