mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 17:57:01 +08:00
ci: add discord release notification
This commit is contained in:
71
.github/workflows/discord-release-notification.yml
vendored
Normal file
71
.github/workflows/discord-release-notification.yml
vendored
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user