Files
raea/.github/workflows/discord.yml

45 lines
2.2 KiB
YAML

# Posts every published release to #releases in the raea Discord. Engine releases (v* tags) ping the "release pings"
# role that members pick in onboarding. Other releases, such as the web modules, post without a ping.
# Needs the repository secret DISCORD_RELEASES_WEBHOOK (the #releases webhook) and the variable DISCORD_RELEASE_ROLE
# (that role's id). Without the secret it skips.
name: discord
on:
release:
types: [published]
permissions: {}
jobs:
announce:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Post the release to #releases
env:
WEBHOOK: ${{ secrets.DISCORD_RELEASES_WEBHOOK }}
ROLE: ${{ vars.DISCORD_RELEASE_ROLE }}
TAG: ${{ github.event.release.tag_name }}
NAME: ${{ github.event.release.name }}
URL: ${{ github.event.release.html_url }}
BODY: ${{ github.event.release.body }}
PRE: ${{ github.event.release.prerelease }}
run: |
[ -n "$WEBHOOK" ] || { echo "no DISCORD_RELEASES_WEBHOOK secret, so nothing to post"; exit 0; }
ping=""
if [[ $TAG == v* && -n $ROLE ]]; then ping="<@&$ROLE> "; fi
kind="release"; [[ $PRE == true ]] && kind="pre-release"
install=""
if [[ $TAG == v* ]]; then install=$'\n\nInstall or update: `curl -fsSL https://raea.io/install | sh` (macOS, Linux), or `irm https://raea.io/install.ps1 | iex` (Windows).'; fi
notes="$BODY"
if (( ${#notes} > 3500 )); then notes="${notes:0:3500}"$'…\n\nThe full notes are on GitHub.'; fi
payload=$(jq -n --arg ping "$ping" --arg tag "$TAG" --arg name "${NAME:-$TAG}" --arg url "$URL" \
--arg notes "$notes$install" --arg kind "$kind" --arg role "$ROLE" '{
content: "\($ping)raea \($tag) is out (\($kind)).",
allowed_mentions: { roles: (if $ping == "" then [] else [$role] end) },
embeds: [{ title: $name, url: $url, description: $notes, color: 16053488,
footer: { text: "github.com/shinyobjectz/raea" } }]
}')
curl -fsS -H "Content-Type: application/json" -d "$payload" "$WEBHOOK?wait=true" -o /dev/null
echo "posted $TAG"