-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from bitmovin/feature/automate-release-on-merge
Automate release on merge in develop
- Loading branch information
Showing
7 changed files
with
192 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const semver = require('semver'); | ||
|
||
function getPlayerUiVersion(versionInput) { | ||
const playerUiVersion = semver.valid(versionInput); | ||
if (!playerUiVersion) { | ||
console.error(`${versionInput} is not a valid semver`); | ||
process.exit(1); | ||
} | ||
|
||
return { | ||
major: semver.major(playerUiVersion), | ||
minor: semver.minor(playerUiVersion), | ||
patch: semver.patch(playerUiVersion), | ||
prereleaseLabels: semver.prerelease(playerUiVersion), | ||
full: playerUiVersion, | ||
}; | ||
} | ||
|
||
function defineReleaseVersion({ core }, targetReleaseLevel, givenVersion) { | ||
core.info(`Defining new release version for level ${targetReleaseLevel} and version ${givenVersion}`); | ||
|
||
const newVersion = semver.inc(givenVersion, targetReleaseLevel); | ||
|
||
const parsedPlayerVersion = getPlayerUiVersion(newVersion); | ||
core.info(`Using release version ${parsedPlayerVersion.full}`); | ||
return parsedPlayerVersion; | ||
} | ||
|
||
module.exports.defineReleaseVersion = defineReleaseVersion; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Updates the changelog by replacing the changelog header with the correct version | ||
* | ||
* @param {string} changelogString the content of the changelog file | ||
* @param {string} version the player version to be released | ||
* @param {string} releaseDate the release date to be written to the changelog | ||
*/ | ||
function updateChangeLog(changelogString, version, releaseDate) { | ||
const optionalBetaOrRc = '(-rc.d+)?(-(b|beta).d+)?'; | ||
const changelogVersionRegExp = new RegExp( | ||
`\\[(development|develop|unreleased|${version})${optionalBetaOrRc}.*`, | ||
'gi', | ||
); | ||
return changelogString.replace(changelogVersionRegExp, `[${version}] - ${releaseDate}`); | ||
} | ||
|
||
module.exports.updateChangeLog = updateChangeLog; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Trigger release on merge | ||
run-name: Starting release for ${{ github.actor }} PR merge | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
trigger-ui-release: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Read package.json version | ||
uses: actions/github-script@v6 | ||
id: define-package-json-version | ||
with: | ||
script: | | ||
const { version } = require('./package.json') | ||
core.info(`performing a minor release for existing version ${version}`) | ||
core.setOutput('packageJsonVersion', version) | ||
- name: Define release version | ||
uses: actions/github-script@v6 | ||
id: define-release-version | ||
with: | ||
script: | | ||
const { defineReleaseVersion } = require('./.github/scripts/defineVersion.js') | ||
return defineReleaseVersion({core}, 'minor', undefined, "${{ steps.define-package-json-version.outputs.packageJsonVersion }}" ) | ||
- name: Bump package.json version | ||
run: | | ||
git config --global user.name 'Automated Release' | ||
git config --global user.email '[email protected]' | ||
npm version "${{ fromJson(steps.define-release-version.outputs.result).full }}" | ||
- name: Update Changelog | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const { updateChangeLog } = require('./.github/scripts/updateChangelog.js') | ||
const stableVersion = '${{ fromJson(steps.define-release-version.outputs.result).full }}'.split('-')[0] | ||
const releaseDate = new Date().toISOString().split('T')[0] | ||
const data = fs.readFileSync('./CHANGELOG.md',{encoding:'utf8', flag:'r'}); | ||
core.info(`Updating ${stableVersion} with date ${releaseDate} in Changelog`); | ||
const changelogFileContents = updateChangeLog(data, stableVersion, releaseDate); | ||
fs.writeFileSync('./CHANGELOG.md', changelogFileContents, 'utf-8'); | ||
- name: Push changes | ||
run: | | ||
git add . | ||
git commit -m "Add release date to changelog" | ||
git push origin develop | ||
git push origin --tags |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { defineReleaseVersion } = require('../../.github/scripts/defineVersion'); | ||
|
||
describe('defineReleaseVersion', () => { | ||
test.each` | ||
existingVersion | desiredReleaseLevel | expectedVersion | ||
${'1.0.0'} | ${'major'} | ${'2.0.0'} | ||
${'1.0.0'} | ${'minor'} | ${'1.1.0'} | ||
${'1.1.0'} | ${'minor'} | ${'1.2.0'} | ||
${'1.0.0'} | ${'patch'} | ${'1.0.1'} | ||
${'1.1.0'} | ${'patch'} | ${'1.1.1'} | ||
${'1.0.4'} | ${'patch'} | ${'1.0.5'} | ||
${'1.0.0'} | ${'minor'} | ${'1.1.0'} | ||
${'1.0.0'} | ${'minor'} | ${'1.1.0'} | ||
${'1.0.0'} | ${'major'} | ${'2.0.0'} | ||
${'1.5.0'} | ${'major'} | ${'2.0.0'} | ||
${'2.0.0'} | ${'major'} | ${'3.0.0'} | ||
`( | ||
'should return version $expectedVersion with version $existingVersion and $desiredReleaseLevel release level', | ||
({ existingVersion, desiredReleaseLevel, expectedVersion }) => { | ||
const core = { info() {} }; | ||
const result = defineReleaseVersion({ core }, desiredReleaseLevel, existingVersion); | ||
|
||
expect(result.full).toEqual(expectedVersion); | ||
}, | ||
); | ||
}); |