Skip to content

Commit e76c44f

Browse files
committed
Add Discord notification workflow
1 parent e5abd60 commit e76c44f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Discord Update Notification
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
notify:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 2
16+
17+
- name: Get changed files
18+
id: changed-files
19+
run: |
20+
CHANGED_FILES=$(git diff --name-only HEAD^..HEAD | head -n 10 | sed 's/^/`/' | sed 's/$/`/' | paste -sd ',' - | sed 's/,/, /g')
21+
if [ -z "$CHANGED_FILES" ]; then
22+
CHANGED_FILES="No files changed"
23+
fi
24+
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
25+
26+
- name: Send Discord Notification
27+
env:
28+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
29+
run: |
30+
COMMIT_MSG=$(echo '${{ github.event.head_commit.message }}' | sed 's/"/\\"/g' | head -c 1000)
31+
AUTHOR="${{ github.event.head_commit.author.name }}"
32+
SHORT_SHA="${{ github.sha }}"
33+
SHORT_SHA=${SHORT_SHA:0:7}
34+
35+
curl -H "Content-Type: application/json" \
36+
-d "{\"embeds\": [{
37+
\"title\": \"πŸš€ FlockersDevHub Updated\",
38+
\"description\": \"New changes have been pushed to the website\",
39+
\"color\": 65475,
40+
\"fields\": [
41+
{\"name\": \"πŸ“ Commit Message\", \"value\": \"${COMMIT_MSG}\"},
42+
{\"name\": \"πŸ‘€ Author\", \"value\": \"${AUTHOR}\", \"inline\": true},
43+
{\"name\": \"🌿 Branch\", \"value\": \"${{ github.ref_name }}\", \"inline\": true},
44+
{\"name\": \"πŸ“¦ Commit\", \"value\": \"[\`${SHORT_SHA}\`](${{ github.event.head_commit.url }})\", \"inline\": true},
45+
{\"name\": \"πŸ“‚ Changed Files\", \"value\": \"${{ steps.changed-files.outputs.files }}\"},
46+
{\"name\": \"🌐 Live Site\", \"value\": \"[Visit FlockersDevHub](https://erasmusdev.github.io/FlockersDevHub)\"}
47+
],
48+
\"thumbnail\": {
49+
\"url\": \"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\"
50+
},
51+
\"footer\": {
52+
\"text\": \"GitHub Actions\"
53+
},
54+
\"timestamp\": \"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)\"
55+
}]}" \
56+
$DISCORD_WEBHOOK

0 commit comments

Comments
Β (0)