Improve script to version changelog

This commit is contained in:
Francisco Giordano
2020-11-17 18:50:10 -03:00
parent b33372cc92
commit 5803e11663
2 changed files with 11 additions and 3 deletions

View File

@ -17,7 +17,7 @@ current_version() {
current_release_branch() { current_release_branch() {
v="$(current_version)" v="$(current_version)"
echo "release-${v%%-"$PRERELEASE_SUFFIX".*}" echo "release-${v%.*-"$PRERELEASE_SUFFIX".*}"
} }
assert_current_branch() { assert_current_branch() {

View File

@ -6,6 +6,8 @@
const fs = require('fs'); const fs = require('fs');
const cp = require('child_process'); const cp = require('child_process');
const suffix = process.env.PRERELEASE_SUFFIX || 'rc';
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
// The changelog entry to be updated looks like this: // The changelog entry to be updated looks like this:
@ -13,15 +15,21 @@ const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
// We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this: // We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this:
// ## 2.5.3 (2019-04-25) // ## 2.5.3 (2019-04-25)
const pkg = require('../../package.json');
const version = pkg.version.replace(new RegExp('-' + suffix + '\\..*'), '');
const unreleased = /^## Unreleased$/im; const unreleased = /^## Unreleased$/im;
const released = new RegExp(`^## ${version} \\([-\\d]*\\)$`, 'm');
if (released.test(changelog)) {
process.exit(0);
}
if (!unreleased.test(changelog)) { if (!unreleased.test(changelog)) {
console.error('Missing changelog entry'); console.error('Missing changelog entry');
process.exit(1); process.exit(1);
} }
const { version } = require('../../package.json');
fs.writeFileSync('CHANGELOG.md', changelog.replace( fs.writeFileSync('CHANGELOG.md', changelog.replace(
unreleased, unreleased,
`## ${version} (${new Date().toISOString().split('T')[0]})`), `## ${version} (${new Date().toISOString().split('T')[0]})`),