diff --git a/.github/actions/notify/action.yaml b/.github/actions/notify/action.yaml new file mode 100644 index 00000000..2a248c7e --- /dev/null +++ b/.github/actions/notify/action.yaml @@ -0,0 +1,106 @@ +name: Send pull request notification to Google Chat +description: | + Sends a notification to a Google Chat room when a pull request is opened. + +inputs: + title: + description: "The title of the notification." + required: true + default: 'no title provided' + + event_author: + description: "The author of the event." + required: true + default: 'unknown' + + event_title: + description: "The title of the event." + required: true + + event_body: + description: "The body of the event." + required: true + default: 'no body provided' + + event_number: + description: "The number of the event." + required: true + default: 'no number provided' + + event_url: + description: "The url of the event." + required: true + default: 'none' + + +runs: + using: "composite" + steps: + - name: Install prerequisites + shell: bash + run: apk add --no-cache curl jq + + - name: Send PR notification to Google Chat + shell: bash + run: | + set -e + + PAYLOAD=$(jq -n \ + --arg repo "${{ github.repository }}" \ + --arg title "${{ inputs.event_title }}" \ + --arg body "${{ inputs.event_body }}" \ + --arg author "${{ inputs.event_author }}" \ + --arg url "${{ inputs.event_url }}" \ + '{ + "header": { + "title": "${{ inputs.title }}", + "subtitle": "Repo: \($repo)", + "imageUrl": "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/git.png", + "imageType": "SQUARE" + }, + "sections": [ + { + "header": $title, + "collapsible": false, + "widgets": [ + { + "decoratedText": { + "icon": { + "knownIcon": "PERSON" + }, + "text": "Opened by: \($author)" + } + }, + { + "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' \ + "${{ secrets.GOOGLE_WEBHOOK_URL }}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=${REPO}/pr/${PR_NUMBER}" \ + -d "$(jq -n --argjson card "$PAYLOAD" '{ "cardsV2": [ { "cardId": "new-pr", "card": $card } ] }')" diff --git a/.github/workflows/notify_pr.yaml b/.github/workflows/notify_pr.yaml new file mode 100644 index 00000000..b80286f5 --- /dev/null +++ b/.github/workflows/notify_pr.yaml @@ -0,0 +1,22 @@ +name: Notify Google Chat on new PR + +on: + pull_request: + types: + - opened + +jobs: + notify-pr-google-chat: + runs-on: docker + container: + image: alpine:latest + steps: + - name: Notify + uses: ./.github/actions/notify + with: + title: New Pull Request + event_title: ${{ github.event.pull_request.title }} + event_author: ${{ github.event.pull_request.user.login }} + event_body: ${{ github.event.pull_request.body || 'No description provided.' }} + event_number: ${{ github.event.pull_request.number }} + event_url: ${{ github.event.pull_request.html_url }} diff --git a/.github/workflows/tf-acc-test.yaml b/.github/workflows/tf-acc-test.yaml index 473ad815..b38997cb 100644 --- a/.github/workflows/tf-acc-test.yaml +++ b/.github/workflows/tf-acc-test.yaml @@ -27,6 +27,16 @@ jobs: name: Acceptance Tests runs-on: stackit-docker steps: + - name: Notify + uses: ./.github/actions/notify + with: + title: Terraform Acceptance Tests started + event_title: ${{ github.event.type }} + event_author: ${{ github.event.actor.login }} + event_body: 'No event body.' + event_number: ${{ github.event.id }} + event_url: "${{ github.repositoryUrl }}" + - name: Checkout uses: actions/checkout@v6 @@ -59,3 +69,13 @@ jobs: tf_acc_kek_key_ring_id: ${{ vars.TF_ACC_KEK_KEY_RING_ID }} tf_acc_kek_key_version: ${{ vars.TF_ACC_KEK_KEY_VERSION }} tf_acc_kek_service_account: ${{ vars.TF_ACC_KEK_SERVICE_ACCOUNT }} + + - name: Notify + uses: ./.github/actions/notify + with: + title: Terraform Acceptance Tests finished + event_title: ${{ github.event.type }} + event_author: ${{ github.event.actor.login }} + event_body: 'No event body.' + event_number: ${{ github.event.id }} + event_url: "${{ github.repositoryUrl }}"