From b28d395a746b2f57b88b11f84ffa568bdb542220 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 11:48:49 -0800 Subject: [PATCH 01/27] first poke at the bear --- .github/workflows/fail-alert.yml | 40 ++++++++++++++++++++++++++++++++ .github/workflows/test-fail.yml | 18 ++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/fail-alert.yml create mode 100644 .github/workflows/test-fail.yml diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml new file mode 100644 index 0000000..3da04ea --- /dev/null +++ b/.github/workflows/fail-alert.yml @@ -0,0 +1,40 @@ +name: Failure Notification +on: + workflow_call: + secrets: + slack_webhook: + required: true + +jobs: + send_notification: + name: Send Failure Notification + runs-on: ubuntu-latest + steps: + - name: Send Slack + uses: slackapi/slack-github-action@v1.27.0 + env: + SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + with: + payload: | + { + "text": "Text that never shows up", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": ":scream:Github Action Failed!","emoji": true + } + }, + { + "type": "context", + "elements": [ + { + "type": "mrkdwn", + "text": "Eat all humans!: ${{ env.CI_BUILD_URL }}" + } + ] + } + ] + } diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml new file mode 100644 index 0000000..f62bcbf --- /dev/null +++ b/.github/workflows/test-fail.yml @@ -0,0 +1,18 @@ +name: Fake Failure Thingy + on: + push: + +jobs: + oh_noes: + runs_on: ubuntu-latest + continue-on-error: true + steps: + - name: Something Fails! + run: | + echo "BOOM" + exit 1 + notify: + uses: .github/workflow/fail-alert.yml + secrets: + slack_webhook: ${{ secrets.TESTING_SLACK_WEBHOOK }} + From 7201eba7d45618c579b77b59d70f2a94e3c91fbb Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 11:50:35 -0800 Subject: [PATCH 02/27] yaml, I know yaml --- .github/workflows/fail-alert.yml | 6 +++--- .github/workflows/test-fail.yml | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 3da04ea..c932e20 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -1,9 +1,9 @@ name: Failure Notification on: workflow_call: - secrets: - slack_webhook: - required: true + secrets: + slack_webhook: + required: true jobs: send_notification: diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml index f62bcbf..ea36164 100644 --- a/.github/workflows/test-fail.yml +++ b/.github/workflows/test-fail.yml @@ -1,6 +1,7 @@ name: Fake Failure Thingy - on: - push: + +on: + push: jobs: oh_noes: From 58d5127235276bbf37822c6e68fc8cec7ff9eb7c Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 11:51:31 -0800 Subject: [PATCH 03/27] reference like this? --- .github/workflows/test-fail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml index ea36164..7aa9794 100644 --- a/.github/workflows/test-fail.yml +++ b/.github/workflows/test-fail.yml @@ -13,7 +13,7 @@ jobs: echo "BOOM" exit 1 notify: - uses: .github/workflow/fail-alert.yml + uses: ./.github/workflow/fail-alert.yml secrets: slack_webhook: ${{ secrets.TESTING_SLACK_WEBHOOK }} From 4fe280c6a1c64357f174a773cc9f85330a0a51c2 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 11:57:59 -0800 Subject: [PATCH 04/27] workflows plural --- .github/workflows/test-fail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml index 7aa9794..b1ef772 100644 --- a/.github/workflows/test-fail.yml +++ b/.github/workflows/test-fail.yml @@ -13,7 +13,7 @@ jobs: echo "BOOM" exit 1 notify: - uses: ./.github/workflow/fail-alert.yml + uses: ./.github/workflows/fail-alert.yml secrets: slack_webhook: ${{ secrets.TESTING_SLACK_WEBHOOK }} From 250bcc4c58a52daae21ba4fccc14c6674f2c9b12 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 11:59:59 -0800 Subject: [PATCH 05/27] hyphen, not underscore --- .github/workflows/test-fail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml index b1ef772..46e09b2 100644 --- a/.github/workflows/test-fail.yml +++ b/.github/workflows/test-fail.yml @@ -5,7 +5,7 @@ on: jobs: oh_noes: - runs_on: ubuntu-latest + runs-on: ubuntu-latest continue-on-error: true steps: - name: Something Fails! From 3d47b961ba76289a33d85dee8d6d4bb6020eb520 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 14:04:07 -0800 Subject: [PATCH 06/27] printy mc printface --- .github/workflows/fail-alert.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index c932e20..3860c30 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -10,7 +10,12 @@ jobs: name: Send Failure Notification runs-on: ubuntu-latest steps: + + - name: Debug + run: | + echo ${{ github | toJSON }} - name: Send Slack + if: false uses: slackapi/slack-github-action@v1.27.0 env: SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook }} From 8ed24124b093c2490b2b215fcb58233b8d89f336 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 14:05:30 -0800 Subject: [PATCH 07/27] dderp --- .github/workflows/fail-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 3860c30..d50c457 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -13,7 +13,7 @@ jobs: - name: Debug run: | - echo ${{ github | toJSON }} + echo ${{ toJSON(github) }} - name: Send Slack if: false uses: slackapi/slack-github-action@v1.27.0 From c312761b988386f293555c106284f68c151eae2d Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 14:13:50 -0800 Subject: [PATCH 08/27] available operators standing by --- .github/workflows/fail-alert.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index d50c457..feb1341 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -12,8 +12,11 @@ jobs: steps: - name: Debug + env: + GITWHAB: ${{ toJson(github) }} run: | - echo ${{ toJSON(github) }} + echo "$GITHUB_CONTEXT" + echo "$GITWHAB" - name: Send Slack if: false uses: slackapi/slack-github-action@v1.27.0 From 4218d02a58b203f958787727e7339d6155790985 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:04:39 -0800 Subject: [PATCH 09/27] don't need that any more --- .github/workflows/test-fail.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/workflows/test-fail.yml diff --git a/.github/workflows/test-fail.yml b/.github/workflows/test-fail.yml deleted file mode 100644 index 46e09b2..0000000 --- a/.github/workflows/test-fail.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Fake Failure Thingy - -on: - push: - -jobs: - oh_noes: - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Something Fails! - run: | - echo "BOOM" - exit 1 - notify: - uses: ./.github/workflows/fail-alert.yml - secrets: - slack_webhook: ${{ secrets.TESTING_SLACK_WEBHOOK }} - From fb9da719cd1c5c521d1355d170c787ec77de9e61 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:12:42 -0800 Subject: [PATCH 10/27] blerg --- .github/workflows/fail-alert.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index feb1341..c283a1b 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -46,3 +46,8 @@ jobs: } ] } + fail: + name: Don't mask failure + runs-on: ubuntu-latest + steps: + - run: exit 1 From f2d5a8c54cec982b71c54770a784ee0879e1ce6d Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:30:19 -0800 Subject: [PATCH 11/27] more fun --- .github/workflows/fail-alert.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index c283a1b..d06afb8 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -1,3 +1,10 @@ +# Simple failure notification reusable workflow +# +# Fast Follows +# +# * inputs we can override, eg workflow name, message, title, etc... +# * an org wide var with the slack webhook so no one has to specify it + name: Failure Notification on: workflow_call: @@ -9,14 +16,16 @@ jobs: send_notification: name: Send Failure Notification runs-on: ubuntu-latest + env: + CI_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} steps: - name: Debug - env: - GITWHAB: ${{ toJson(github) }} run: | - echo "$GITHUB_CONTEXT" - echo "$GITWHAB" + echo "Github Action ${{ github.workflow }} Failed" + echo "on ${{ github.repository }} Repo" + echo "Tell ${{ github.triggering_actor }}" + - name: Send Slack if: false uses: slackapi/slack-github-action@v1.27.0 @@ -26,13 +35,13 @@ jobs: with: payload: | { - "text": "Text that never shows up", + "text": "GH Action ${{ github.workflow}} Failed on ${{ github.repository }}. Tell ${{ github.triggering_actor }}", "blocks": [ { "type": "header", "text": { "type": "plain_text", - "text": ":scream:Github Action Failed!","emoji": true + "text": "Github Workflow ${{ github.workflow }} Failed on ${{ github.repository }}!" } }, { @@ -40,7 +49,7 @@ jobs: "elements": [ { "type": "mrkdwn", - "text": "Eat all humans!: ${{ env.CI_BUILD_URL }}" + "text": "See ${{ env.CI_BUILD_URL }}" } ] } From 4709c482f4e924cc004040193eeae086eda2623f Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:34:56 -0800 Subject: [PATCH 12/27] taking the gloves off --- .github/workflows/fail-alert.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index d06afb8..67f3407 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -27,7 +27,6 @@ jobs: echo "Tell ${{ github.triggering_actor }}" - name: Send Slack - if: false uses: slackapi/slack-github-action@v1.27.0 env: SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook }} From cdc630857bdc3354b16858416205030998cea974 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:41:43 -0800 Subject: [PATCH 13/27] why did that fail? --- .github/workflows/fail-alert.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 67f3407..8830b38 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -21,10 +21,14 @@ jobs: steps: - name: Debug + env: + SECRET: ${{ secrets.slack_webhook }} run: | echo "Github Action ${{ github.workflow }} Failed" echo "on ${{ github.repository }} Repo" echo "Tell ${{ github.triggering_actor }}" + echo -n "Secret ends with: " + echo $SECRET | tail -c 4 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From 0939afb375a49665e1af987047d708ffd35b7be8 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:45:55 -0800 Subject: [PATCH 14/27] why did that fail? --- .github/workflows/fail-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 8830b38..2609ca6 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -28,7 +28,7 @@ jobs: echo "on ${{ github.repository }} Repo" echo "Tell ${{ github.triggering_actor }}" echo -n "Secret ends with: " - echo $SECRET | tail -c 4 + echo "$SECRET" | tail -c 4 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From 1b0400c7e0c1f905cc61f006c2eb95f44ec4629a Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:47:36 -0800 Subject: [PATCH 15/27] why did that fail? --- .github/workflows/fail-alert.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 2609ca6..fddba89 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -22,13 +22,13 @@ jobs: - name: Debug env: - SECRET: ${{ secrets.slack_webhook }} + AS_AN_ENV_VAR: ${{ secrets.slack_webhook }} run: | echo "Github Action ${{ github.workflow }} Failed" echo "on ${{ github.repository }} Repo" echo "Tell ${{ github.triggering_actor }}" echo -n "Secret ends with: " - echo "$SECRET" | tail -c 4 + echo "${AS_AN_ENV_VAR}" | tail -c 4 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From b8cbc51e22b5e89af4571901441c3bdd6644f9fb Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:48:21 -0800 Subject: [PATCH 16/27] why did that fail? --- .github/workflows/fail-alert.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index fddba89..749ce53 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -29,6 +29,7 @@ jobs: echo "Tell ${{ github.triggering_actor }}" echo -n "Secret ends with: " echo "${AS_AN_ENV_VAR}" | tail -c 4 + echo ${{ secrets.slack_webhook }} | wc -c - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From b003d1895f4d63ba2205b831fa2d159e6b506e5e Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:50:04 -0800 Subject: [PATCH 17/27] what the heck? --- .github/workflows/fail-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 749ce53..a75a21e 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -29,7 +29,7 @@ jobs: echo "Tell ${{ github.triggering_actor }}" echo -n "Secret ends with: " echo "${AS_AN_ENV_VAR}" | tail -c 4 - echo ${{ secrets.slack_webhook }} | wc -c + echo ${{ secrets.slack_webhook }} | tail -c 6 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From e3b7057e67aae9727a689773333e4471ba3da0bc Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 15:51:21 -0800 Subject: [PATCH 18/27] what the heck? --- .github/workflows/fail-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index a75a21e..c9e957f 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -29,7 +29,7 @@ jobs: echo "Tell ${{ github.triggering_actor }}" echo -n "Secret ends with: " echo "${AS_AN_ENV_VAR}" | tail -c 4 - echo ${{ secrets.slack_webhook }} | tail -c 6 + echo ${{ secrets.slack_webhook }} | tail -c 10 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 From 639ecf68772c9c8552d9f7954f733c07c4a678cd Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 16:26:31 -0800 Subject: [PATCH 19/27] massage the message --- .github/workflows/fail-alert.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index c9e957f..29deb01 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -21,15 +21,12 @@ jobs: steps: - name: Debug - env: - AS_AN_ENV_VAR: ${{ secrets.slack_webhook }} run: | echo "Github Action ${{ github.workflow }} Failed" echo "on ${{ github.repository }} Repo" echo "Tell ${{ github.triggering_actor }}" - echo -n "Secret ends with: " - echo "${AS_AN_ENV_VAR}" | tail -c 4 - echo ${{ secrets.slack_webhook }} | tail -c 10 + echo -n "Web hook ends with: " + echo ${{ secrets.slack_webhook }} | tail -c 4 - name: Send Slack uses: slackapi/slack-github-action@v1.27.0 @@ -45,7 +42,7 @@ jobs: "type": "header", "text": { "type": "plain_text", - "text": "Github Workflow ${{ github.workflow }} Failed on ${{ github.repository }}!" + "text": "Workflow Failed" } }, { @@ -53,7 +50,7 @@ jobs: "elements": [ { "type": "mrkdwn", - "text": "See ${{ env.CI_BUILD_URL }}" + "text": "On ${{ github.repository }}\n\nworkflow '${{ github.workflow }}'\n\n See ${{ env.CI_BUILD_URL }}" } ] } From ee1cc7632b3469238459adcc63bdcc65d089b5ec Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 16:31:44 -0800 Subject: [PATCH 20/27] forgot actor --- .github/workflows/fail-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 29deb01..ea9d770 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -50,7 +50,7 @@ jobs: "elements": [ { "type": "mrkdwn", - "text": "On ${{ github.repository }}\n\nworkflow '${{ github.workflow }}'\n\n See ${{ env.CI_BUILD_URL }}" + "text": "On ${{ github.repository }}\nworkflow '${{ github.workflow }} failed'\nTell ${{ github.triggering_actor }}.\nSee ${{ env.CI_BUILD_URL }}" } ] } From 4ef0dde34f448709894a8c8b2034b9889b5525f7 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 16:53:17 -0800 Subject: [PATCH 21/27] defang --- .github/workflows/fail-alert.yml | 1 + README.md | 38 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index ea9d770..ac4a8e6 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -29,6 +29,7 @@ jobs: echo ${{ secrets.slack_webhook }} | tail -c 4 - name: Send Slack + if: false uses: slackapi/slack-github-action@v1.27.0 env: SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook }} diff --git a/README.md b/README.md index 089be6a..4d66cf0 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,40 @@ Checks if there is a valid `helmfile.yaml` in the working directory. Executes `h #### [`trufflehog-actions-scan`](trufflehog-actions-scan) -Runs Trufflehog as a GitHub Action. Based off of [`https://github.com/edplato/trufflehog-actions-scan`](https://github.com/edplato/trufflehog-actions-scan). Uses Dependabot to stay up-to-date with the latest version. \ No newline at end of file +Runs Trufflehog as a GitHub Action. Based off of [`https://github.com/edplato/trufflehog-actions-scan`](https://github.com/edplato/trufflehog-actions-scan). Uses Dependabot to stay up-to-date with the latest version. + +#### [`fail-alert`](./github/workflows/fail-alert.yml) + +Reusable workflow, not an action. For when you want a slack alert to notify the person who triggeredthe build when it fails + +1. Add a job that you want to monitor. +2. Add a new job directly after that. +3. It must `needs` the job you want to monitor. +4. set `if: ${{ failure() }}` on the new job. +5. Make the new job `uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main` +6. fail-alert has no inputs, but does require a secrets.slack_webhook for whichever slack channel you want to message. + +Here's an example workflow + +``` +name: Project X + +on: + push + +jobs: + build: + runs-on: ubuntu-latest + steps + - name: Something Fails! + run: | + exit 1 + + notify: + needs: build + if: ${{ failure() }} + uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main + secrets: + slack_webhook: ${{ secrets.DEPLOYMENTS_SLACK_WEBHOOK }} +``` + From af94046ebfbb30a46a87325428d1d1de5e623a98 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 16:59:48 -0800 Subject: [PATCH 22/27] separate doc file --- README.md | 32 +------------------------------- fail-alert.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 fail-alert.md diff --git a/README.md b/README.md index 4d66cf0..1a194c5 100644 --- a/README.md +++ b/README.md @@ -30,38 +30,8 @@ Checks if there is a valid `helmfile.yaml` in the working directory. Executes `h Runs Trufflehog as a GitHub Action. Based off of [`https://github.com/edplato/trufflehog-actions-scan`](https://github.com/edplato/trufflehog-actions-scan). Uses Dependabot to stay up-to-date with the latest version. -#### [`fail-alert`](./github/workflows/fail-alert.yml) +#### [`fail-alert`](./fail-alert.md) Reusable workflow, not an action. For when you want a slack alert to notify the person who triggeredthe build when it fails -1. Add a job that you want to monitor. -2. Add a new job directly after that. -3. It must `needs` the job you want to monitor. -4. set `if: ${{ failure() }}` on the new job. -5. Make the new job `uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main` -6. fail-alert has no inputs, but does require a secrets.slack_webhook for whichever slack channel you want to message. - -Here's an example workflow - -``` -name: Project X - -on: - push - -jobs: - build: - runs-on: ubuntu-latest - steps - - name: Something Fails! - run: | - exit 1 - - notify: - needs: build - if: ${{ failure() }} - uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main - secrets: - slack_webhook: ${{ secrets.DEPLOYMENTS_SLACK_WEBHOOK }} -``` diff --git a/fail-alert.md b/fail-alert.md new file mode 100644 index 0000000..1d9d79e --- /dev/null +++ b/fail-alert.md @@ -0,0 +1,35 @@ +# Fail Alert + +Sends a slack alert when a job fails + +1. Add a job that you want to monitor. +2. Add a new job. +3. It must `needs` any jobs you want to monitor. Needs can accept an array. +4. set `if: ${{ failure() }}` on the new job. +5. Make the new job `uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main` +6. fail-alert has no inputs, but does require a secrets.slack_webhook for whichever slack channel you want to message. + +Here's an example workflow + +``` +name: Project X + +on: + push + +jobs: + build: + runs-on: ubuntu-latest + steps + - name: Something Fails! + run: | + exit 1 + + notify: + needs: build + if: ${{ failure() }} + uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main + secrets: + slack_webhook: ${{ secrets.DEPLOYMENTS_SLACK_WEBHOOK }} +``` + From a09aae25b468c4eb8f8dfd0e4ae9738868a7a30f Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 17:09:27 -0800 Subject: [PATCH 23/27] updated readme --- fail-alert.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fail-alert.md b/fail-alert.md index 1d9d79e..b1f4832 100644 --- a/fail-alert.md +++ b/fail-alert.md @@ -2,12 +2,17 @@ Sends a slack alert when a job fails -1. Add a job that you want to monitor. +The alert contains the name of the repo, the workflow and the GitHub user who triggered the +workflow. + +Anyone who triggers workflows should add their GitHub username as a (keyword)[https://slack.com/help/articles/201355156-Configure-your-Slack-notifications#keyword-notifications] in Slack. + +1. Add any jobs that you want to monitor. 2. Add a new job. 3. It must `needs` any jobs you want to monitor. Needs can accept an array. -4. set `if: ${{ failure() }}` on the new job. +4. Set `if: ${{ failure() }}` on the new job. 5. Make the new job `uses: iStreamPlanet/github-actions/.github/workflows/fail-alert.yml@main` -6. fail-alert has no inputs, but does require a secrets.slack_webhook for whichever slack channel you want to message. +6. fail-alert has no inputs, but does require a `secrets.slack_webhook` for whichever slack channel you want to message. Here's an example workflow @@ -33,3 +38,10 @@ jobs: slack_webhook: ${{ secrets.DEPLOYMENTS_SLACK_WEBHOOK }} ``` +## Future Improvements + +* Get an org-wide webhook and call it from within fail-alert. Users wouldn't need to have one. +* Accept optional inputs to override values from github. E.G. workflow name, contact etc... +* Somehow map gh users to slack name and do a real @ + * Make an actual slack app that looks it up on a table or something + * Have users put thier slack @handle in gh profile and look that up somehow? From 90af40749590227a4ee860fb46e62813f24b76de Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Wed, 18 Dec 2024 17:11:26 -0800 Subject: [PATCH 24/27] rm unneded comments --- .github/workflows/fail-alert.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index ac4a8e6..e83bafe 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -1,9 +1,4 @@ # Simple failure notification reusable workflow -# -# Fast Follows -# -# * inputs we can override, eg workflow name, message, title, etc... -# * an org wide var with the slack webhook so no one has to specify it name: Failure Notification on: From 1ffb261e925aefc8177b2454aba40b3429a4de3a Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Thu, 19 Dec 2024 09:09:00 -0800 Subject: [PATCH 25/27] fix quotes around repo and workflow names --- .github/workflows/fail-alert.yml | 2 +- fail-alert.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index e83bafe..fa49fbd 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -46,7 +46,7 @@ jobs: "elements": [ { "type": "mrkdwn", - "text": "On ${{ github.repository }}\nworkflow '${{ github.workflow }} failed'\nTell ${{ github.triggering_actor }}.\nSee ${{ env.CI_BUILD_URL }}" + "text": "On '${{ github.repository }}'\nworkflow '${{ github.workflow }}' failed\nTell ${{ github.triggering_actor }}.\nSee ${{ env.CI_BUILD_URL }}" } ] } diff --git a/fail-alert.md b/fail-alert.md index b1f4832..937bd61 100644 --- a/fail-alert.md +++ b/fail-alert.md @@ -42,6 +42,7 @@ jobs: * Get an org-wide webhook and call it from within fail-alert. Users wouldn't need to have one. * Accept optional inputs to override values from github. E.G. workflow name, contact etc... +* Better slack message formatting with Block Kit. * Somehow map gh users to slack name and do a real @ * Make an actual slack app that looks it up on a table or something * Have users put thier slack @handle in gh profile and look that up somehow? From 90c8c25119cc192a9ee8b9fc7d92abc1a6197373 Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Thu, 19 Dec 2024 11:59:16 -0800 Subject: [PATCH 26/27] more formatting --- .github/workflows/fail-alert.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index fa49fbd..82324dd 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -42,13 +42,11 @@ jobs: } }, { - "type": "context", - "elements": [ - { - "type": "mrkdwn", - "text": "On '${{ github.repository }}'\nworkflow '${{ github.workflow }}' failed\nTell ${{ github.triggering_actor }}.\nSee ${{ env.CI_BUILD_URL }}" - } - ] + "type": "section", + "text": { + "type": "mrkdwn", + "text": "On '${{ github.repository }}'\nworkflow '${{ github.workflow }}' failed\nTell ${{ github.triggering_actor }}.\nSee ${{ env.CI_BUILD_URL }}" + } } ] } From dac1c4d7250f35c19edc21538c7ad1ec6867af1e Mon Sep 17 00:00:00 2001 From: Dylan Martin Date: Thu, 19 Dec 2024 12:03:18 -0800 Subject: [PATCH 27/27] derp de doo --- .github/workflows/fail-alert.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/fail-alert.yml b/.github/workflows/fail-alert.yml index 82324dd..a9c9d04 100644 --- a/.github/workflows/fail-alert.yml +++ b/.github/workflows/fail-alert.yml @@ -24,7 +24,6 @@ jobs: echo ${{ secrets.slack_webhook }} | tail -c 4 - name: Send Slack - if: false uses: slackapi/slack-github-action@v1.27.0 env: SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook }}