feat: add discord automated release notifications (#564)

This commit is contained in:
Zach
2026-04-22 17:27:39 -04:00
committed by Zach Yale
parent 9c3ecc58d4
commit e65536de1c
11 changed files with 938 additions and 59 deletions
@@ -0,0 +1,191 @@
name: Release - Notify Discord
on:
workflow_call:
inputs:
channel:
description: 'Target message channel context (for template selection)'
required: true
type: string
candidate_sha:
description: 'Resolved commit SHA for the candidate build'
required: true
type: string
base_tag:
description: 'Stable base tag that the candidate is built on top of'
required: false
default: ''
type: string
mention_text:
description: 'Optional role mentions or intro text to prepend to the message'
required: false
default: ''
type: string
current_version:
description: 'Current release/build identifier to display in the embed'
required: true
type: string
predicted_version:
description: 'Predicted next semantic version (without v-prefix)'
required: false
default: ''
type: string
compare_url:
description: 'GitHub compare URL between base stable tag and candidate SHA'
required: false
default: ''
type: string
details_url:
description: 'Canonical details link for the full markdown notes'
required: false
default: ''
type: string
image_tag:
description: 'Container image tag for this build'
required: false
default: ''
type: string
secrets:
discord_webhook:
description: 'Discord webhook URL for release notifications'
required: true
jobs:
notify:
name: Notify Discord
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Compose Message
id: compose
env:
CHANNEL: ${{ inputs.channel }}
CANDIDATE_SHA: ${{ inputs.candidate_sha }}
COMPARE_URL: ${{ inputs.compare_url }}
CURRENT_VERSION: ${{ inputs.current_version }}
DETAILS_URL: ${{ inputs.details_url }}
MENTION_TEXT: ${{ inputs.mention_text }}
PREDICTED_VERSION: ${{ inputs.predicted_version }}
run: |
set -eu
short_sha="$(printf '%s' "$CANDIDATE_SHA" | cut -c1-7)"
if [ "$CHANNEL" = "rc" ]; then
header="🧪 **A new release candidate has been announced**"
elif [ "$CHANNEL" = "stable" ]; then
header="🚀 **A new release is now available**"
else
header="🌙 **A new nightly build is now available**"
fi
if [ -n "$MENTION_TEXT" ]; then
content="${header} ${MENTION_TEXT}"
else
content="${header}"
fi
if [ -n "$DETAILS_URL" ]; then
title_url="$DETAILS_URL"
elif [ -n "$COMPARE_URL" ]; then
title_url="$COMPARE_URL"
else
title_url=""
fi
description="- Current Version: \`${CURRENT_VERSION}\`"
if [ "$CHANNEL" != "stable" ]; then
if [ -n "$PREDICTED_VERSION" ] && [ "$PREDICTED_VERSION" != "no-release" ]; then
predicted_release="v${PREDICTED_VERSION}"
else
predicted_release="no predicted release"
fi
description="${description}\n- Predicted Release: \`${predicted_release}\`"
fi
if [ -n "$COMPARE_URL" ]; then
description="${description}\n- Candidate SHA: \`${short_sha}\` ([compare](${COMPARE_URL}))"
else
description="${description}\n- Candidate SHA: \`${short_sha}\`"
fi
{
echo 'content<<EOF'
printf '%s\n' "$content"
echo 'EOF'
echo "title_url=${title_url}"
echo 'description<<EOF'
printf '%b\n' "$description"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Send Discord Webhook
env:
DISCORD_WEBHOOK: ${{ secrets.discord_webhook }}
CONTENT: ${{ steps.compose.outputs.content }}
DESCRIPTION: ${{ steps.compose.outputs.description }}
TITLE_URL: ${{ steps.compose.outputs.title_url }}
run: |
set -eu
payload="$(jq -n \
--arg content "$CONTENT" \
--arg description "$DESCRIPTION" \
--arg title_url "$TITLE_URL" \
'
{
content: $content,
embeds: [
{
title: "Build Details",
description: $description,
color: 5763719
}
]
}
+ (
if $title_url != "" then
{
components: [
{
type: 1,
components: [
{
type: 2,
style: 5,
label: "View Changelog",
url: $title_url
},
{
type: 2,
style: 5,
label: "Report Issue",
url: "https://github.com/orgs/grimmory-tools/discussions/new?category=issue-triage"
}
]
}
]
}
else
{
components: [
{
type: 1,
components: [
{
type: 2,
style: 5,
label: "Report Issue",
url: "https://github.com/orgs/grimmory-tools/discussions/new?category=issue-triage"
}
]
}
]
}
end
)
')"
curl --fail-with-body -sS -X POST "${DISCORD_WEBHOOK}?with_components=true" \
-H 'Content-Type: application/json' \
-d "$payload"
+111 -18
View File
@@ -4,40 +4,72 @@ on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
inputs:
publish_image:
description: 'Publish the nightly container image'
required: false
default: false
type: boolean
jobs:
resolve_ref:
name: Resolve Nightly Ref
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
outputs:
base_tag: ${{ steps.resolve.outputs.base_tag }}
commit_sha: ${{ steps.resolve.outputs.commit_sha }}
from_ref: ${{ steps.resolve.outputs.from_ref }}
nightly_tag: ${{ steps.resolve.outputs.nightly_tag }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
fetch-depth: 0
ref: develop
- name: Record Resolved Commit
id: resolve
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
set -eu
test-suite:
name: Test Suite
needs: [resolve_ref]
uses: ./.github/workflows/test-suite.yml
permissions:
contents: read
checks: write
with:
checkout_ref: ${{ needs.resolve_ref.outputs.commit_sha }}
save_gradle_cache: true
git fetch origin main --tags --force
short_sha="$(git rev-parse --short HEAD)"
build_date="$(date -u +%Y%m%d)"
nightly_tag="nightly-${build_date}-${short_sha}"
base_tag="$(git describe --tags --abbrev=0 --match 'v*' origin/main)"
from_ref="$base_tag"
previous_nightly_sha=""
if previous_nightly_json="$(
gh api "/repos/${GITHUB_REPOSITORY}/actions/workflows/publish-nightly.yml/runs?branch=develop&event=schedule&status=success&per_page=1"
)"; then
previous_nightly_sha="$(printf '%s' "$previous_nightly_json" | jq -r '.workflow_runs[0].head_sha // ""')"
else
echo "::warning::Unable to resolve previous nightly run; using ${base_tag}"
fi
if [ -n "$previous_nightly_sha" ] \
&& git rev-parse --verify --quiet "${previous_nightly_sha}^{commit}" >/dev/null \
&& git merge-base --is-ancestor "$previous_nightly_sha" HEAD; then
from_ref="$previous_nightly_sha"
elif [ -n "$previous_nightly_sha" ]; then
echo "::warning::Ignoring unusable nightly baseline ${previous_nightly_sha}; using ${base_tag}"
fi
echo "base_tag=${base_tag}" >> "$GITHUB_OUTPUT"
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "from_ref=${from_ref}" >> "$GITHUB_OUTPUT"
echo "nightly_tag=${nightly_tag}" >> "$GITHUB_OUTPUT"
build-and-push:
name: Build and Push Nightly Image
if: ${{ github.event_name == 'schedule' || inputs.publish_image }}
needs: [resolve_ref, test-suite]
runs-on: ubuntu-latest
@@ -45,6 +77,9 @@ jobs:
contents: read
packages: write
outputs:
image_tag: ${{ steps.record.outputs.image_tag }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -52,14 +87,13 @@ jobs:
fetch-depth: 1
ref: ${{ needs.resolve_ref.outputs.commit_sha }}
- name: Generate Nightly Tag
- name: Record Nightly Build Metadata
id: record
run: |
short_sha=$(git rev-parse --short HEAD)
build_date=$(date -u +%Y%m%d)
nightly_tag="nightly-${build_date}-${short_sha}"
echo "nightly_tag=$nightly_tag" >> "$GITHUB_ENV"
echo "image_tag=${{ needs.resolve_ref.outputs.nightly_tag }}" >> "$GITHUB_OUTPUT"
echo "nightly_tag=${{ needs.resolve_ref.outputs.nightly_tag }}" >> "$GITHUB_ENV"
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
echo "Nightly tag: $nightly_tag"
echo "Nightly tag: ${{ needs.resolve_ref.outputs.nightly_tag }}"
- name: Set Up QEMU for Multi-Arch Builds
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
@@ -103,3 +137,62 @@ jobs:
cache-to: |
type=gha,scope=image-shared,mode=max
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
generate-notes:
name: Nightly Changelog
if: ${{ always() && needs.test-suite.result == 'success' }}
needs: [resolve_ref, test-suite]
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
compare_url: ${{ steps.notes.outputs.compare_url }}
details_url: ${{ steps.notes.outputs.details_url }}
predicted_version: ${{ steps.notes.outputs.predicted_version }}
release_notes: ${{ steps.notes.outputs.release_notes }}
release_type: ${{ steps.notes.outputs.release_type }}
released: ${{ steps.notes.outputs.released }}
to_sha: ${{ steps.notes.outputs.to_sha }}
steps:
- name: Checkout Workflow Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- name: Build Full Changelog
id: notes
uses: ./.github/actions/compute-release-notes
with:
base_tag: ${{ needs.resolve_ref.outputs.base_tag }}
from_ref: ${{ needs.resolve_ref.outputs.from_ref }}
repository_url: ${{ format('{0}/{1}', github.server_url, github.repository) }}
to_ref: ${{ needs.resolve_ref.outputs.commit_sha }}
notify-discord:
name: Notify Discord (Nightly)
if: ${{ always() && needs.generate-notes.result == 'success' && (needs.build-and-push.result == 'success' || needs.build-and-push.result == 'skipped') }}
needs: [resolve_ref, build-and-push, generate-notes]
permissions: {}
uses: ./.github/workflows/notify-discord-release-notes.yml
secrets:
discord_webhook: ${{ secrets.DISCORD_NIGHTLY_WEBHOOK != '' && secrets.DISCORD_NIGHTLY_WEBHOOK || secrets.DISCORD_RELEASE_WEBHOOK }}
with:
channel: nightly
candidate_sha: ${{ needs.resolve_ref.outputs.commit_sha }}
base_tag: ${{ needs.resolve_ref.outputs.base_tag }}
current_version: ${{ needs.resolve_ref.outputs.nightly_tag }}
details_url: ${{ needs.generate-notes.outputs.details_url }}
compare_url: ${{ needs.generate-notes.outputs.compare_url }}
mention_text: ${{ vars.DISCORD_NIGHTLY_MENTIONS }}
predicted_version: ${{ needs.generate-notes.outputs.predicted_version }}
test-suite:
name: Test Suite
needs: [resolve_ref]
uses: ./.github/workflows/test-suite.yml
permissions:
contents: read
checks: write
with:
checkout_ref: ${{ needs.resolve_ref.outputs.commit_sha }}
save_gradle_cache: true
+113
View File
@@ -0,0 +1,113 @@
name: Release - Candidate
on:
workflow_dispatch:
inputs:
candidate_ref:
description: 'Branch, tag, or commit SHA to build as a release candidate'
required: false
default: develop
type: string
concurrency:
group: release-candidate
cancel-in-progress: false
jobs:
resolve_ref:
name: Resolve Candidate Ref
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
outputs:
candidate_sha: ${{ steps.resolve.outputs.candidate_sha }}
base_tag: ${{ steps.resolve.outputs.base_tag }}
current_version: ${{ steps.resolve.outputs.current_version }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
ref: ${{ inputs.candidate_ref }}
- name: Resolve Candidate Metadata
id: resolve
env:
GH_TOKEN: ${{ github.token }}
run: |
set -eu
git fetch origin main --tags --force
if ! git merge-base --is-ancestor origin/main HEAD; then
echo "Selected ref does not contain origin/main and cannot be promoted cleanly to main" >&2
exit 1
fi
candidate_sha="$(git rev-parse HEAD)"
base_tag="$(git describe --tags --abbrev=0 --match 'v*' origin/main)"
latest_nightly_json="$(
gh api "/repos/${GITHUB_REPOSITORY}/actions/workflows/publish-nightly.yml/runs?branch=develop&status=success&per_page=1"
)"
latest_nightly_sha="$(printf '%s' "$latest_nightly_json" | jq -r '.workflow_runs[0].head_sha // ""')"
latest_nightly_created_at="$(printf '%s' "$latest_nightly_json" | jq -r '.workflow_runs[0].created_at // ""')"
current_version="$base_tag"
if [ -n "$latest_nightly_sha" ] && [ -n "$latest_nightly_created_at" ]; then
latest_nightly_date="$(date -u -d "$latest_nightly_created_at" +%Y%m%d)"
latest_nightly_short_sha="$(printf '%s' "$latest_nightly_sha" | cut -c1-7)"
current_version="nightly-${latest_nightly_date}-${latest_nightly_short_sha}"
fi
echo "candidate_sha=${candidate_sha}" >> "$GITHUB_OUTPUT"
echo "base_tag=${base_tag}" >> "$GITHUB_OUTPUT"
echo "current_version=${current_version}" >> "$GITHUB_OUTPUT"
generate-notes:
name: Release Candidate Changelog
needs: [resolve_ref]
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
compare_url: ${{ steps.notes.outputs.compare_url }}
details_url: ${{ steps.notes.outputs.details_url }}
predicted_version: ${{ steps.notes.outputs.predicted_version }}
release_notes: ${{ steps.notes.outputs.release_notes }}
release_type: ${{ steps.notes.outputs.release_type }}
released: ${{ steps.notes.outputs.released }}
to_sha: ${{ steps.notes.outputs.to_sha }}
steps:
- name: Checkout Workflow Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- name: Build Full Changelog
id: notes
uses: ./.github/actions/compute-release-notes
with:
base_tag: ${{ needs.resolve_ref.outputs.base_tag }}
from_ref: ${{ needs.resolve_ref.outputs.base_tag }}
repository_url: ${{ format('{0}/{1}', github.server_url, github.repository) }}
to_ref: ${{ needs.resolve_ref.outputs.candidate_sha }}
notify-discord:
name: Notify Discord (RC)
if: ${{ always() && needs.generate-notes.result == 'success' }}
needs: [resolve_ref, generate-notes]
permissions: {}
uses: ./.github/workflows/notify-discord-release-notes.yml
secrets:
discord_webhook: ${{ secrets.DISCORD_RC_WEBHOOK != '' && secrets.DISCORD_RC_WEBHOOK || secrets.DISCORD_RELEASE_WEBHOOK }}
with:
channel: rc
candidate_sha: ${{ needs.resolve_ref.outputs.candidate_sha }}
base_tag: ${{ needs.resolve_ref.outputs.base_tag }}
current_version: ${{ needs.resolve_ref.outputs.current_version }}
details_url: ${{ needs.generate-notes.outputs.details_url }}
predicted_version: ${{ needs.generate-notes.outputs.predicted_version }}
compare_url: ${{ needs.generate-notes.outputs.compare_url }}
mention_text: ${{ vars.DISCORD_RC_MENTIONS }}
+65
View File
@@ -131,6 +131,71 @@ jobs:
release_tag: ${{ needs.semantic-release.outputs.release_tag }}
commit_sha: ${{ needs.semantic-release.outputs.release_sha }}
prepare-release-notification:
name: Prepare Stable Release Notification
if: ${{ needs.semantic-release.outputs.released == 'true' && needs.publish-release.result == 'success' }}
needs: [semantic-release, publish-release]
runs-on: ubuntu-latest
outputs:
base_tag: ${{ steps.metadata.outputs.base_tag }}
compare_url: ${{ steps.metadata.outputs.compare_url }}
release_url: ${{ steps.metadata.outputs.release_url }}
release_version: ${{ steps.metadata.outputs.release_version }}
permissions:
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
ref: ${{ needs.semantic-release.outputs.release_sha }}
- name: Extract Stable Release Metadata
id: metadata
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN != '' && secrets.RELEASE_BOT_TOKEN || github.token }}
RELEASE_TAG: ${{ needs.semantic-release.outputs.release_tag }}
run: |
set -eu
git fetch origin main --tags --force
release_json="$(gh release view "$RELEASE_TAG" --json body,url)"
release_version="${RELEASE_TAG#v}"
base_tag="$(git tag --sort=-version:refname 'v*' | grep -Fxv "$RELEASE_TAG" | head -n 1 || true)"
compare_url=""
release_url="$(printf '%s' "$release_json" | jq -r '.url')"
if [ -n "$base_tag" ]; then
compare_url="https://github.com/${GITHUB_REPOSITORY}/compare/${base_tag}...${RELEASE_TAG}"
fi
{
echo "base_tag=${base_tag}"
echo "compare_url=${compare_url}"
echo "release_url=${release_url}"
echo "release_version=${release_version}"
} >> "$GITHUB_OUTPUT"
notify-discord:
name: Notify Discord (Stable)
if: ${{ needs.semantic-release.outputs.released == 'true' && needs.publish-release.result == 'success' && needs.prepare-release-notification.result == 'success' }}
needs: [semantic-release, publish-release, prepare-release-notification]
permissions: {}
uses: ./.github/workflows/notify-discord-release-notes.yml
secrets:
discord_webhook: ${{ secrets.DISCORD_STABLE_WEBHOOK != '' && secrets.DISCORD_STABLE_WEBHOOK || secrets.DISCORD_RELEASE_WEBHOOK }}
with:
channel: stable
candidate_sha: ${{ needs.semantic-release.outputs.release_sha }}
base_tag: ${{ needs.prepare-release-notification.outputs.base_tag }}
current_version: ${{ needs.semantic-release.outputs.release_tag }}
details_url: ${{ needs.prepare-release-notification.outputs.release_url }}
compare_url: ${{ needs.prepare-release-notification.outputs.compare_url }}
mention_text: ${{ vars.DISCORD_STABLE_MENTIONS }}
predicted_version: ${{ needs.prepare-release-notification.outputs.release_version }}
backport-release:
name: Backport Release Commit to Develop
if: ${{ needs.semantic-release.outputs.released == 'true' && needs.publish-release.result == 'success' }}