diff --git a/scripts/semantic-commits/get-binary-release-data.js b/scripts/semantic-commits/get-binary-release-data.js index be265cd1ae8f..82651189e5c9 100644 --- a/scripts/semantic-commits/get-binary-release-data.js +++ b/scripts/semantic-commits/get-binary-release-data.js @@ -7,7 +7,11 @@ const { getCurrentReleaseData } = require('./get-current-release-data') const { getNextVersionForBinary } = require('../get-next-version') const { getLinkedIssues } = require('./get-linked-issues') -const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }) +if (process.env.CIRCLECI && !process.env.GH_TOKEN) { + throw new Error('The GITHUB_TOKEN env is not set.') +} + +const octokit = new Octokit({ auth: process.env.GH_TOKEN }) /** * Get the list of file names that have been added, deleted or changed since the git diff --git a/scripts/semantic-commits/parse-changelog.js b/scripts/semantic-commits/parse-changelog.js index b05c661086b0..786b61c62f70 100644 --- a/scripts/semantic-commits/parse-changelog.js +++ b/scripts/semantic-commits/parse-changelog.js @@ -2,12 +2,7 @@ const fs = require('fs') const path = require('path') const { userFacingChanges } = require('./change-categories') - -const isValidSection = (section) => { - return Object.values(userFacingChanges).some((set) => { - return set.section === section - }) -} +const userFacingSections = Object.values(userFacingChanges).map(({ section }) => section) async function parseChangelog (pendingRelease = true) { const changelog = fs.readFileSync(path.join(__dirname, '..', '..', 'cli', 'CHANGELOG.md'), 'utf8') @@ -38,35 +33,39 @@ async function parseChangelog (pendingRelease = true) { if (index === 1) { if (!/^## \d+\.\d+\.\d+/.test(line)) { - throw new Error(`Expected line number ${index} to include "## x.x.x"`) + throw new Error(`Expected line number ${index + 1} to include "## x.x.x"`) } sections['version'] = line } else if (index === 3) { nextKnownLineBreak = index + 1 if (pendingRelease && !/_Released \d+\/\d+\/\d+ \(PENDING\)_/.test(line)) { - throw new Error(`Expected line number ${index} to include "_Released xx/xx/xxxx (PENDING)_"`) + throw new Error(`Expected line number ${index + 1} to include "_Released xx/xx/xxxx (PENDING)_"`) } else if (!pendingRelease && !/_Released \d+\/\d+\/\d+__/.test(line)) { - throw new Error(`Expected line number ${index} to include "_Released xx/xx/xxxx_"`) + throw new Error(`Expected line number ${index + 1} to include "_Released xx/xx/xxxx_"`) } sections['releaseDate'] = line } else if (index === nextKnownLineBreak) { if (line !== '') { - throw new Error(`Expected line number ${index} to be a line break`) + throw new Error(`Expected line number ${index + 1} to be a line break`) } } else { - const result = /\*\*([A-Z])\w+:\*\*/.exec(line) + const result = /\*\*.+?:\*\*/.exec(line) + + if (currentSection === '' && !result) { + throw new Error(`Expected line number ${index + 1} to be a valid section header. Received ${line}. Expected one of ...\n - ${userFacingSections.join('\n - ')}`) + } if (result) { const section = result[0] - if (!isValidSection(section)) { - throw new Error(`Expected line number ${index} to be a valid section header. Received ${section}. Expected one of ...`) + if (!userFacingSections.includes(section)) { + throw new Error(`Expected line number ${index + 1} to be a valid section header. Received ${section}. Expected one of ...\n - ${userFacingSections.join('\n - ')}`) } if (result === currentSection || sections[section]) { - throw new Error(`Duplicate section header of "${section}" on line number ${index}. Condense change content under a single section header.`) + throw new Error(`Duplicate section header of "${section}" on line number ${index + 1}. Condense change content under a single section header.`) } if (currentSection !== '') { diff --git a/scripts/semantic-commits/validate-binary-changelog.js b/scripts/semantic-commits/validate-binary-changelog.js index 865d2b557346..a4fd625d3c0d 100644 --- a/scripts/semantic-commits/validate-binary-changelog.js +++ b/scripts/semantic-commits/validate-binary-changelog.js @@ -12,7 +12,7 @@ const changelog = async () => { const hasVersionBump = checkedInBinaryVersion !== latestReleaseInfo.version - if (process.env.CIRCLE_BRANCH !== 'develop' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) { + if (process.env.CIRCLE_BRANCH !== 'develop' && process.env.CIRCLE_BRANCH !== 'emily/changelog2' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) { console.log('Only verify the entire changelog for develop, a release branch or any branch that bumped to the Cypress version in the package.json.') return