Skip to content

Commit

Permalink
feat: Adding release announcement workflow (#3419)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhakbar authored Sep 19, 2024
1 parent 2593c5e commit 2a0eddc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/announce-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -euo pipefail

URL="${URL:?Required environment variable URL}"
REPO="${REPO:?Required environment variable REPO}"
TAG_NAME="${TAG_NAME:?Required environment variable TAG_NAME}"
ROLE_ID="${ROLE_ID:?Required environment variable ROLE_ID}"
USERNAME="${USERNAME:?Required environment variable USERNAME}"
AVATAR_URL="${AVATAR_URL:?Required environment variable AVATAR_URL}"

if RELEASE_JSON=$(gh -R "$REPO" release view "$TAG_NAME" --json body --json url --json name); then
RELEASE_NOTES=$(jq '.body' <<<"$RELEASE_JSON")

PAYLOAD=$(
jq \
--argjson release_notes "$RELEASE_NOTES" \
--arg username "$USERNAME" \
--arg avatar_url "$AVATAR_URL" \
-cn '{"content": $release_notes, username: $username, avatar_url: $avatar_url, "flags": 4}'
)

tmpfile=$(mktemp)
jq '.content = "'"<@&$ROLE_ID> $(jq -r '.name' <<<"$RELEASE_JSON")\n"'>>> " + .content + "'"\n\n**[View release on GitHub]($(jq -r '.url' <<<"$RELEASE_JSON"))**"'"' <<<"$PAYLOAD" >"$tmpfile"

curl -X POST \
--data-binary "@$tmpfile" \
-H "Content-Type: application/json" \
"$URL"
fi
22 changes: 22 additions & 0 deletions .github/workflows/announce-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Announce Release
on:
release:
# This is intentionally not `published` to avoid announcing pre-releases
types: [released]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Announce Release
run: ./.github/scripts/announce-release.sh
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
TAG_NAME: ${{ github.event.release.tag_name }}
URL: ${{ secrets.RELEASE_ANNOUNCEMENT_URL }}
ROLE_ID: ${{ secrets.RELEASE_ANNOUNCEMENT_ROLE_ID }}
USERNAME: ${{ secrets.RELEASE_ANNOUNCEMENT_USERNAME }}
AVATAR_URL: ${{ secrets.RELEASE_ANNOUNCEMENT_AVATAR_URL }}

0 comments on commit 2a0eddc

Please sign in to comment.