Skip to content

Commit c6ef089

Browse files
committed
Release Notifier Push
1 parent afe7927 commit c6ef089

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Discord Release Notifier
2+
3+
on:
4+
# Manual or UI-published releases
5+
release:
6+
types: [published]
7+
8+
# Releases created by your tag-driven workflow
9+
workflow_run:
10+
workflows: ["Package & Release"] # must match the 'name:' in release.yml
11+
types: [completed]
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
# 1) Handle manual / UI / non-workflow-created releases
18+
notify-from-release:
19+
if: github.event_name == 'release' && github.event.action == 'published'
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Send release payload to Discord Bot
23+
env:
24+
URL: http://${{ secrets.DISCORDBOT }}:3000/github-releases
25+
run: |
26+
curl -sS -X POST "$URL" \
27+
-H 'Content-Type: application/json' \
28+
--data-binary "@$GITHUB_EVENT_PATH"
29+
30+
# 2) Handle releases created by your 'Package & Release' workflow
31+
# (which won’t trigger `on: release` when using GITHUB_TOKEN)
32+
notify-from-workflow-run:
33+
if: >
34+
github.event_name == 'workflow_run' &&
35+
github.event.workflow_run.conclusion == 'success'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Install jq
39+
run: sudo apt-get update && sudo apt-get install -y jq
40+
41+
- name: Fetch release JSON by tag
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
set -euo pipefail
46+
OWNER="${GITHUB_REPOSITORY%/*}"
47+
REPO="${GITHUB_REPOSITORY#*/}"
48+
TAG="${{ github.event.workflow_run.head_branch }}"
49+
# head_branch is the tag name for a tag push workflow_run
50+
curl -fsSL -H "Authorization: Bearer $GH_TOKEN" \
51+
-H "Accept: application/vnd.github+json" \
52+
"https://api.github.com/repos/$OWNER/$REPO/releases/tags/$TAG" \
53+
> release.json
54+
55+
- name: Wrap as 'release' event payload & notify bot
56+
env:
57+
URL: http://${{ secrets.DISCORDBOT }}:3000/github-releases
58+
run: |
59+
set -euo pipefail
60+
jq -n --slurpfile rel release.json \
61+
--arg repo "$GITHUB_REPOSITORY" \
62+
--arg repo_url "https://github.com/$GITHUB_REPOSITORY" \
63+
--arg action "published" '
64+
{ action: $action,
65+
repository: { full_name: $repo, html_url: $repo_url },
66+
release: $rel[0],
67+
sender: { login: "github-actions[bot]" } }' > payload.json
68+
69+
curl -sS -X POST "$URL" \
70+
-H 'Content-Type: application/json' \
71+
--data-binary "@payload.json"

0 commit comments

Comments
 (0)