generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): notify via slack when a publishing workflow fails (#525)
* chore(ci): uses shared notification if workflow job fails * chore(ci): adds pr for testing * chore(ci): changes to fully qualified url * chore(ci): makes use of the shared workflow correctly * chore(ci): passes webhook as input * chore(ci): reads webhook from input * chore(ci): passes the webhook as secret * chore(ci): adds mapping * chore(ci): sets secrets not within with statement * chore(ci): adds valid json * chore(ci): formats the body * chore(ci): formats the title * chore(ci): removes double JUNO on title * chore(ci): sets body rich per var * chore(ci): sets inline envs * chore(ci): sets playload in a new step * chore(ci): corrects envs json syntax * chore(ci): ensures the JSON output is compact and valid * chore(ci): adds tests with rich body * chore(ci): cleans up the call * chore(ci): adds branch to the shared task * chore(ci): removes test * chore(ci): tests reuse action in release * chore(ci): removes double quotes * chore(ci): adds test * chore(ci): adds test integration * chore(ci): adds last test * chore(ci): removes tests and setups release * chore(ci): fixes copy paste errors --------- Co-authored-by: Andreas Pfau <[email protected]>
- Loading branch information
Showing
4 changed files
with
110 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ jobs: | |
release: | ||
name: Release | ||
runs-on: [default] | ||
outputs: | ||
published: ${{ steps.changesets.outputs.published }} | ||
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
|
@@ -42,45 +45,23 @@ jobs: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Send a Slack notification if a publish happens | ||
if: steps.changesets.outputs.published == 'true' | ||
id: slack_notification | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "context", | ||
"elements": [ | ||
{ | ||
"type": "image", | ||
"image_url": "https://raw.githubusercontent.com/cloudoperators/juno/main/assets/logos/JUNO_logo_slack.png", | ||
"alt_text": "cloudoperators/juno" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "JUNO Packages Released Successfully! 🚀" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "rich_text", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_preformatted", | ||
"elements": [ | ||
{ | ||
"type": "text", | ||
"text": ${{ toJson(steps.changesets.outputs.publishedPackages) }} | ||
} | ||
], | ||
"border": 0 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | ||
notify-on-success: | ||
if: needs.release.outputs.published == 'true' | ||
needs: [release] # List the jobs that should complete successfully | ||
uses: cloudoperators/juno/.github/workflows/shared-slack-notification.yaml@artie-shared-slack | ||
with: | ||
title: "JUNO Packages Released Successfully! 🚀" | ||
body: ${{ needs.release.outputs.publishedPackages }} | ||
rich_body: true | ||
secrets: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
||
notify-on-failure: | ||
if: failure() | ||
needs: [release] | ||
uses: cloudoperators/juno/.github/workflows/shared-slack-notification.yaml@artie-shared-slack | ||
with: | ||
title: "🚨 JUNO Packages Release Failed 🚨" | ||
body: "An error occurred while releasing JUNO Packages for the branch ${{ github.head_ref || github.ref_name }}. Please check the logs for more information. <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Check the logs>" | ||
secrets: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Slack Notification | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
title: | ||
required: true | ||
type: string | ||
body: | ||
required: false | ||
type: string | ||
rich_body: | ||
required: false | ||
type: boolean | ||
default: false | ||
secrets: | ||
SLACK_WEBHOOK_URL: | ||
required: true | ||
|
||
jobs: | ||
notify: | ||
runs-on: [default] | ||
steps: | ||
- name: Set Slack Payload | ||
env: | ||
RICH_BODY: '{"type":"rich_text","elements":[{"type":"rich_text_preformatted","elements":[{"type":"text","text":${{ toJson(inputs.body) }}}],"border":0}]}' | ||
SECTION_BODY: '{"type":"section","text":{"type":"mrkdwn","text":${{ toJson(inputs.body) }}}}' | ||
run: | | ||
if [[ "${{ inputs.rich_body }}" == "true" ]]; then | ||
echo "SLACK_PAYLOAD=${RICH_BODY}" >> $GITHUB_ENV | ||
else | ||
echo "SLACK_PAYLOAD=${SECTION_BODY}" >> $GITHUB_ENV | ||
fi | ||
- name: Construct Full Slack Payload | ||
run: | | ||
echo "FULL_PAYLOAD=$(jq -c . <<EOF | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "context", | ||
"elements": [ | ||
{ | ||
"type": "image", | ||
"image_url": "https://raw.githubusercontent.com/cloudoperators/juno/main/assets/logos/JUNO_logo_slack.png", | ||
"alt_text": "cloudoperators/juno" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "${{ inputs.title }}" | ||
} | ||
] | ||
}, | ||
${{ env.SLACK_PAYLOAD }} | ||
] | ||
} | ||
EOF | ||
)" >> $GITHUB_ENV | ||
- name: Send a Slack notification if a publish happens | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: ${{ env.FULL_PAYLOAD }} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |