Skip to content

Commit

Permalink
github-actions: Add gchat notification (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Ruiz <[email protected]>
  • Loading branch information
migruiz4 authored Feb 10, 2025
1 parent a0089ba commit f582608
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/gchat-notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

name: 'GChat Notification'
on:
workflow_call:
inputs:
workflow:
type: string
required: true
job-url:
type: string
required: true
repository:
type: string
secrets:
webhook-url:
required: true
# Remove all permissions by default
permissions: {}
jobs:
notification:
name: Google Chat Notification
runs-on: ubuntu-latest
steps:
- name: Notify
env:
JOB_URL: ${{ inputs.job-url }}
GH_WORKFLOW: ${{ inputs.workflow }}
GH_REPOSITORY: ${{ inputs.repository != '' && inputs.repository || github.repository }}
WEBHOOK_URL: ${{ secrets.webhook-url }}
run: |
tmp_file=$(mktemp)
cat >"${tmp_file}"<<EOF
⚠️ [${GH_REPOSITORY}] Failure detected on '${GH_WORKFLOW}' workflow ⚠️
📑 See details <${JOB_URL}|here>.
EOF
# Use curl to send the JSON to Google.
escapedText=$(sed -e 's/\n/\\n/g' -e 's/"/\\"/g' -e "s/'/\\'/g" "${tmp_file}")
json="{\"text\": \"$escapedText\"}"
curl -o /tmp/out -s --fail -X POST -H 'Content-Type: application/json' -d "$json" "${WEBHOOK_URL}"

0 comments on commit f582608

Please sign in to comment.