From a2697f6f3b9f4ee1149555e721a36a74dc46772d Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Mon, 31 Jul 2023 09:34:16 -0400 Subject: [PATCH] testing slack notification (#68) --- .github/workflows/ci_release.yml | 32 ++++++++++++++++++ .github/workflows/reusable_notify_slack.yml | 36 +++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/reusable_notify_slack.yml diff --git a/.github/workflows/ci_release.yml b/.github/workflows/ci_release.yml index 27e999e..feb2652 100644 --- a/.github/workflows/ci_release.yml +++ b/.github/workflows/ci_release.yml @@ -78,3 +78,35 @@ jobs: # docker_password: ${{ secrets.DOCKER_PASSWORD}} # docker_repository: # semver_version: ${{ needs.release.outputs.new_version }} + + # notify-slack-on-failure will send a message to slack if the workflow fails. + # This shows how to use the reusable workflow. Below is how to call it directly. + notify-slack-on-failure: + needs: [yamllint, markdown-lint] + # Always run, regardless of job failures, only run on main/master branches. + if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') + secrets: inherit + uses: ./.github/workflows/reusable_notify_slack.yml + + # Option for directly calling the workflow + # notify-slack-on-failure: + # needs: [yamllint, markdown-lint] + # if: always() + # # if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') + # runs-on: ubuntu-latest + # steps: + # # run this action to get the workflow conclusion + # # You can get the conclusion via env (env.WORKFLOW_CONCLUSION) + # - uses: technote-space/workflow-conclusion-action@v3 + + # - name: Notify Slack On Failure + # uses: ravsamhq/notify-slack-action@v2 + # with: + # status: ${{ env.WORKFLOW_CONCLUSION }} + # token: ${{ secrets.GITHUB_TOKEN }} + # notification_title: "{workflow} has {status_message}" + # message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + # footer: "" + # notify_when: "failure" + # env: + # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_RELEASE_CHANNEL }} diff --git a/.github/workflows/reusable_notify_slack.yml b/.github/workflows/reusable_notify_slack.yml new file mode 100644 index 0000000..bcc00d7 --- /dev/null +++ b/.github/workflows/reusable_notify_slack.yml @@ -0,0 +1,36 @@ +name: "Notify Slack" +on: + workflow_call: + +# This is a reuable workflow instead of a composite action so that we can +# inherit secrets and reduce the inputs to zero. + +jobs: + stale: + runs-on: ubuntu-latest + steps: + # run this action to get the workflow conclusion + # You can get the conclusion via env (env.WORKFLOW_CONCLUSION) + # + # NOTE: it is important that we use the workflow conclusion, otherwise the + # job status will always be successful since it is just the job of notifying + # slack. + - uses: technote-space/workflow-conclusion-action@v3 + + - name: Notify Slack On Failure + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ env.WORKFLOW_CONCLUSION }} + token: ${{ secrets.GITHUB_TOKEN }} + # These fields could be updated to be inputs, but that might make the + # reuseable action less useful since it there wouldn't be much + # refactored. + notification_title: "{workflow} has {status_message}" + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>" + footer: "" + notify_when: "failure" + env: + # This could be updated to a more generic name that repos could set as a + # way to customize which channel they are reporting to. Currently this + # is an org level secret. + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_RELEASE_CHANNEL }}