-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version based on change log fragments
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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,37 @@ | ||
const execSync = require('child_process').execSync | ||
const semver = require('semver') | ||
const glob = require('glob') | ||
const packageJson = require('../../package.json') | ||
|
||
const folderPath = '.changelog/' | ||
const majorPattern = `${folderPath}*breaking*.md` | ||
const minorPattern = `${folderPath}*feature*.md` | ||
const patchPattern = `${folderPath}*{process,cfg,bugfix,doc,internal,trivial}*.md` | ||
|
||
console.log('Assembling Change Log and updating package version') | ||
|
||
let version = packageJson.version | ||
if (glob.sync(majorPattern).length > 0) { | ||
console.log('\x1b[31m%s\x1b[0m', 'Warning: This release contains breaking changes.') | ||
version = semver.inc(version, 'major') | ||
} else if (glob.sync(minorPattern).length > 0) { | ||
version = semver.inc(version, 'minor') | ||
} else if (glob.sync(patchPattern).length > 0) { | ||
version = semver.inc(version, 'patch') | ||
} else { | ||
console.log('No Change Log fragments found. Aborting release...') | ||
process.exit(1) | ||
} | ||
|
||
if (!semver.valid(version)) { | ||
console.log(`Invalid version: ${version}`) | ||
process.exit(1) | ||
} | ||
|
||
if (semver.lte(version, packageJson.version)) { | ||
console.log(`Version ${version} is not greater than ${packageJson.version}`) | ||
process.exit(1) | ||
} | ||
|
||
execSync(`yarn version --no-git-tag-version --new-version ${version}`, { stdio: 'inherit' }) | ||
execSync(`towncrier build --version ${version}`, { stdio: 'inherit' }) |
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