-
Notifications
You must be signed in to change notification settings - Fork 2
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 #172 from bitmovin/feature/automate-release
Automate release
- Loading branch information
Showing
4 changed files
with
190 additions
and
78 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,35 @@ | ||
const parseChangelog = require('changelog-parser'); | ||
const semver = require('semver'); | ||
|
||
async function defineReleaseVersion({ core }, currentVersion, changelogFile) { | ||
return parseChangelog(changelogFile).then((result) => { | ||
const unreleased = result.versions.find((entry) => entry.version === null); | ||
|
||
if (!unreleased.parsed) { | ||
core.error('No unreleased section found', unreleased); | ||
return; | ||
} | ||
|
||
const parsedSections = unreleased.parsed; | ||
|
||
const hasAddedSection = parsedSections.Added && parsedSections.Added.length > 0; | ||
const hasChangedSection = parsedSections.Changed && parsedSections.Changed.length > 0; | ||
const hasRemovedSection = parsedSections.Removed && parsedSections.Removed.length > 0; | ||
|
||
const hasFixedSection = parsedSections.Fixed && parsedSections.Fixed.length > 0; | ||
const hasSecurityEntries = parsedSections.Security && parsedSections.Security.length > 0; | ||
const hasDeprecatedEntries = parsedSections.Deprecated && parsedSections.Deprecated.length > 0; | ||
|
||
if (hasAddedSection || hasChangedSection || hasRemovedSection) { | ||
const version = semver.inc(currentVersion, 'minor'); | ||
core.info(`Increase version from ${currentVersion} to ${version}`); | ||
return version; | ||
} else if (hasFixedSection || hasSecurityEntries || hasDeprecatedEntries) { | ||
const version = semver.inc(currentVersion, 'patch'); | ||
core.info(`Increase version from ${currentVersion} to ${version}`); | ||
return version; | ||
} else { | ||
core.error('No valid entries to release', unreleased); | ||
} | ||
}); | ||
} |
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,71 @@ | ||
name: Release new version | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# The Yospace private npm registry seems to not support NPM token so we sadly need to use password and email | ||
- name: Log in to Yospace private NPM registry | ||
run: | | ||
cp .npmrc ~/.npmrc | ||
echo "//yospacerepo.jfrog.io/artifactory/api/npm/javascript-sdk/:_password=${{ secrets.NPM_YOSPACE_PASS }}" >> ~/.npmrc | ||
echo "//yospacerepo.jfrog.io/artifactory/api/npm/javascript-sdk/:username=${{ secrets.NPM_YOSPACE_USER }}" >> ~/.npmrc | ||
echo "//yospacerepo.jfrog.io/artifactory/api/npm/javascript-sdk/:email=${{ secrets.NPM_YOSPACE_EMAIL }}" >> ~/.npmrc | ||
- name: Set up node.js | ||
uses: actions/setup-node@v3.3.0 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Read latest release version from package.json | ||
uses: actions/github-script@v6 | ||
id: read-latest-release-version | ||
with: | ||
script: | | ||
const { version } = require('./package.json') | ||
core.info(`Latest release version is ${version}`) | ||
core.setOutput('latestReleaseVersion', version) | ||
- name: Define next release version based on Changelog entries | ||
uses: actions/github-script@v6 | ||
id: define-release-version | ||
with: | ||
script: | | ||
const { defineReleaseVersion } = require('./.github/scripts/defineVersion.js') | ||
return defineReleaseVersion({core}, "${{ steps.define-package-json-version.outputs.packageJsonVersion }}", './CHANGELOG.md' ) | ||
- name: Bump package.json and Changelog version and tag commit | ||
run: | | ||
git config --global user.name 'Automated Release' | ||
git config --global user.email 'release-automation@bitmovin.com' | ||
npm version "${{ fromJson(steps.define-release-version.outputs.result) }}" | ||
kacl release | ||
- name: Push changes | ||
run: | | ||
git add . | ||
git commit -m "Bump version and update changelog" | ||
git push origin develop | ||
git push origin --tags | ||
- name: build and publish | ||
run: | | ||
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc | ||
npm run publish |
Oops, something went wrong.