diff --git a/.github/scripts/notifySlackTeam.js b/.github/scripts/notifySlackTeam.js index 4546a6610..c4f1470a9 100644 --- a/.github/scripts/notifySlackTeam.js +++ b/.github/scripts/notifySlackTeam.js @@ -3,9 +3,8 @@ const https = require('https'); const jobStatus = process.argv[2]; const changelogPath = process.argv[3]; -const releaseVersion = process.argv[4]; -const slackWebhookUrl = process.argv[5]; -const runId = process.argv[6]; +const slackWebhookUrl = process.argv[4]; +const runId = process.argv[5]; const slackChannelId = 'C06BYVC27QU' @@ -15,9 +14,21 @@ fs.readFile(changelogPath, 'utf8', (err, fileContent) => { } const changelogContent = parseChangelogEntry(fileContent); + const releaseVersion = parseReleaseVersion(fileContent); sendSlackMessage(slackChannelId, releaseVersion, changelogContent); }); +function parseReleaseVersion(fileContent) { + const regex = /##\s\[(\d+\.\d+.\d+)\]/; + const releaseVersion = fileContent.match(regex); + + if (!releaseVersion) { + return ''; + } + + return releaseVersion[1]; +} + function parseChangelogEntry(fileContent) { // The regex looks for the first paragraph starting with "###" until it finds // a paragraph starting with "##". @@ -35,7 +46,7 @@ function sendSlackMessage(slackChannelId, releaseVersion, changelogContent) { if (jobStatus === 'success') { message = `Changelog v${releaseVersion}\n${changelogContent}` } else { - message = `Release failed.\nPlease check https://github.com/bitmovin/bitmovin-player-ui/actions/runs/${runId}` + message = `Release v${releaseVersion} failed.\nPlease check https://github.com/bitmovin/bitmovin-player-ui/actions/runs/${runId}` } const sampleData = JSON.stringify({ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2754eef30..881c517b4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,7 +31,7 @@ jobs: run: echo Publish - name: Notify team - run: node .github/scripts/notifySlackTeam.js 'success' 'CHANGELOG.md' '${{ fromJson(steps.define-release-version.outputs.result).full }}' ${{ secrets.RELEASE_SUCCESS_SLACK_WEBHOOK }} + run: node .github/scripts/notifySlackTeam.js 'success' 'CHANGELOG.md' ${{ secrets.RELEASE_SUCCESS_SLACK_WEBHOOK }} handle_failure: needs: [test_and_build, download_and_publish] @@ -42,7 +42,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: feature/notify-team-on-release-workflow + ref: feature/test-slack-notify-step - name: Notify team - run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' '' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }} \ No newline at end of file + run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }} \ No newline at end of file diff --git a/.github/workflows/tag-release-version.yml b/.github/workflows/tag-release-version.yml index 4cbd14f54..aa99284c2 100644 --- a/.github/workflows/tag-release-version.yml +++ b/.github/workflows/tag-release-version.yml @@ -71,4 +71,4 @@ jobs: git commit -m "Add release date to changelog" - name: Notify failure if: ${{ failure() }} - run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' '${{ fromJson(steps.define-release-version.outputs.result).full }}' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }} \ No newline at end of file + run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }} \ No newline at end of file