|
| 1 | +name: Announce Releases on Discord |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: "Published release tag" |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + secrets: |
| 11 | + DISCORD_ANNOUNCEMENTS_WEBHOOK_URL: |
| 12 | + required: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + announce: |
| 19 | + # Disable the native GitHub release webhook before enabling this repository variable. |
| 20 | + if: github.repository == 'vectordotdev/vector' && vars.DISCORD_RELEASES_ENABLED == 'true' |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + timeout-minutes: 5 |
| 23 | + continue-on-error: true |
| 24 | + steps: |
| 25 | + - name: Read published release |
| 26 | + env: |
| 27 | + GH_TOKEN: ${{ github.token }} |
| 28 | + RELEASE_TAG: ${{ inputs.tag }} |
| 29 | + run: | |
| 30 | + encoded_tag=$(jq -rn --arg tag "$RELEASE_TAG" '$tag | @uri') |
| 31 | + gh api "repos/$GITHUB_REPOSITORY/releases/tags/$encoded_tag" > "$RUNNER_TEMP/release.json" |
| 32 | + jq -e --arg tag "$RELEASE_TAG" ' |
| 33 | + .tag_name == $tag and .draft == false and .published_at != null |
| 34 | + ' "$RUNNER_TEMP/release.json" > /dev/null |
| 35 | +
|
| 36 | + - name: Post release to Discord |
| 37 | + env: |
| 38 | + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCEMENTS_WEBHOOK_URL }} |
| 39 | + run: | |
| 40 | + if [ -z "$DISCORD_WEBHOOK_URL" ]; then |
| 41 | + echo "::error::DISCORD_ANNOUNCEMENTS_WEBHOOK_URL is not configured" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + # Bound the payload size even when every character uses four UTF-8 bytes. |
| 46 | + jq '{ |
| 47 | + username: "Vector Releases", |
| 48 | + allowed_mentions: {parse: []}, |
| 49 | + embeds: [{ |
| 50 | + title: (("Vector " + .tag_name)[:128]), |
| 51 | + url: .html_url, |
| 52 | + description: ((.body // "") | |
| 53 | + if length > 1000 then .[:1000] + "…" else . end), |
| 54 | + footer: {text: (if .prerelease or (.tag_name | split("+")[0] | contains("-")) then "Pre-release" else "Release" end)} |
| 55 | + }] |
| 56 | + }' "$RUNNER_TEMP/release.json" > "$RUNNER_TEMP/discord-release.json" |
| 57 | +
|
| 58 | + curl --fail --silent --show-error \ |
| 59 | + --connect-timeout 10 --max-time 30 \ |
| 60 | + --header 'Content-Type: application/json' \ |
| 61 | + --data-binary "@$RUNNER_TEMP/discord-release.json" \ |
| 62 | + --output /dev/null \ |
| 63 | + "${DISCORD_WEBHOOK_URL}?wait=true" |
| 64 | +
|
| 65 | + - name: Report notification failure |
| 66 | + if: failure() |
| 67 | + run: echo "::warning::Discord release notification failed; release publishing can continue." |
0 commit comments