-
Notifications
You must be signed in to change notification settings - Fork 18
155 lines (138 loc) · 5.66 KB
/
release.yml
File metadata and controls
155 lines (138 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
release:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Package and Upload
uses: BigWigsMods/packager@6d50adb6e8517eefef63f4afb16a6518166a6b28 # v2
env:
CF_API_KEY: ${{ secrets.CF_API_KEY }}
WOWI_API_TOKEN: ${{ secrets.WOWI_API_TOKEN }}
WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }}
GITHUB_OAUTH: ${{ secrets.GITHUB_TOKEN }}
- name: Announce on Discord
if: success()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
REPO: ${{ github.repository }}
SERVER_URL: ${{ github.server_url }}
API_URL: ${{ github.api_url }}
run: |
python3 - <<'PY'
import json
import os
import urllib.request
tag = os.environ["TAG"]
repo = os.environ["REPO"]
release_url = f'{os.environ["SERVER_URL"]}/{repo}/releases/tag/{tag}'
curseforge_url = "https://www.curseforge.com/wow/addons/midnight-routine"
release_request = urllib.request.Request(
f'{os.environ["API_URL"]}/repos/{repo}/releases/tags/{tag}',
headers={
"Accept": "application/vnd.github+json",
"Authorization": f'Bearer {os.environ["GITHUB_TOKEN"]}',
"User-Agent": "MidnightRoutineReleaseBot (GitHub Actions)"
}
)
with urllib.request.urlopen(release_request) as response:
release = json.loads(response.read().decode("utf-8"))
notes = release.get("body", "").strip() or "A new Midnight Routine update is available."
if len(notes) > 3300:
notes = notes[:3290].rstrip() + "\n\n...more details in the full changelog."
description = f"{notes}\n\n[View full release notes]({release_url})"
payload = {
"username": "Midnight Routine Changelog",
"allowed_mentions": {"parse": []},
"embeds": [{
"title": f"Midnight Routine {tag} released",
"url": release_url,
"description": description,
"color": 5625599,
"fields": [
{
"name": "Download",
"value": f"[GitHub Release]({release_url}) | [CurseForge]({curseforge_url})",
"inline": False
}
],
"footer": {
"text": "Midnight Routine - Your weekly Midnight checklist"
}
}]
}
request = urllib.request.Request(
os.environ["DISCORD_WEBHOOK"] + "?wait=true",
data=json.dumps(payload).encode("utf-8"),
headers={
"Content-Type": "application/json",
"User-Agent": "MidnightRoutineReleaseBot (GitHub Actions)"
},
method="POST",
)
with urllib.request.urlopen(request) as response:
if response.status not in (200, 204):
raise RuntimeError(f"Discord webhook failed: HTTP {response.status}")
message = json.loads(response.read().decode("utf-8"))
guild_id = message.get("guild_id")
channel_id = message.get("channel_id")
message_id = message.get("id")
print(f"Discord accepted message ID {message_id} in channel ID {channel_id}.")
if guild_id and channel_id and message_id:
print(f"Discord message link: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}")
PY
discord-test:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Test Discord Webhook
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
python3 - <<'PY'
import json
import os
import urllib.request
payload = {
"username": "Midnight Routine Changelog",
"allowed_mentions": {"parse": []},
"embeds": [{
"title": "Midnight Routine Discord connection test",
"description": "This test message confirms which Discord channel receives release announcements.",
"color": 5625599,
"footer": {
"text": "Midnight Routine - Release workflow test"
}
}]
}
request = urllib.request.Request(
os.environ["DISCORD_WEBHOOK"] + "?wait=true",
data=json.dumps(payload).encode("utf-8"),
headers={
"Content-Type": "application/json",
"User-Agent": "MidnightRoutineReleaseBot (GitHub Actions)"
},
method="POST",
)
with urllib.request.urlopen(request) as response:
message = json.loads(response.read().decode("utf-8"))
guild_id = message.get("guild_id")
channel_id = message.get("channel_id")
message_id = message.get("id")
print(f"Discord accepted message ID {message_id} in channel ID {channel_id}.")
if guild_id and channel_id and message_id:
print(f"Discord message link: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}")
PY