From 57157e0d1497eb5a7e9616b85697b5f9dcd742ce Mon Sep 17 00:00:00 2001 From: Constrat <56174894+Constrat@users.noreply.github.com> Date: Fri, 20 Mar 2026 23:05:14 +0100 Subject: [PATCH] ci: add discord release notification --- .../discord-release-notification.yml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/discord-release-notification.yml diff --git a/.github/workflows/discord-release-notification.yml b/.github/workflows/discord-release-notification.yml new file mode 100644 index 0000000000..436588c203 --- /dev/null +++ b/.github/workflows/discord-release-notification.yml @@ -0,0 +1,71 @@ +name: Discord Release Notification + +on: + release: + types: + - published + workflow_dispatch: + inputs: + release_tag: + description: "Release tag (e.g. v6.2.3, leave empty for latest)" + type: string + required: false + default: "" + +jobs: + notify: + name: Send Discord Release Notification + if: ${{ github.repository_owner == 'MaaAssistantArknights' }} + runs-on: ubuntu-latest + + steps: + - name: Resolve release info + id: release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [ "${{ github.event_name }}" = "release" ]; then + TAG="${{ github.event.release.tag_name }}" + URL="${{ github.event.release.html_url }}" + else + MANUAL_TAG="${{ github.event.inputs.release_tag }}" + if [ -z "$MANUAL_TAG" ]; then + TAG=$(gh release list --repo "${{ github.repository }}" --limit 1 --json tagName -q '.[0].tagName') + else + TAG="$MANUAL_TAG" + fi + URL="https://github.com/MaaAssistantArknights/MaaAssistantArknights/releases/tag/$TAG" + fi + + echo "tag=$TAG" >> $GITHUB_OUTPUT + echo "url=$URL" >> $GITHUB_OUTPUT + + - name: Build and send Discord message + env: + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL_TEST }} + run: | + TAG="${{ steps.release.outputs.tag }}" + URL="${{ steps.release.outputs.url }}" + + BASE_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}" + WIN_URL="${BASE_URL}/MAA-${TAG}-win-x64.zip" + MAC_URL="${BASE_URL}/MAA-${TAG}-macos-universal.dmg" + LIN_URL="${BASE_URL}/MAA-${TAG}-linux-amd64.tar.gz" + + CONTENT=$(printf '🎉 **New MAA Release: %s**\n\nRead the full release note [here](%s).\n\nOpen or reopen your MAA client to get automatic updates.\nOr, download `MAA %s` for your platform:\n[Windows (x64) ↗](%s) | [macOS (Universal, dmg) ↗](%s) | [Linux (amd64, tar.gz) ↗](%s)' \ + "$TAG" "$URL" "$TAG" "$WIN_URL" "$MAC_URL" "$LIN_URL") + + PAYLOAD=$(jq -n --arg content "$CONTENT" '{ content: $content }') + + HTTP_STATUS=$(curl -sS -o /tmp/discord_response.txt -w "%{http_code}" \ + -X POST "$DISCORD_WEBHOOK_URL" \ + -H "Content-Type: application/json" \ + -d "$PAYLOAD") + + echo "Discord response (HTTP $HTTP_STATUS):" + cat /tmp/discord_response.txt + + if [ "$HTTP_STATUS" -lt 200 ] || [ "$HTTP_STATUS" -ge 300 ]; then + echo "Error: Discord webhook returned HTTP $HTTP_STATUS" + exit 1 + fi