From a0a3b7ff4c70c737a52b73ca31d19589b62c77cd Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:53:27 -0500 Subject: [PATCH] CI: post merged pull requests, community issues and releases to the WrongGPU Discord A Discord feed for #github-feed: each merged pull request with a short summary from its description and its milestone's progress, new issues from the community, and published releases. No pushes and no opened or edited pull requests. It reads only the event and the milestone; it never checks out pull request code, so pull_request_target is safe here. A workflow_dispatch entry posts a written digest (maintainers only). The webhook is the DISCORD_GITHUB_FEED secret. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/discord-feed.yml | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/discord-feed.yml diff --git a/.github/workflows/discord-feed.yml b/.github/workflows/discord-feed.yml new file mode 100644 index 00000000..6db3c71f --- /dev/null +++ b/.github/workflows/discord-feed.yml @@ -0,0 +1,77 @@ +# Posts what matters on GitHub to the WrongGPU Discord (#github-feed): merged pull requests with a short summary and +# their milestone's progress, new issues from the community, and published releases. Nothing else (no pushes, no +# opened or edited pull requests). It never checks out pull request code; it only reads the event and the milestone. +# The digest job posts a summary written elsewhere (workflow_dispatch with a message; maintainers only). +name: Discord feed + +on: + pull_request_target: + types: [closed] + issues: + types: [opened] + release: + types: [published] + workflow_dispatch: + inputs: + title: + description: Digest title + required: true + message: + description: Digest text (Discord markdown, up to 4000 characters) + required: true + +permissions: + issues: read + pull-requests: read + +jobs: + post: + runs-on: ubuntu-latest + if: >- + (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) || + (github.event_name == 'issues' && github.event.issue.user.login != 'phantoslayer21') || + github.event_name == 'release' || github.event_name == 'workflow_dispatch' + steps: + - name: Build and send the message + env: + WEBHOOK: ${{ secrets.DISCORD_GITHUB_FEED }} + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + DIGEST_TITLE: ${{ inputs.title }} + DIGEST_MESSAGE: ${{ inputs.message }} + run: | + set -euo pipefail + [ -n "$WEBHOOK" ] || { echo "no webhook secret"; exit 0; } + ev="$GITHUB_EVENT_PATH" + # first real paragraph of a body: no headings, comments, checklists or bot lines; 350 characters at most + summary() { jq -r "$1 // \"\"" "$ev" | tr -d '\r' | sed -e '/^/d' -e '/^#/d' -e '/^- \[[ x]\]/d' \ + -e '/^Signed-off-by:/d' -e '/^Co-Authored-By:/d' -e '/^Refs\? #/d' -e '/^Fixes #/d' -e '/^Closes #/d' \ + | awk 'BEGIN{p=0} /^[[:space:]]*$/{if(p)exit; next} {p=1; printf "%s ", $0}' \ + | sed -e 's/\*\*//g' -e 's/ */ /g' | cut -c1-350; } + progress() { + local n; n=$(jq -r "$1 // empty" "$ev"); [ -n "$n" ] || return 0 + gh api "repos/$REPO/milestones/$n" --jq '"\(.title): \(.closed_issues) of \(.open_issues + .closed_issues) done"' 2>/dev/null || true; } + case "$GITHUB_EVENT_NAME" in + pull_request_target) + title="Merged #$(jq -r .pull_request.number "$ev"): $(jq -r .pull_request.title "$ev")" + url=$(jq -r .pull_request.html_url "$ev"); desc=$(summary .pull_request.body); color=5763719 + ms=$(progress .pull_request.milestone.number) + if [ -z "$ms" ]; then # the PR itself may not carry a milestone; use the first issue it closes or refers to + ref=$(jq -r '.pull_request.body // ""' "$ev" | grep -oiE '(fixes|closes|refs?) #[0-9]+' | head -1 | grep -oE '[0-9]+' || true) + [ -n "$ref" ] && ms=$(gh api "repos/$REPO/issues/$ref" --jq 'select(.milestone)|.milestone.number' 2>/dev/null \ + | xargs -r -I{} gh api "repos/$REPO/milestones/{}" --jq '"\(.title): \(.closed_issues) of \(.open_issues + .closed_issues) done"' 2>/dev/null || true) + fi ;; + issues) + title="New issue #$(jq -r .issue.number "$ev"): $(jq -r .issue.title "$ev")" + url=$(jq -r .issue.html_url "$ev"); desc="by $(jq -r .issue.user.login "$ev") — $(summary .issue.body)"; color=15105570; ms="" ;; + release) + title="Released: $(jq -r '.release.name // .release.tag_name' "$ev")" + url=$(jq -r .release.html_url "$ev"); desc=$(summary .release.body); color=3447003; ms="" ;; + workflow_dispatch) + title="$DIGEST_TITLE"; url="https://github.com/$REPO"; desc=$(printf '%s' "$DIGEST_MESSAGE" | cut -c1-4000); color=10181046; ms="" ;; + esac + payload=$(jq -n --arg t "${title:0:250}" --arg u "$url" --arg d "$desc" --arg m "$ms" --argjson c "$color" \ + '{username:"GitHub", embeds:[{title:$t, url:$u, description:$d, color:$c, + fields:(if $m=="" then [] else [{name:"Milestone", value:$m, inline:true}] end)}]}') + curl -fsS -X POST -H "Content-Type: application/json" --data "$payload" "$WEBHOOK" >/dev/null + echo "posted: $title"