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