|
1 | 1 | # For app repos (TypeType-Android, TypeType-IOS, TypeType-TV, TypeType-tvOS). |
2 | 2 | # Pre-releases (-beta.N, -rc.N) go to #🧪・releases-rc, stable releases go to #🚀・releases-main, |
3 | 3 | # with the release notes. Needs the secrets DISCORD_WEBHOOK_RC and DISCORD_WEBHOOK_MAIN. |
| 4 | +# |
| 5 | +# A release published by hand fires `release`. A release created by a build workflow with GITHUB_TOKEN never fires |
| 6 | +# `release` (GitHub does not start workflows from GITHUB_TOKEN events), so `workflow_run` catches those: when a build |
| 7 | +# that ran a release/publish job succeeds, the releases whose tag points at the commit it built are posted. |
| 8 | +# `workflow_dispatch` posts one tag by hand. |
4 | 9 | name: Discord release notify |
5 | 10 |
|
6 | 11 | on: |
7 | 12 | release: |
8 | 13 | types: [published] |
| 14 | + workflow_run: |
| 15 | + workflows: ["iOS", "Android", "Android Beta", "Release"] |
| 16 | + types: [completed] |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + tag: |
| 20 | + description: Release tag to post |
| 21 | + required: true |
9 | 22 |
|
10 | 23 | permissions: |
11 | 24 | contents: read |
| 25 | + actions: read |
12 | 26 |
|
13 | 27 | jobs: |
14 | 28 | notify: |
| 29 | + if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} |
15 | 30 | runs-on: ubuntu-latest |
16 | 31 | steps: |
| 32 | + - name: Find the releases to post |
| 33 | + env: |
| 34 | + GH_TOKEN: ${{ github.token }} |
| 35 | + REPO: ${{ github.repository }} |
| 36 | + EVENT: ${{ github.event_name }} |
| 37 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 38 | + INPUT_TAG: ${{ inputs.tag }} |
| 39 | + RUN_ID: ${{ github.event.workflow_run.id }} |
| 40 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + : > tags.txt |
| 44 | + case "$EVENT" in |
| 45 | + release) echo "$RELEASE_TAG" > tags.txt ;; |
| 46 | + workflow_dispatch) echo "$INPUT_TAG" > tags.txt ;; |
| 47 | + workflow_run) |
| 48 | + ran=$(gh api "repos/$REPO/actions/runs/$RUN_ID/jobs" \ |
| 49 | + --jq '[.jobs[] | select((.name | test("release|publish"; "i")) and .conclusion == "success")] | length') |
| 50 | + [ "$ran" -gt 0 ] || { echo "no release job ran"; exit 0; } |
| 51 | + for tag in $(gh api "repos/$REPO/releases?per_page=10" \ |
| 52 | + --jq '.[] | select(.draft == false and .author.login == "github-actions[bot]") | .tag_name'); do |
| 53 | + sha=$(gh api "repos/$REPO/commits/$tag" --jq .sha) |
| 54 | + [ "$sha" = "$HEAD_SHA" ] && echo "$tag" >> tags.txt |
| 55 | + done |
| 56 | + ;; |
| 57 | + esac |
| 58 | + cat tags.txt |
| 59 | +
|
17 | 60 | - name: Post to Discord |
18 | 61 | env: |
| 62 | + GH_TOKEN: ${{ github.token }} |
| 63 | + REPO: ${{ github.repository }} |
19 | 64 | WEBHOOK_RC: ${{ secrets.DISCORD_WEBHOOK_RC }} |
20 | 65 | WEBHOOK_MAIN: ${{ secrets.DISCORD_WEBHOOK_MAIN }} |
21 | | - PRERELEASE: ${{ github.event.release.prerelease }} |
22 | | - TAG: ${{ github.event.release.tag_name }} |
23 | | - RNAME: ${{ github.event.release.name }} |
24 | | - URL: ${{ github.event.release.html_url }} |
25 | | - BODY: ${{ github.event.release.body }} |
26 | | - REPO: ${{ github.repository }} |
27 | 66 | run: | |
28 | 67 | set -euo pipefail |
29 | | - if [ "$PRERELEASE" = "true" ]; then |
30 | | - WEBHOOK="$WEBHOOK_RC"; BOT="The Lab TV"; EMOJI="🧪"; COLOR=15105570; INTRO="Beta build, might break, have fun (・ω・)" |
31 | | - else |
32 | | - WEBHOOK="$WEBHOOK_MAIN"; BOT="Rocket TV"; EMOJI="🚀"; COLOR=5763719; INTRO="New release (。•̀ᴗ-)✧" |
33 | | - fi |
34 | | - [ -n "$WEBHOOK" ] || { echo "webhook secret not set"; exit 0; } |
35 | | - TITLE="${EMOJI} ${RNAME:-${REPO#*/} ${TAG}}" |
36 | | - jq -n \ |
37 | | - --arg title "$TITLE" \ |
38 | | - --arg url "$URL" \ |
39 | | - --arg desc "$(printf '%s\n\n%s' "$INTRO" "${BODY:-}" | cut -c1-3900)" \ |
40 | | - --argjson color "$COLOR" \ |
41 | | - --arg bot "$BOT" \ |
42 | | - '{username: $bot, embeds: [{title: $title, url: $url, description: $desc, color: $color}]}' \ |
43 | | - > payload.json |
44 | | - curl -fsS -H "Content-Type: application/json" -d @payload.json "$WEBHOOK" |
| 68 | + while read -r TAG; do |
| 69 | + [ -n "$TAG" ] || continue |
| 70 | + gh api "repos/$REPO/releases/tags/$TAG" > release.json |
| 71 | + PRERELEASE=$(jq -r .prerelease release.json) |
| 72 | + RNAME=$(jq -r '.name // ""' release.json) |
| 73 | + URL=$(jq -r .html_url release.json) |
| 74 | + BODY=$(jq -r '.body // ""' release.json) |
| 75 | + if [ "$PRERELEASE" = "true" ]; then |
| 76 | + WEBHOOK="$WEBHOOK_RC"; BOT="The Lab TV"; EMOJI="🧪"; COLOR=15105570; INTRO="Beta build, might break, have fun (・ω・)" |
| 77 | + else |
| 78 | + WEBHOOK="$WEBHOOK_MAIN"; BOT="Rocket TV"; EMOJI="🚀"; COLOR=5763719; INTRO="New release (。•̀ᴗ-)✧" |
| 79 | + fi |
| 80 | + [ -n "$WEBHOOK" ] || { echo "webhook secret not set"; exit 0; } |
| 81 | + TITLE="${EMOJI} ${RNAME:-${REPO#*/} ${TAG}}" |
| 82 | + jq -n \ |
| 83 | + --arg title "$TITLE" \ |
| 84 | + --arg url "$URL" \ |
| 85 | + --arg desc "$(printf '%s\n\n%s' "$INTRO" "${BODY:-}" | cut -c1-3900)" \ |
| 86 | + --argjson color "$COLOR" \ |
| 87 | + --arg bot "$BOT" \ |
| 88 | + '{username: $bot, embeds: [{title: $title, url: $url, description: $desc, color: $color}]}' \ |
| 89 | + > payload.json |
| 90 | + curl -fsS -H "Content-Type: application/json" -d @payload.json "$WEBHOOK" |
| 91 | + echo "posted $TAG" |
| 92 | + done < tags.txt |
0 commit comments