Skip to content

Commit 8807cf7

Browse files
Refactor Discord notifications workflow
1 parent 0507a29 commit 8807cf7

1 file changed

Lines changed: 40 additions & 30 deletions

File tree

.github/workflows/main.yml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
1-
name: Discord Push Notifications
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
7-
jobs:
8-
notify:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Send all commits to Discord
12-
run: |
13-
REPO="${{ github.repository }}"
14-
BRANCH="${GITHUB_REF##*/}" # dynamically get branch name
15-
ACTOR="${{ github.actor }}"
16-
COMMIT_TEXT=""
17-
18-
# Loop through all commits safely
19-
jq -c '.commits[]' < "${GITHUB_EVENT_PATH}" | while read commit; do
20-
COMMIT_MSG=$(echo "$commit" | jq -r '.message')
21-
COMMIT_URL=$(echo "$commit" | jq -r '.url')
22-
COMMIT_TEXT="${COMMIT_TEXT}- [$COMMIT_MSG]($COMMIT_URL)"
23-
done
24-
25-
# Prepare payload with proper newlines
26-
PAYLOAD=$(jq -n --arg content "🚀 $ACTOR pushed to **$BRANCH** in [$REPO](https://github.com/$REPO):
27-
$COMMIT_TEXT" '{content: $content}')
28-
29-
# Send to Discord
30-
curl -H "Content-Type: application/json" -d "$PAYLOAD" ${{ secrets.DISCORD_WEBHOOK }}
1+
- name: Actions Status Discord
2+
# You may pin to the exact commit or the version.
3+
# uses: sarisia/actions-status-discord@11a0bfe3b50977e38aa2bd4a4ebd296415e83c19
4+
uses: sarisia/actions-status-discord@v1.15.4
5+
with:
6+
# Discord webhook endpoint. If not set, env.DISCORD_WEBHOOK will be used.
7+
webhook: {{ secrets.DISCORD_WEBHOOK }}
8+
# Job status. Should be bound to job.status. Default to success.
9+
status: # optional, default is ${{ job.status }}
10+
# Deprecated. Job name included in message title. Same as title input.
11+
job: # optional
12+
# Content. Shown as an message outside of the embed. See [Mention to user/role](#mention-to-user-role)
13+
content: # optional
14+
# String included in embed title. Overrides job input.
15+
title: # optional, default is ${{ github.workflow }}
16+
# Description included in message
17+
description: # optional
18+
# Image attached to the message
19+
image: # optional
20+
# Overrides Discord embed color
21+
color: # optional
22+
# URL to jump when the title is clicked
23+
url: # optional
24+
# Overrides Discord webhook username
25+
username: # optional
26+
# Overrides Discord webhook avatar url
27+
avatar_url: # optional
28+
# This action won't make workflow failed by default.
29+
nofail: # optional, default is true
30+
# Suppress GitHub context fields
31+
nocontext: # optional, default is false
32+
# Avoid appending job status to title
33+
noprefix: # optional, default is false
34+
# Suppress detailed embed fields
35+
nodetail: # optional, default is false
36+
# Avoid appending timestamp
37+
notimestamp: # optional, default is false
38+
# Suppress error which raised when webhook is not set
39+
ack_no_webhook: # optional, default is false
40+

0 commit comments

Comments
 (0)