From dc75c18bdf9a5fbb24b81674ad892cceedb9550a Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 1 Apr 2021 12:28:50 -0230 Subject: [PATCH] Add changelog entries under release candidate header (#10784) Instead of always placing new changelog entries under the "Current Develop Branch" header, the changelog script now places them under the header for the current release if that release has not yet been tagged. This eliminates one manual step from the release process. Relates to #10752 --- development/auto-changelog.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/development/auto-changelog.js b/development/auto-changelog.js index 22743f32e..c032572c6 100755 --- a/development/auto-changelog.js +++ b/development/auto-changelog.js @@ -1,6 +1,8 @@ #!/usr/bin/env node const fs = require('fs').promises; +const assert = require('assert').strict; const path = require('path'); +const { version } = require('../app/manifest/_base.json'); const runCommand = require('./lib/runCommand'); const URL = 'https://github.com/MetaMask/metamask-extension'; @@ -18,6 +20,7 @@ async function main() { '--tags', mostRecentTagCommitHash, ]); + assert.equal(mostRecentTag[0], 'v', 'Most recent tag should start with v'); const commitsSinceLastRelease = await runCommand('git', [ 'rev-list', @@ -67,11 +70,28 @@ async function main() { const changelogFilename = path.resolve(__dirname, '..', 'CHANGELOG.md'); const changelog = await fs.readFile(changelogFilename, { encoding: 'utf8' }); const changelogLines = changelog.split('\n'); - const releaseHeaderIndex = changelogLines.findIndex( - (line) => line === '## Current Develop Branch', + + // remove the "v" prefix + const mostRecentVersion = mostRecentTag.slice(1); + + const isReleaseCandidate = mostRecentVersion !== version; + const versionHeader = `## ${version}`; + const currentDevelopBranchHeader = '## Current Develop Branch'; + const currentReleaseHeaderPattern = isReleaseCandidate + ? // This ensures this doesn't match on a version with a suffix + // e.g. v9.0.0 should not match on the header v9.0.0-beta.0 + `${versionHeader}$|${versionHeader}\\s` + : currentDevelopBranchHeader; + + const releaseHeaderIndex = changelogLines.findIndex((line) => + line.match(new RegExp(currentReleaseHeaderPattern, 'u')), ); if (releaseHeaderIndex === -1) { - throw new Error('Failed to find release header'); + throw new Error( + `Failed to find release header '${ + isReleaseCandidate ? versionHeader : currentDevelopBranchHeader + }'`, + ); } changelogLines.splice(releaseHeaderIndex + 1, 0, ...changelogEntries); const updatedChangelog = changelogLines.join('\n');