Files
charts/.github/workflows/gchat-notification.yml
2025-01-16 11:55:42 +01:00

43 lines
1.3 KiB
YAML

# 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:
GCHAT_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 }}
GCHAT_WEBHOOK_URL: ${{ secrets.GCHAT_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" "${GCHAT_WEBHOOK_URL}"