|
| 1 | +name: Notification |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + branches: [master] |
| 6 | + workflows: |
| 7 | + - "Continuous Integration" |
| 8 | + - "CodeQL" |
| 9 | + - "Fossa" |
| 10 | + - "Lint" |
| 11 | + types: |
| 12 | + - completed |
| 13 | + |
| 14 | +jobs: |
| 15 | + on-failure: |
| 16 | + runs-on: ubuntu-20.04 |
| 17 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 18 | + steps: |
| 19 | + - name: Output Variables |
| 20 | + continue-on-error: true |
| 21 | + id: vars |
| 22 | + run: | |
| 23 | + suite_id=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | jq '.check_suite_id') |
| 24 | + event=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | jq -r '.event') |
| 25 | + name=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/check-suites/$suite_id/check-runs | jq -r '[.check_runs[] | select(.conclusion=="failure")][0].name') |
| 26 | + url=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/check-suites/$suite_id/check-runs | jq -r '[.check_runs[] | select(.conclusion=="failure")][0].html_url') |
| 27 | + message_sanitized=$(awk '{gsub("&","&");gsub("<","\\<");gsub(">","\\>");print}' <<<'${{ github.event.workflow_run.head_commit.message }}') |
| 28 | +
|
| 29 | + echo "::set-output name=name::$name" |
| 30 | + echo "::set-output name=url::$url" |
| 31 | + echo "::set-output name=event::$event" |
| 32 | + echo "::set-output name=message::$message_sanitized" |
| 33 | +
|
| 34 | + - name: Send Notification |
| 35 | + uses: 8398a7/action-slack@v3 |
| 36 | + with: |
| 37 | + status: custom |
| 38 | + custom_payload: | |
| 39 | + { |
| 40 | + username: 'Github', |
| 41 | + icon_emoji: ':github:', |
| 42 | + mention: 'channel', |
| 43 | + attachments: [{ |
| 44 | + title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ steps.vars.outputs.event }})', |
| 45 | + color: 'danger', |
| 46 | + fields: [{ |
| 47 | + title: 'Commit', |
| 48 | + value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ steps.vars.outputs.message }}>`, |
| 49 | + short: true |
| 50 | + }, |
| 51 | + { |
| 52 | + title: 'Failed Job', |
| 53 | + value: `<${{ steps.vars.outputs.url }}|${{ steps.vars.outputs.name }}>`, |
| 54 | + short: true |
| 55 | + }, |
| 56 | + { |
| 57 | + title: 'Author', |
| 58 | + value: `${{ github.event.workflow_run.head_commit.author.name }}`, |
| 59 | + short: true |
| 60 | + }, |
| 61 | + { |
| 62 | + title: 'Pipeline URL', |
| 63 | + value: `<https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|${{ github.event.workflow_run.id }}>`, |
| 64 | + short: true |
| 65 | + }] |
| 66 | + }] |
| 67 | + } |
| 68 | + env: |
| 69 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} |
0 commit comments