Skip to content

Commit 39811ea

Browse files
authored
Create discord_test.yml
1 parent 75c5b1a commit 39811ea

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/discord_test.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Discord Webhook Debug
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
jobs:
7+
ping:
8+
runs-on: ubuntu-latest
9+
env:
10+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
11+
steps:
12+
- name: Sanity ping (plain text)
13+
run: |
14+
echo "Posting a simple message to verify the webhook/channel…"
15+
# Capture HTTP code and response
16+
CODE=$(curl -sS -o /tmp/resp.txt -w '%{http_code}' \
17+
-H "Content-Type: application/json" \
18+
-d '{"content":"✅ Webhook test from GitHub Actions."}' \
19+
"${DISCORD_WEBHOOK}")
20+
echo "HTTP: $CODE"
21+
echo "Response:"
22+
cat /tmp/resp.txt
23+
# 204 = success (Discord webhooks return 204 No Content on success)
24+
if [ "$CODE" -ne 204 ]; then
25+
echo "::error::Discord did not accept the message (HTTP $CODE)"
26+
exit 1
27+
fi
28+
29+
- name: Install jq
30+
run: |
31+
sudo apt-get update -y >/dev/null 2>&1
32+
sudo apt-get install -y jq >/dev/null 2>&1
33+
34+
- name: Post a sample embed (robust JSON escaping)
35+
env:
36+
REPO_NAME: ${{ github.repository }}
37+
run: |
38+
SAMPLE_BODY="This is a test embed description.\n• Supports **Markdown**\n• Shows up if JSON is valid"
39+
# Truncate to 4096 (embed description limit)
40+
BODY_TRUNCATED=$(printf '%s' "$SAMPLE_BODY" | head -c 4096)
41+
# Encode as JSON string safely
42+
BODY_JSON=$(printf '%s' "$BODY_TRUNCATED" | jq -Rs .)
43+
44+
payload=$(jq -n \
45+
--arg title "$REPO_NAME – Debug Embed" \
46+
--arg url "https://github.com/${REPO_NAME}" \
47+
--arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
48+
--argjson desc "$BODY_JSON" '
49+
{
50+
embeds: [
51+
{
52+
title: $title,
53+
url: $url,
54+
description: $desc,
55+
timestamp: $ts,
56+
footer: { text: "Webhook debug" }
57+
}
58+
]
59+
}')
60+
61+
CODE=$(curl -sS -o /tmp/resp2.txt -w '%{http_code}' \
62+
-H "Content-Type: application/json" \
63+
-d "$payload" \
64+
"${DISCORD_WEBHOOK}")
65+
echo "HTTP: $CODE"
66+
echo "Response:"
67+
cat /tmp/resp2.txt
68+
if [ "$CODE" -ne 204 ]; then
69+
echo "::error::Discord rejected the embed (HTTP $CODE)"
70+
exit 1
71+
fi

0 commit comments

Comments
 (0)