Juju519 commited on
Commit
631f3c9
·
unverified ·
1 Parent(s): dfd3a73

Update discord-notification.yml

Browse files
.github/workflows/discord-notification.yml CHANGED
@@ -1,68 +1 @@
1
- name: Discord Notification
2
 
3
- on:
4
- push:
5
- branches: [case_study_1_2025]
6
- workflow_dispatch:
7
-
8
- permissions:
9
- contents: read
10
-
11
- jobs:
12
- notify:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - name: Guard: ensure webhook is set
16
- id: guard
17
- env:
18
- DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
19
- run: |
20
- if [ -z "$DISCORD_WEBHOOK_URL" ]; then
21
- echo "Webhook secret DISCORD_WEBHOOK_URL is not set. Skipping."
22
- echo "continue=false" >> $GITHUB_OUTPUT
23
- else
24
- echo "continue=true" >> $GITHUB_OUTPUT
25
- fi
26
-
27
- - name: Build rich Discord embed
28
- if: steps.guard.outputs.continue == 'true'
29
- id: payload
30
- uses: actions/github-script@v7
31
- with:
32
- script: |
33
- const repo = context.payload.repository.full_name;
34
- const branch = (context.ref || "").replace("refs/heads/", "") || context.payload.ref || "unknown";
35
- const actor = context.actor;
36
- const sha = context.sha || (context.payload.after ?? "");
37
- const sha7 = sha ? sha.substring(0,7) : "unknown";
38
- const head = context.payload.head_commit || null;
39
- const message = head?.message || (context.payload.commits?.length ? `${context.payload.commits.length} commits pushed` : "(no message)");
40
- const compare = context.payload.compare || `https://github.com/${repo}/commit/${sha}`;
41
-
42
- const embed = {
43
- title: `Push to ${branch}`,
44
- url: compare,
45
- description: `**${repo}**\n\`${sha7}\` by **${actor}**`,
46
- color: 5814783,
47
- fields: [
48
- { name: "Branch", value: branch, inline: true },
49
- { name: "Actor", value: actor, inline: true },
50
- { name: "Message", value: (message || "").slice(0, 1000) || "(empty)" }
51
- ],
52
- timestamp: new Date().toISOString()
53
- };
54
-
55
- const payload = { username: "CI Bot", embeds: [embed] };
56
- core.setOutput("json", JSON.stringify(payload));
57
-
58
- - name: Send Discord notification
59
- if: steps.guard.outputs.continue == 'true'
60
- env:
61
- DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
62
- PAYLOAD: ${{ steps.payload.outputs.json }}
63
- run: |
64
- curl -sS -X POST \
65
- -H "Content-Type: application/json" \
66
- --retry 5 --retry-delay 2 \
67
- -d "$PAYLOAD" \
68
- "$DISCORD_WEBHOOK_URL"
 
 
1