Skip to content

Commit

Permalink
Parser release version
Browse files Browse the repository at this point in the history
  • Loading branch information
mukulmishra18 committed Jan 4, 2024
1 parent e354185 commit cbd3b9d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions .github/scripts/notifySlackTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 "##".
Expand All @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 }}
run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }}
2 changes: 1 addition & 1 deletion .github/workflows/tag-release-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
run: node .github/scripts/notifySlackTeam.js 'failure' 'CHANGELOG.md' ${{ secrets.RELEASE_FAILURE_SLACK_WEBHOOK }} ${{ github.run_id }}

0 comments on commit cbd3b9d

Please sign in to comment.