Notify Release #69
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Notify Release | |
| on: | |
| workflow_run: | |
| workflows: ["Release Build"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| mention_everyone: | |
| description: "Ping @everyone on Discord?" | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| steps: | |
| - name: Fetch Release Data | |
| id: fetch_data | |
| run: | | |
| RELEASE_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{github.repository}}/releases" | jq '.[0]') | |
| TAG=$(echo "$RELEASE_DATA" | jq -r '.tag_name') | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "$RELEASE_DATA" | jq -r '.body' > release_notes.txt | |
| echo "$RELEASE_DATA" > release.json | |
| - name: Categorize Assets | |
| run: | | |
| jq -r '.assets[] | "🔹 [\(.name)](\(.browser_download_url)) | \((.size/1048576) | tonumber | round) MB"' release.json > asset_list.txt | |
| - name: Send Discord Notification | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
| MENTION: ${{ github.event.inputs.mention_everyone == 'true' && '@everyone' || '' }} | |
| TAG: ${{ steps.fetch_data.outputs.tag }} | |
| run: | | |
| NOTES=$(cat release_notes.txt) | |
| ASSETS=$(cat asset_list.txt) | |
| FULL_DESC=$(printf "### Changelog\n%s\n\n### Downloads\n%s" "$NOTES" "$ASSETS") | |
| cat <<EOF > discord_payload.json | |
| { | |
| "content": "$MENTION", | |
| "embeds": [{ | |
| "title": "🚀 New Release: $TAG", | |
| "description": "", | |
| "color": 1754309, | |
| "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| }] | |
| } | |
| EOF | |
| jq --arg desc "$FULL_DESC" '.embeds[0].description = $desc' discord_payload.json > final_payload.json | |
| curl -H "Content-Type: application/json" -X POST -d @final_payload.json "$DISCORD_WEBHOOK" |