Skip to content

Commit

Permalink
chore(ci): notify via slack when a publishing workflow fails (#525)
Browse files Browse the repository at this point in the history
* 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
ArtieReus and andypf authored Oct 23, 2024
1 parent 24fec5c commit 79d3c8c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 52 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/build-push-greenhouse-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,8 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
# value is a template that will be evaluated at runtime
# this will generate a list of tags like:
# ghcr.io/cloudoperators/juno-app-greenhouse:0.2.1
# ghcr.io/cloudoperators/juno-app-greenhouse:latest
tags: |
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=${{ steps.read_version.outputs.IMAGE_VERSION }}
# Debugging step to print the tags
#- name: print tags
# run: |
# echo "${{ steps.meta.outputs.tags }}"
# exit 1
# Build and load to Docker
- name: Build and export to Docker ${{ steps.meta.outputs.tags }}
Expand Down Expand Up @@ -154,3 +145,13 @@ jobs:
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

notify-on-failure:
if: failure()
needs: [build-and-push-greenhouse-image]
uses: cloudoperators/juno/.github/workflows/shared-slack-notification.yaml@main
with:
title: "🚨 JUNO Greenhouse Image Failed 🚨"
body: "An error occurred while building the Greenhouse image 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 }}
12 changes: 11 additions & 1 deletion .github/workflows/build-push-supernova-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
org.opencontainers.image.title=Supernova UI
org.opencontainers.image.description="This image contains a standalone runnable version of the Supernova alternative Alertmanager UI. For configuration options see the README here: https://github.com/cloudoperators/juno/tree/main/apps/supernova/docker"
org.opencontainers.image.url="https://github.com/cloudoperators/juno/tree/main/apps/supernova"
org.opencontainers.image.source="https://github.com/cloudoperators/juno/tree/main/apps/supernova"
org.opencontainers.image.source="https://github.com/cloudoperators/juno/tree/main/apps/supernova"
org.opencontainers.image.documentation=https://github.com/cloudoperators/juno/tree/main/apps/supernova
# Build and push Docker image with Buildx (don't push on PR)
Expand Down Expand Up @@ -173,3 +173,13 @@ jobs:
if: always()
with:
sarif_file: trivy-results.sarif

notify-on-failure:
if: failure()
needs: [build-and-push, vulnerability-scan]
uses: cloudoperators/juno/.github/workflows/shared-slack-notification.yaml@main
with:
title: "🚨 JUNO Supernova Image Failed 🚨"
body: "An error occurred while building the Supernova image 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 }}
65 changes: 23 additions & 42 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
66 changes: 66 additions & 0 deletions .github/workflows/shared-slack-notification.yaml
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

0 comments on commit 79d3c8c

Please sign in to comment.