-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (87 loc) · 3.84 KB
/
Copy pathdiscord-release.yml
File metadata and controls
94 lines (87 loc) · 3.84 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
name: Discord release announce
on:
release:
types: [published]
jobs:
announce:
runs-on: ubuntu-latest
steps:
- name: Wait for the Docker image to be published
env:
TAG: ${{ github.event.release.tag_name }}
run: |
# Announce on Discord only once the image is actually pullable, so the
# "New release published" ping never arrives before the Docker Hub tag
# exists (the build can take 20-40 min, and longer if it stalls). Poll
# the public Docker Hub tags API for the version tag (v-prefix stripped)
# until it returns 200, then let the announce step run.
IMG_TAG="${TAG#v}"
API="https://hub.docker.com/v2/repositories/60plus/gamesdownloader/tags/${IMG_TAG}"
echo "Waiting for Docker Hub tag: ${IMG_TAG}"
for i in $(seq 1 120); do
CODE=$(curl -s -o /dev/null -w "%{http_code}" "$API")
if [ "$CODE" = "200" ]; then
echo "Image ${IMG_TAG} is available after ~$(( (i - 1) * 30 ))s."
exit 0
fi
echo "[$i/120] image not ready yet (HTTP ${CODE}); waiting 30s..."
sleep 30
done
echo "::error::Docker image ${IMG_TAG} did not appear within ~60 min; not announcing. Re-publish the release once the image is built to retry."
exit 1
- name: Post release to Discord
env:
WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
TAG: ${{ github.event.release.tag_name }}
NAME: ${{ github.event.release.name }}
URL: ${{ github.event.release.html_url }}
BODY: ${{ github.event.release.body }}
AUTHOR: ${{ github.event.release.author.login }}
ASSETS: ${{ toJSON(github.event.release.assets) }}
run: |
# Truncate body to 1500 chars to fit in Discord embed
DESCRIPTION=$(echo "$BODY" | head -c 1500)
# Up to four image assets become a gallery. Extra embeds that share the
# release URL are merged by Discord into one gallery under the main embed,
# so attaching screenshots to the release shows them inline.
IMAGE_EMBEDS=$(echo "$ASSETS" | jq --arg url "$URL" '
[ .[]
| select((.content_type // "" | startswith("image/"))
or (.name | test("\\.(png|jpe?g|webp|gif)$"; "i")))
| { url: $url, image: { url: .browser_download_url } }
] | .[0:4]')
# Direct video links (webm/mp4) found in the release body go into the
# plain message content - Discord renders a playable player for raw
# video URLs there (embeds cannot). First link only, to keep it tidy.
VIDEO_URL=$(echo "$BODY" | grep -oE 'https://[^ )>]+\.(webm|mp4)' | head -1 || true)
CONTENT=":rocket: **New release published!**"
if [ -n "$VIDEO_URL" ]; then
CONTENT="$CONTENT
$VIDEO_URL"
fi
# Build JSON payload using jq for safe escaping
PAYLOAD=$(jq -n \
--arg title "$NAME" \
--arg url "$URL" \
--arg desc "$DESCRIPTION" \
--arg tag "$TAG" \
--arg author "$AUTHOR" \
--arg content "$CONTENT" \
--argjson images "$IMAGE_EMBEDS" \
'{
content: $content,
embeds: ([{
title: $title,
url: $url,
description: $desc,
color: 10180351,
fields: [
{ name: "Tag", value: $tag, inline: true },
{ name: "By", value: $author, inline: true }
],
footer: { text: "GamesDownloader" }
}] + $images)
}')
curl -X POST -H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$WEBHOOK_URL"