Skip to content

Commit

Permalink
Update version based on change log fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 18, 2023
1 parent b413520 commit 18ab2ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internals/scripts/changelog.js
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' })
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lint-git": "node ./internals/scripts/gitlint.js",
"lint-docs": "markdownlint --ignore '**/node_modules/**' '**/*.md'",
"lint-changelog": "markdownlint --config .changelog/.markdownlint.yml .changelog/",
"changelog": "node ./internals/scripts/changelog.js",
"release-tag": "node ./internals/scripts/release-tag.js",
"extract-messages": "rm src/locales/en/translation.json && i18next-scanner --config=internals/extractMessages/i18next-scanner.config.js",
"fix-grommet-icons-types": "node ./internals/scripts/fix-grommet-icons-types.js",
Expand Down

0 comments on commit 18ab2ce

Please sign in to comment.