terraform-provider-stackitp.../.github/actions/notify/action.yaml
Marcel_Henselin 7b2dfaea44
chore: refactor pipelines (#97)
## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #97
2026-03-27 15:23:30 +00:00

149 lines
4.4 KiB
YAML

name: Send notification via Google Chat
description: "Sends a notification to a Google Chat room when a pull request is opened."
inputs:
webhook_url:
description: "The URL of the Google Chat webhook."
required: true
title:
description: "The title of the notification."
required: true
subtitle:
description: "The subtitle of the notification."
default: 'no subtitle provided'
image_slug:
description: "The slug of the image to be included in the notification."
default: 'git'
event_author:
description: "The author of the event."
default: 'unknown'
event_title:
description: "The title of the event."
required: true
event_body:
description: "The body of the event."
default: 'no body provided'
event_number:
description: "The number of the event."
default: 'no number provided'
event_url:
description: "The url of the event."
default: 'none'
status:
description: "The status of the event."
default: 'UNKNOWN'
runs:
using: "composite"
steps:
- name: Install prerequisites
shell: bash
run: |
echo "::group::apt install"
set -e
apt update
apt install -y curl jq
echo "::endgroup::"
- name: Determine status color
id: status
shell: bash
run: |
case "${{ inputs.status }}" in
SUCCESS)
STATUS_COLOR="006400/228b22"
ADD='{"decoratedText": {"startIcon": {"materialIcon": {"name": "check_circle"}},"text": "<b style=\"color: green;\">SUCCESS</b>"}},'
;;
FAILURE)
STATUS_COLOR="8b0000/dc143c"
ADD='{"decoratedText": {"startIcon": {"materialIcon": {"name": "stop_circle"}},"text": "<b style=\"color: red;\">FAILURE</b>"}},'
;;
*)
STATUS_COLOR="483d8b/6495ed"
ADD=''
;;
esac
echo "color=${STATUS_COLOR}" >> "$GITHUB_OUTPUT"
echo "status_add=${ADD}" >> "$GITHUB_OUTPUT"
- name: Notify via Google Chat Webhook
shell: bash
env:
WEBHOOK: ${{ inputs.webhook_url }}
run: |
set -e
PAYLOAD=$(jq -n -r \
--arg header "${{ inputs.title }}" \
--arg subtitle "${{ inputs.subtitle }}" \
--arg imgurl "https://cdn.simpleicons.org/${{ inputs.image_slug }}/${{ steps.status.outputs.color }}" \
--arg title "${{ inputs.event_title || 'no event title given' }}" \
--arg body "${{ inputs.event_body || 'no event body given' }}" \
--arg author "${{ inputs.event_author || 'no event author given' }}" \
--arg url "${{ inputs.event_url || github.repositoryUrl || github.server_url }}" \
'{ "cardsV2": [ { "cardId": "notify-${{ github.run_id }}", "card": {
"header": {
"title": "\($header)",
"subtitle": "\($subtitle)",
"imageUrl": "\($imgurl)",
"imageType": "SQUARE"
},
"sections": [
{
"header": "\($title)",
"collapsible": false,
"widgets": [
${{ steps.status.outputs.status_add }}
{
"decoratedText": {
"startIcon": {
"knownIcon": "PERSON"
},
"text": "<b>\($author)</b>"
}
},
{
"textParagraph": {
"text": "\($body)",
"maxLines": 2
}
}
]
},
{
"widgets": [
{
"buttonList": {
"buttons": [
{
"text": "View Source Event",
"type": "FILLED",
"onClick": {
"openLink": {
"url": "\($url)"
}
}
}
]
}
}
]
}
]
}} ] }')
curl \
--fail-with-body \
-X POST \
-H 'Content-Type: application/json' \
"${{ inputs.webhook_url }}" \
-d "${PAYLOAD}"