Skip to content

Commit

Permalink
Merge pull request #172 from bitmovin/feature/automate-release
Browse files Browse the repository at this point in the history
Automate release
  • Loading branch information
dweinber committed Mar 29, 2024
2 parents 2c95f3c + 63e0b36 commit 3aa3cbe
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 78 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/defineVersion.js
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);
}
});
}
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
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
Loading

0 comments on commit 3aa3cbe

Please sign in to comment.