name: Announce release on Discord on: release: types: [published] workflow_dispatch: inputs: tag: description: Release tag to announce required: true type: string permissions: contents: read jobs: announce: runs-on: ubuntu-latest steps: - name: Send Discord announcement env: DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} RELEASE_TAG_INPUT: ${{ inputs.tag }} REPO: ${{ github.repository }} GH_TOKEN: ${{ github.token }} run: | test -n "$DISCORD_WEBHOOK_URL" if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then test -n "$RELEASE_TAG_INPUT" curl --fail-with-body \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GH_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "$GITHUB_API_URL/repos/$REPO/releases/tags/$RELEASE_TAG_INPUT" \ > release.json else jq '.release' "$GITHUB_EVENT_PATH" > release.json fi if [ "$(jq -r '.prerelease' release.json)" = "true" ]; then echo "Skipping prerelease." exit 0 fi jq -n \ --arg repo "$REPO" \ --arg name "$(jq -r '.name // ""' release.json)" \ --arg tag "$(jq -r '.tag_name' release.json)" \ --arg url "$(jq -r '.html_url' release.json)" \ --arg body "$(jq -r '.body // ""' release.json)" \ '($body | if length > 1500 then .[:1500] + "...\n\n[Read more](" + $url + ")" else . end) as $description | { username: "Basecoat Releases", allowed_mentions: { parse: [] }, embeds: [{ title: ($repo + " " + $tag), url: $url, description: ((if $name != "" then "**" + $name + "**\n\n" else "" end) + $description), color: 5793266 }] }' > payload.json curl --fail-with-body \ --retry 3 \ --retry-all-errors \ --retry-delay 2 \ -H "Content-Type: application/json" \ -X POST \ -d @payload.json \ "$DISCORD_WEBHOOK_URL"