Skip to content

Commit e1ae413

Browse files
authored
Merge pull request #8 from sodadata/CLOUD-4354-soda-github-actions-fails-when
[CLOUD-4354] Implement exit codes correctly
2 parents 116ba03 + ddc11c6 commit e1ae413

File tree

8 files changed

+44
-26
lines changed

8 files changed

+44
-26
lines changed

.github/workflows/tests.yaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@ jobs:
2323
data_source: reporting_api__marts
2424
checks: ./testing/checks_p*.yaml
2525
expected_exit_code: 0
26-
- name: failing scan on check
26+
- name: scan with check warnings
2727
data_source: reporting_api__marts
28-
checks: ./testing/checks_fail_on_check.yaml
29-
expected_exit_code: 2
30-
- name: failing scan on error
31-
data_source: MISSING_DS
32-
checks: ./testing/checks_pass.yaml
28+
checks: ./testing/checks_warn.yaml
3329
expected_exit_code: 1
30+
- name: scan with check failures
31+
data_source: reporting_api__marts
32+
checks: ./testing/checks_fail.yaml
33+
expected_exit_code: 2
34+
- name: scan with errors (wrong checks)
35+
data_source: reporting_api__marts
36+
checks: ./testing/checks_error.yaml
37+
expected_exit_code: 3
38+
# Disabled until https://github.com/sodadata/soda-library/pull/63 is merged and released
39+
# - name: scan with errors (wrong data source)
40+
# data_source: MISSING_DS
41+
# checks: ./testing/checks_pass.yaml
42+
# expected_exit_code: 3
3443
steps:
3544
- name: Checkout
3645
uses: actions/checkout@v3
@@ -39,8 +48,7 @@ jobs:
3948
continue-on-error: true
4049
uses: ./
4150
with:
42-
# should be latest, but it is not published yet
43-
soda_library_version: v1.0.4
51+
soda_library_version: v1.0.6
4452
configuration: ./testing/configuration.yaml
4553
data_source: ${{ matrix.data_source }}
4654
checks: ${{ matrix.checks }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ soda_scan_results_raw.json
33
*.DS_store
44
.env_file
55
testing/configuration_local.yaml
6+
.venv

action.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ runs:
122122
shell: bash
123123

124124
- name: Scan results link
125-
if: env.SCAN_EXIT_CODE == 0 || env.SCAN_EXIT_CODE == 2
125+
if: env.SCAN_EXIT_CODE <= 2
126126
run: |
127127
echo -e "\033[36;1m-----------------------------\033[0m"
128128
echo -e "\033[36;1m View the full scan results -> \033[0m ${{ env.SCAN_CLOUD_LINK }}"
@@ -151,7 +151,19 @@ runs:
151151
152152
[View the full scan results](${{ env.SCAN_CLOUD_LINK }})
153153
154-
- name: Comment PR on failure with results
154+
- name: Comment PR on warning
155+
uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3
156+
continue-on-error: true
157+
if: env.SCAN_EXIT_CODE == 1
158+
with:
159+
message: |
160+
🟠 Soda scan completed with the following results:
161+
162+
${{ steps.table.outputs.table }}
163+
164+
[View the full scan results](${{ env.SCAN_CLOUD_LINK }})
165+
166+
- name: Comment PR on failure
155167
uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3
156168
continue-on-error: true
157169
if: env.SCAN_EXIT_CODE == 2
@@ -163,23 +175,23 @@ runs:
163175
164176
[View the full scan results](${{ env.SCAN_CLOUD_LINK }})
165177
166-
- name: Comment PR on fatal failure
178+
- name: Comment PR on scan errors
167179
uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3
168180
continue-on-error: true
169-
if: env.SCAN_EXIT_CODE == 1 || env.SCAN_EXIT_CODE == 3
181+
if: env.SCAN_EXIT_CODE == 3
170182
with:
171183
message: |
172-
🔴 Soda scan failed. Check logs for more details.
184+
🔴 Soda scan failed. Check the logs for more details.
173185
174186
175187
# 6. Post additional message to make it clear scan failed or not
176-
- name: Fail Job if Soda Scan Failed
188+
- name: Fail job if Soda scan failed
177189
shell: bash
178190
if: env.SCAN_EXIT_CODE != 0
179191
run: |
180192
echo -e "\033[31;1;4mSoda Scan failed\033[0m" && exit ${{ env.SCAN_EXIT_CODE }}
181193
182-
- name: Fail Job if Soda Scan Succeeded
194+
- name: Exit job if Soda scan succeeded
183195
shell: bash
184196
if: env.SCAN_EXIT_CODE == 0
185197
run: |

entrypoint.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ soda scan \
1111
--scan-type cicd \
1212
-cif soda_scan_ci_info.json
1313

14-
exit_status=$?
14+
echo "SCAN_EXIT_CODE=$?" >> $GITHUB_ENV
15+
echo "SCAN_CLOUD_LINK=$(python3 /tmp/action_path/scripts/reformat_json.py soda_scan_results_raw.json)" >> $GITHUB_ENV
16+
echo "SCAN_RESULTS=$(cat soda_scan_results.json 2> /dev/null)" >> $GITHUB_ENV
1517

16-
scan_cloud_link=$(python3 /tmp/action_path/scripts/reformat_json.py soda_scan_results_raw.json)
17-
18-
{
19-
echo "SCAN_RESULTS=$(cat soda_scan_results.json)"
20-
echo "SCAN_EXIT_CODE=$exit_status"
21-
echo "SCAN_CLOUD_LINK=$scan_cloud_link"
22-
} >> "$GITHUB_ENV"
23-
24-
exit $exit_status
18+
exit 0

testing/checks_warn.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
checks for incidents:
2+
- row_count:
3+
warn: when > 0

testing/configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ data_source reporting_api__marts:
1515
soda_cloud:
1616
host: dev.sodadata.io
1717
api_key_id: ${CLOUD_API_KEY_ID}
18-
api_key_secret: ${CLOUD_API_KEY_SECRET}
18+
api_key_secret: ${CLOUD_API_KEY_SECRET}

0 commit comments

Comments
 (0)