|
| 1 | +name: Notification |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + branches: main |
| 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: Data |
| 20 | + uses: actions/github-script@v6 |
| 21 | + continue-on-error: true |
| 22 | + id: data |
| 23 | + with: |
| 24 | + script: | |
| 25 | + const message = context.payload.workflow_run.head_commit.message |
| 26 | + message_sanitized = message.split('\n')[0] |
| 27 | +
|
| 28 | + const check_data = (await github.rest.checks.listForRef({ |
| 29 | + owner: context.payload.repository.owner.login, |
| 30 | + repo: context.payload.repository.name, |
| 31 | + ref: context.payload.workflow_run.head_commit.id, |
| 32 | + })).data.check_runs.filter(check_run => check_run.conclusion === 'failure')[0] |
| 33 | +
|
| 34 | + return { |
| 35 | + job_name: check_data.name, |
| 36 | + job_url: check_data.html_url, |
| 37 | + commit_message: message_sanitized, |
| 38 | + } |
| 39 | +
|
| 40 | + - name: Send Notification |
| 41 | + uses: 8398a7/action-slack@v3 |
| 42 | + with: |
| 43 | + status: custom |
| 44 | + custom_payload: | |
| 45 | + { |
| 46 | + username: 'Github', |
| 47 | + icon_emoji: ':github:', |
| 48 | + mention: 'channel', |
| 49 | + attachments: [{ |
| 50 | + title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ github.event.workflow_run.event }})', |
| 51 | + color: 'danger', |
| 52 | + fields: [{ |
| 53 | + title: 'Commit', |
| 54 | + value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ fromJSON(steps.data.outputs.result).commit_message }}>`, |
| 55 | + short: true |
| 56 | + }, |
| 57 | + { |
| 58 | + title: 'Failed Job', |
| 59 | + value: `<${{ fromJSON(steps.data.outputs.result).job_url }}|${{ fromJSON(steps.data.outputs.result).job_name }}>`, |
| 60 | + short: true |
| 61 | + }, |
| 62 | + { |
| 63 | + title: 'Author', |
| 64 | + value: `${{ github.event.workflow_run.head_commit.author.name }}`, |
| 65 | + short: true |
| 66 | + }, |
| 67 | + { |
| 68 | + title: 'Pipeline URL', |
| 69 | + value: `<https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|${{ github.event.workflow_run.id }}>`, |
| 70 | + short: true |
| 71 | + }] |
| 72 | + }] |
| 73 | + } |
| 74 | + env: |
| 75 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} |
0 commit comments