-
Notifications
You must be signed in to change notification settings - Fork 32
52 lines (47 loc) · 1.92 KB
/
discord-release-notification.yml
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
name: Discord Release Notification
on:
release:
types: [published, created, edited]
workflow_dispatch:
jobs:
notify_discord:
runs-on: ubuntu-latest
steps:
- name: Fetch latest release
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_release=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest")
echo "RELEASE_TAG=$(echo $latest_release | jq -r .tag_name)" >> $GITHUB_ENV
echo "RELEASE_NAME=$(echo $latest_release | jq -r .name)" >> $GITHUB_ENV
printf "RELEASE_BODY=%s\n" "$(echo $latest_release | jq -r .body)" >> $GITHUB_ENV
echo "RELEASE_URL=$(echo $latest_release | jq -r .html_url)" >> $GITHUB_ENV
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Send Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_ANN }}
RELEASE_TAG: ${{ env.RELEASE_TAG || github.event.release.tag_name }}
RELEASE_NAME: ${{ env.RELEASE_NAME || github.event.release.name }}
RELEASE_BODY: ${{ env.RELEASE_BODY || github.event.release.body }}
RELEASE_URL: ${{ env.RELEASE_URL || github.event.release.html_url }}
run: |
echo "Sending notification for release: $RELEASE_TAG"
curl -H "Content-Type: application/json" -X POST -d @- $DISCORD_WEBHOOK <<EOF
{
"embeds": [{
"title": "New Release: $RELEASE_TAG",
"description": "$RELEASE_NAME\n\n$RELEASE_BODY",
"url": "$RELEASE_URL",
"color": 3066993
}]
}
EOF