|
| 1 | +name: Release Notification |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + notify: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Extract release info |
| 12 | + id: release_info |
| 13 | + run: | |
| 14 | + echo "RELEASE_TAG=${GITHUB_REF##*/}" >> "$GITHUB_ENV" |
| 15 | + echo "RELEASE_NAME=${{ github.event.release.name }}" >> "$GITHUB_ENV" |
| 16 | + echo "RELEASE_URL=${{ github.event.release.html_url }}" >> "$GITHUB_ENV" |
| 17 | + echo "IS_PRERELEASE=${{ github.event.release.prerelease }}" >> "$GITHUB_ENV" |
| 18 | + # Write release body to a file to preserve multi-line content |
| 19 | + echo '${{ toJSON(github.event.release.body) }}' > release_body.json |
| 20 | +
|
| 21 | + - name: Send Discord Notification |
| 22 | + env: |
| 23 | + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 24 | + RELEASE_TAG: ${{ env.RELEASE_TAG }} |
| 25 | + RELEASE_NAME: ${{ env.RELEASE_NAME }} |
| 26 | + RELEASE_URL: ${{ env.RELEASE_URL }} |
| 27 | + IS_PRERELEASE: ${{ env.IS_PRERELEASE }} |
| 28 | + run: | |
| 29 | + # Read release body from file to preserve multi-line content |
| 30 | + RELEASE_NOTES=$(cat release_body.json | jq -r . | sed ':a;N;$!ba;s/\r//g' | jq -Rs .) |
| 31 | +
|
| 32 | + send_payload() { |
| 33 | + curl -X POST "$DISCORD_WEBHOOK_URL" \ |
| 34 | + -H "Content-Type: application/json" \ |
| 35 | + -d "$1" |
| 36 | + } |
| 37 | +
|
| 38 | + # Determine Release Type |
| 39 | + if [[ "$RELEASE_TAG" == "v3.0.0" ]]; then |
| 40 | + VERSION_TYPE="INITIAL RELEASE" |
| 41 | + COLOR=7308441 |
| 42 | + DESCRIPTION=$(jq -Rs <<< "This is the initial release for the [Re]Structure plugin.") |
| 43 | + FOOTER="Released" |
| 44 | + BUG_FIELD='{ |
| 45 | + "name": "BUG REPORTING:", |
| 46 | + "value": "Report bugs [here](https://github.com/GregoryAM-SP/ReStructure-Plugin/issues)." |
| 47 | + }' |
| 48 | + elif [[ "$RELEASE_TAG" == *"rc"* ]]; then |
| 49 | + VERSION_TYPE="RELEASE CANDIDATE - $RELEASE_NAME" |
| 50 | + COLOR=16760124 |
| 51 | + DESCRIPTION=$(jq -Rs <<< "**Release candidates _can be_ used for production use. ** |
| 52 | + This release is for finalizing checks that the bugs and issues from the pre-release are no longer present. |
| 53 | + |
| 54 | + While you can use [Re]Structure release candidate within your main project, you may have to recreate the Mod Element upon updating to the stable release or if you are updating from a pre-release.") |
| 55 | + FOOTER="Release Candidate" |
| 56 | + BUG_FIELD='{ |
| 57 | + "name": "BUG REPORTING:", |
| 58 | + "value": "Report bugs [here](https://github.com/GregoryAM-SP/ReStructure-Plugin/issues)." |
| 59 | + }' |
| 60 | + elif [[ "$RELEASE_TAG" == *"beta"* || "$IS_PRERELEASE" == "true" ]]; then |
| 61 | + VERSION_TYPE="PRE-RELEASE - $RELEASE_NAME" |
| 62 | + COLOR=16760124 |
| 63 | + DESCRIPTION=$(jq -Rs <<< "This release is for locating bugs, issues and for testing purposes which will help with further development. |
| 64 | + |
| 65 | + **- It is recommended to NOT use this version in your main workspace. **") |
| 66 | + FOOTER="Pre-release" |
| 67 | + BUG_FIELD='{ |
| 68 | + "name": "BUG REPORTING:", |
| 69 | + "value": "Report bugs [here](https://github.com/GregoryAM-SP/ReStructure-Plugin/issues)." |
| 70 | + }' |
| 71 | + else |
| 72 | + # Stable update (Major, Minor, Patch) |
| 73 | + VERSION_TYPE="PATCH UPDATE - $RELEASE_NAME" |
| 74 | + COLOR=7929683 |
| 75 | + DESCRIPTION=$(jq -Rs <<< "This is the latest stable release of **[Re]Structure**. |
| 76 | + |
| 77 | + You can download this release now from the [Re]Structure Menu or from GitHub.") |
| 78 | + FOOTER="Released" |
| 79 | + BUG_FIELD='{ |
| 80 | + "name": "BUG REPORTING:", |
| 81 | + "value": "Report bugs [here](https://github.com/GregoryAM-SP/ReStructure-Plugin/issues)." |
| 82 | + }' |
| 83 | +
|
| 84 | + # Detect Major or Minor |
| 85 | + if [[ "$RELEASE_TAG" =~ ^v([0-9]+)\.([0-9]+)\.0$ ]]; then |
| 86 | + if [[ "${BASH_REMATCH[2]}" == "0" ]]; then |
| 87 | + VERSION_TYPE="MAJOR UPDATE - $RELEASE_NAME" |
| 88 | + DESCRIPTION=$(jq -Rs <<< "This is the latest stable release of **[Re]Structure**. |
| 89 | + |
| 90 | + You can download this release now from the [Re]Structure Menu or from GitHub.") |
| 91 | + else |
| 92 | + VERSION_TYPE="MINOR UPDATE - $RELEASE_NAME" |
| 93 | + DESCRIPTION=$(jq -Rs <<< "This is the latest stable release of **[Re]Structure**. |
| 94 | + |
| 95 | + You can download this release now from the [Re]Structure Menu or from GitHub.") |
| 96 | + fi |
| 97 | + fi |
| 98 | + fi |
| 99 | +
|
| 100 | + # Build JSON payload (correct multiline handling) |
| 101 | + JSON=$(jq -n --arg title "$VERSION_TYPE" \ |
| 102 | + --arg description "$DESCRIPTION" \ |
| 103 | + --arg url "$RELEASE_URL" \ |
| 104 | + --arg timestamp "$(date --utc +%Y-%m-%dT%H:%M:%SZ)" \ |
| 105 | + --argjson color "$COLOR" \ |
| 106 | + --arg footer "$FOOTER" \ |
| 107 | + --arg releaseNotes "$RELEASE_NOTES" \ |
| 108 | + --arg bugField "$BUG_FIELD" \ |
| 109 | + '{ |
| 110 | + "embeds": [ |
| 111 | + { |
| 112 | + "title": $title, |
| 113 | + "description": ($description | fromjson), |
| 114 | + "url": $url, |
| 115 | + "timestamp": $timestamp, |
| 116 | + "color": $color, |
| 117 | + "footer": { |
| 118 | + "text": $footer, |
| 119 | + "icon_url": "https://cdn.discordapp.com/avatars/1368444615224459274/e3ebe26579536ab912c23528f67f3281.webp?size=80" |
| 120 | + }, |
| 121 | + "author": { |
| 122 | + "name": "GitHub: @Gregory-AM", |
| 123 | + "icon_url": "https://avatars.githubusercontent.com/u/83489100?v=4&size=64" |
| 124 | + }, |
| 125 | + "fields": ( |
| 126 | + [$bugField | select(. != "") | fromjson] + [ |
| 127 | + { |
| 128 | + "name": "RELEASE NOTES:", |
| 129 | + "value": ($releaseNotes | fromjson) |
| 130 | + } |
| 131 | + ] |
| 132 | + ) |
| 133 | + } |
| 134 | + ] |
| 135 | + }') |
| 136 | +
|
| 137 | + # Send the payload |
| 138 | + send_payload "$JSON" |
0 commit comments