diff --git a/.github/bot-scripts/post-release-notes.js b/.github/bot-scripts/post-release-notes.js new file mode 100644 index 0000000000..49a602c9d8 --- /dev/null +++ b/.github/bot-scripts/post-release-notes.js @@ -0,0 +1,37 @@ +/// +// @ts-check + +/** + * @param {{github: Github, context: Context}} param + */ +async function main(param) { + const { github, context } = param; + + const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL || ''; + + // remove multiple spaces and put links between < > to prevent embeds + const releaseNotes = context.payload.release.body.replace(/(\r\n+|\n+|\r+)/gm, '\n').replace(/(https:\/\/[^)]+)/g, '<$1>'); + + try { + console.log('Posting release notes to Discord...'); + console.log(releaseNotes); + + const response = await fetch(discordWebhookUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ content: releaseNotes }), + }); + + if (response.ok) { + console.log('Release notes posted to Discord successfully.'); + } else { + console.error('Failed to post release notes to Discord:', response.status, response.statusText); + } + } catch (error) { + console.error('Error posting release notes to Discord:', error); + } +} +module.exports = main; + diff --git a/.github/workflows/discord-publish.yml b/.github/workflows/discord-publish.yml new file mode 100644 index 0000000000..ce906a1ab6 --- /dev/null +++ b/.github/workflows/discord-publish.yml @@ -0,0 +1,23 @@ +name: Post Release Notes to Discord + +on: + release: + types: + - published + +jobs: + post-release-notes: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - uses: actions/github-script@v6 + name: Post release notes to Discord + env: + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + with: + script: | + const script = require('./.github/bot-scripts/post-release-notes.js') + script({github, context}) \ No newline at end of file