Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Slack notification #94

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 0 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,58 +68,3 @@ jobs:
run: make test
env:
NGINX_PLUS_VERSION: nightly

notify:
name: Notify
runs-on: ubuntu-20.04
needs: build
if: always() && github.ref == 'refs/heads/main'
steps:
- name: Workflow Status
id: check
uses: martialonline/workflow-status@v2
- name: Output Variables
id: commit
run: |
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
- name: Send Notification
uses: 8398a7/action-slack@v3
if:
steps.check.outputs.status == 'failure' ||
steps.check.outputs.status == 'cancelled'
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':octocat:',
mention: 'channel',
attachments: [{
title: '[${{ steps.commit.outputs.repo }}] ${{ github.workflow }} pipeline has failed',
color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
fields: [{
title: 'Commit Hash',
value: '${{ steps.commit.outputs.sha }}',
short: true
},
{
title: 'Author',
value: '${{ github.actor }}',
short: true
},
{
title: 'Commit Message',
value: `${{ github.event.head_commit.message }}`,
short: false
},
{
title: 'Pipeline URL',
value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
short: false
}]
}]
}
env:
GITHUB_TOKEN: ${{ github.token }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
48 changes: 0 additions & 48 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,3 @@ jobs:
uses: fossas/fossa-action@v1
with:
api-key: ${{ secrets.FOSSA_TOKEN }}

notify:
name: Notify
runs-on: ubuntu-20.04
needs: scan
if: always()
steps:
- name: Workflow Status
id: check
uses: martialonline/workflow-status@v2
- name: Output Variables
id: commit
run: |
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
- name: Send Notification
uses: 8398a7/action-slack@v3
if: steps.check.outputs.status == 'failure'
with:
status: custom
custom_payload: |
{
username: 'Fossa Scan',
icon_emoji: ':fossa:',
mention: 'channel',
attachments: [{
title: '${{ steps.commit.outputs.repo }} ${{ github.workflow }} license scan has failed',
color: 'danger',
fields: [{
title: 'Commit Hash',
value: '${{ steps.commit.outputs.sha }}',
short: true
},
{
title: 'Author',
value: '${{ github.actor }}',
short: true
},
{
title: 'Job URL',
value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
short: false
}]
}]
}
env:
GITHUB_TOKEN: ${{ github.token }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
75 changes: 75 additions & 0 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Notification

on:
workflow_run:
branches: main
workflows:
- "Continuous Integration"
- "CodeQL"
- "Fossa"
- "Lint"
types:
- completed

jobs:
on-failure:
runs-on: ubuntu-20.04
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Data
uses: actions/github-script@v6
continue-on-error: true
id: data
with:
script: |
const message = context.payload.workflow_run.head_commit.message
message_sanitized = message.split('\n')[0]

const check_data = (await github.rest.checks.listForRef({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
ref: context.payload.workflow_run.head_commit.id,
})).data.check_runs.filter(check_run => check_run.conclusion === 'failure')[0]

return {
job_name: check_data.name,
job_url: check_data.html_url,
commit_message: message_sanitized,
}

- name: Send Notification
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':github:',
mention: 'channel',
attachments: [{
title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ github.event.workflow_run.event }})',
color: 'danger',
fields: [{
title: 'Commit',
value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ fromJSON(steps.data.outputs.result).commit_message }}>`,
short: true
},
{
title: 'Failed Job',
value: `<${{ fromJSON(steps.data.outputs.result).job_url }}|${{ fromJSON(steps.data.outputs.result).job_name }}>`,
short: true
},
{
title: 'Author',
value: `${{ github.event.workflow_run.head_commit.author.name }}`,
short: true
},
{
title: 'Pipeline URL',
value: `<https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|${{ github.event.workflow_run.id }}>`,
short: true
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}