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

Use workflow_run for notifications, avoid duplication #1892

Merged
merged 8 commits into from
Aug 24, 2021
50 changes: 0 additions & 50 deletions .github/workflows/edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
go_version: ${{ steps.vars.outputs.go_version }}
go_path: ${{ steps.go.outputs.go_path }}
nginx_version: ${{ steps.vars.outputs.nginx_version }}
repo_name: ${{ steps.vars.outputs.repo }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
Expand All @@ -59,7 +58,6 @@ jobs:
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
echo "::set-output name=nginx_version::$(cat build/Dockerfile | grep -m1 "FROM nginx:" | cut -d":" -f2 | cut -d" " -f1)"
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
- name: Setup Golang Environment
uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -446,51 +444,3 @@ jobs:
git -c user.name='${{ env.GIT_NAME }}' -c user.email='${{ env.GIT_MAIL }}' \
commit -m "NGINX Ingress Controller - Edge Release (latest)"
git push -u origin master

notify:
name: Notify
runs-on: ubuntu-20.04
needs: release-helm
if: always() && github.ref == 'refs/heads/master'
steps:
- name: Workflow Status
id: check
uses: martialonline/workflow-status@v2
- name: Send Notification
uses: 8398a7/action-slack@v3
if: steps.check.outputs.status == 'failure'
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':octocat:',
mention: 'channel',
attachments: [{
title: '${{ needs.check.outputs.repo_name }} ${{ github.workflow }} pipeline has failed',
color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
fields: [{
title: 'Commit Hash',
value: '${{ needs.checks.outputs.sha_short }}',
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 @@ -26,51 +26,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 }}
50 changes: 0 additions & 50 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,53 +261,3 @@ jobs:
- name: Test HTTPS
run: |
. tests/ci-files/helm-http-test.sh ${{ env.HELM_TEST_RETRIES }} ${{ env.NGINX_HTTPS_PORT }} ${{ env.HELM_HTTP_POSTFIX }}

notify:
name: Notify
runs-on: ubuntu-20.04
needs: [helm-tests, smoke-tests]
if: always() && github.ref == 'refs/heads/master'
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: '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 }}
58 changes: 58 additions & 0 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
workflow_run:
branches: [master, release-*]
workflows:
- "CodeQL"
- "Edge"
- "Fossa"
- "Lint"
- "Nightly"
- "Release"
- "Update Docker Images"
types:
- completed

jobs:
on-failure:
runs-on: ubuntu-20.04
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Output Variables
id: vars
run: echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: Send Notification
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':octocat:',
mention: 'channel',
attachments: [{
title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed',
color: 'danger',
fields: [{
title: 'Commit Hash',
value: '<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|${{ steps.vars.outputs.sha }}>',
short: true
},
{
title: 'Commit Message',
value: `${{ github.event.workflow_run.head_commit.message }}`,
short: true
},
{
title: 'Author',
value: '<${{ github.event.sender.html_url }}|${{ github.event.sender.login }}>',
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 }}
50 changes: 0 additions & 50 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,53 +181,3 @@ jobs:
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

notify:
name: Notify
runs-on: ubuntu-20.04
needs: publish-release-notes
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' ||
steps.check.outputs.status == 'cancelled'
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':octocat:',
mention: 'channel',
attachments: [{
title: '[${{ needs.binary.outputs.repo }}] ${{ github.workflow }} pipeline has failed',
color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
fields: [{
title: 'Commit Hash',
value: '${{ needs.binary.outputs.sha }}',
short: true
},
{
title: 'Author',
value: '${{ github.actor }}',
short: true
},
{
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 }}
50 changes: 0 additions & 50 deletions .github/workflows/update-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
nginx_version: ${{ steps.versions.outputs.nginx_version }}
sha_short: ${{ steps.vars.outputs.sha }}
go_version: ${{ steps.vars.outputs.go_version }}
repo_name: ${{ steps.vars.outputs.repo }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand All @@ -52,7 +51,6 @@ jobs:
run: |
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"

check:
name: Check if updates are needed
Expand Down Expand Up @@ -294,51 +292,3 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: ${{ matrix.needs-updating == 'true' }}

notify:
name: Notify
runs-on: ubuntu-20.04
needs: [release-docker, variables]
if: always()
steps:
- name: Workflow Status
id: check
uses: martialonline/workflow-status@v2
- name: Send Notification
uses: 8398a7/action-slack@v3
if: steps.check.outputs.status == 'failure'
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':octocat:',
mention: 'channel',
attachments: [{
title: '${{ needs.variables.outputs.repo_name }} ${{ github.workflow }} pipeline has failed',
color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
fields: [{
title: 'Commit Hash',
value: '${{ needs.variables.outputs.sha_short }}',
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 }}