This commit is contained in:
techartdev
2026-02-25 16:15:43 +02:00
parent 0f5357e7c7
commit 7bd4f45538
+56 -56
View File
@@ -1,68 +1,68 @@
name: Announce release to Discord name: Announce release to Discord
on: on:
release: release:
types: [published] types: [published]
permissions: permissions:
contents: read contents: read
jobs: jobs:
notify-discord: notify-discord:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Post release announcement to Discord - name: Post release announcement to Discord
env: env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
RELEASE_NAME: ${{ github.event.release.name }} RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_TAG: ${{ github.event.release.tag_name }} RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_URL: ${{ github.event.release.html_url }} RELEASE_URL: ${{ github.event.release.html_url }}
RELEASE_BODY: ${{ github.event.release.body }} RELEASE_BODY: ${{ github.event.release.body }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: | run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL is not configured; skipping." echo "DISCORD_WEBHOOK_URL is not configured; skipping."
exit 0 exit 0
fi fi
if [ -n "$RELEASE_NAME" ]; then if [ -n "$RELEASE_NAME" ]; then
TITLE="$RELEASE_NAME" TITLE="$RELEASE_NAME"
else else
TITLE="$RELEASE_TAG" TITLE="$RELEASE_TAG"
fi fi
BODY_CLEAN=$(printf '%s' "$RELEASE_BODY" | sed 's/\r//g') BODY_CLEAN=$(printf '%s' "$RELEASE_BODY" | sed 's/\r//g')
BODY_TRIM=$(printf '%s' "$BODY_CLEAN" | sed '/^[[:space:]]*$/d') BODY_TRIM=$(printf '%s' "$BODY_CLEAN" | sed '/^[[:space:]]*$/d')
if [ -n "$BODY_TRIM" ]; then if [ -n "$BODY_TRIM" ]; then
SUMMARY=$(printf '%s' "$BODY_TRIM" | head -c 1400) SUMMARY=$(printf '%s' "$BODY_TRIM" | head -c 1400)
else else
SUMMARY="No release notes provided." SUMMARY="No release notes provided."
fi fi
PAYLOAD=$(jq -n \ PAYLOAD=$(jq -n \
--arg title "🚀 New release published: $TITLE" \ --arg title "🚀 New release published: $TITLE" \
--arg repo "$REPO" \ --arg repo "$REPO" \
--arg tag "$RELEASE_TAG" \ --arg tag "$RELEASE_TAG" \
--arg url "$RELEASE_URL" \ --arg url "$RELEASE_URL" \
--arg summary "$SUMMARY" \ --arg summary "$SUMMARY" \
'{ '{
content: "", content: "",
embeds: [ embeds: [
{ {
title: $title, title: $title,
url: $url, url: $url,
color: 5814783, color: 5814783,
fields: [ fields: [
{name: "Repository", value: $repo, inline: true}, {name: "Repository", value: $repo, inline: true},
{name: "Tag", value: $tag, inline: true}, {name: "Tag", value: $tag, inline: true},
{name: "Release URL", value: $url, inline: false}, {name: "Release URL", value: $url, inline: false},
{name: "Release notes", value: $summary, inline: false} {name: "Release notes", value: $summary, inline: false}
] ]
} }
] ]
}') }')
curl -sS -X POST "$DISCORD_WEBHOOK_URL" \ curl -sS -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$PAYLOAD" -d "$PAYLOAD"