-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
209 lines (186 loc) · 7.17 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
---
name: 'Soda Library Action'
description: 'Prevent downstream data quality issues by integrating the Soda Library into your CI/CD pipeline.'
branding:
icon: 'check-circle'
color: 'green'
inputs:
soda_library_version:
description: 'Version of the Soda Library on which to run the scan'
required: true
data_source:
description: 'Data Source name'
required: true
configuration:
description: 'Configuration file'
required: true
checks:
description: 'Checks file(s)'
required: true
runs:
using: "composite"
steps:
# 0. Check if required inputs are set
- name: Check required inputs
run: |
[[ "${{ inputs.soda_library_version }}" ]] || { echo -e "\033[31;1;4m[Soda Library Github Action] Input: 'soda_library_version' is required\033[0m" ; exit 1; }
[[ "${{ inputs.data_source }}" ]] || { echo -e "\033[31;1;4m[Soda Library Github Action] Input: 'data_source' is required\033[0m" ; exit 1; }
[[ "${{ inputs.configuration }}" ]] || { echo -e "\033[31;1;4m[Soda Library Github Action] Input: 'configuration' is required\033[0m" ; exit 1; }
[[ "${{ inputs.checks }}" ]] || { echo -e "\033[31;1;4m[Soda Library Github Action] Input: 'checks' is required\033[0m" ; exit 1; }
shell: bash
# 1. Build docker image with a specific soda-library version for the base image
- name: Build the Docker image
run: |
docker build \
${GITHUB_ACTION_PATH} \
--file ${GITHUB_ACTION_PATH}/Dockerfile \
-t soda_action_${{ github.sha }} \
--build-arg="SODA_LIBRARY_VERSION=${{ inputs.soda_library_version }}"
shell: bash
# 2. Need to expand the environment variables to pass to the docker run command
# as these variables can be configured in the workflow file and contain secrets etc.
- name: Set job related envs for PR
if: ${{ github.event_name == 'pull_request' }}
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
env > .env_file
shell: bash
- name: Set job related envs for non-PR
if: ${{ github.event_name != 'pull_request' }}
env:
BRANCH_NAME: ${{ github.ref_name }}
PR_TITLE: ${{ github.event.head_commit.message }}
PR_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
PR_NUMBER: false
run: |
env > .env_file
shell: bash
# 3. Run built image to trigger the actual scan
- name: Run the docker with the scan
id: soda_scan
run: |
docker run \
--workdir ${GITHUB_ACTION_PATH} \
--env-file .env_file \
-e "HOME" \
-e "GITHUB_JOB" \
-e "GITHUB_REF" \
-e "GITHUB_SHA" \
-e "GITHUB_REPOSITORY" \
-e "GITHUB_REPOSITORY_OWNER" \
-e "GITHUB_REPOSITORY_OWNER_ID" \
-e "GITHUB_RUN_ID" \
-e "GITHUB_RUN_NUMBER" \
-e "GITHUB_RETENTION_DAYS" \
-e "GITHUB_RUN_ATTEMPT" \
-e "GITHUB_REPOSITORY_ID" \
-e "GITHUB_ACTOR_ID" \
-e "GITHUB_ACTOR" \
-e "GITHUB_TRIGGERING_ACTOR" \
-e "GITHUB_HEAD_REF" \
-e "GITHUB_BASE_REF" \
-e "GITHUB_EVENT_NAME" \
-e "GITHUB_SERVER_URL" \
-e "GITHUB_API_URL" \
-e "GITHUB_GRAPHQL_URL" \
-e "GITHUB_REF_NAME" \
-e "GITHUB_REF_PROTECTED" \
-e "GITHUB_REF_TYPE" \
-e "GITHUB_WORKFLOW_REF" \
-e "GITHUB_WORKFLOW_SHA" \
-e "GITHUB_WORKSPACE" \
-e "GITHUB_ACTION" \
-e "GITHUB_EVENT_PATH" \
-e "GITHUB_ACTION_REPOSITORY" \
-e "GITHUB_ACTION_REF" \
-e "GITHUB_PATH" \
-e "GITHUB_ENV" \
-e "GITHUB_STEP_SUMMARY" \
-e "GITHUB_STATE" \
-e "GITHUB_OUTPUT" \
-e "GITHUB_ACTION_PATH" \
-e "RUNNER_OS" \
-e "RUNNER_ARCH" \
-e "RUNNER_NAME" \
-e "RUNNER_TOOL_CACHE" \
-e "RUNNER_TEMP" \
-e "RUNNER_WORKSPACE" \
-e "ACTIONS_RUNTIME_URL" \
-e "ACTIONS_RUNTIME_TOKEN" \
-e "ACTIONS_CACHE_URL" \
-e GITHUB_ACTIONS=true \
-e CI=true \
--rm \
-v ${{ github.env}}:${{ github.env}} \
-v ${GITHUB_ACTION_PATH}:/tmp/action_path \
-v ${{ github.workspace }}:/tmp/workspace \
soda_action_${{ github.sha }} \
${{ inputs.data_source }} \
"${{ inputs.configuration }}" \
"${{ inputs.checks }}" || true
shell: bash
- name: Scan results link
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 }}"
echo -e "\033[36;1m-----------------------------\033[0m"
shell: bash
# 4. The soda-library scan results are converted to a markdown table
# Using newest hash from 1.0.0 version.
- uses: buildingcash/json-to-markdown-table-action@ce128b72e0c93612c8f02b85e0672bcb16fd9bf9
id: table
if: ${{ env.SCAN_RESULTS }}
with:
json: ${{ env.SCAN_RESULTS }}
# 5. Create the PR comment
# Using newest hash from 2.4.0 version.
- name: Comment PR on success
uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3
continue-on-error: true
if: env.SCAN_EXIT_CODE == 0
with:
message: |
🟢 Soda scan completed successfully with the following results:
${{ steps.table.outputs.table }}
[View the full scan results](${{ env.SCAN_CLOUD_LINK }})
- 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
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 scan errors
uses: thollander/actions-comment-pull-request@8c77f42bbcc27c832a3a5962c8f9a60e34b594f3
continue-on-error: true
if: env.SCAN_EXIT_CODE == 3
with:
message: |
🔴 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
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: Exit job if Soda scan succeeded
shell: bash
if: env.SCAN_EXIT_CODE == 0
run: |
echo -e "\33[32;1;4mSoda Scan succeeded\033[0m"