Skip to content

Commit 6f1653c

Browse files
chore: fix changlelog section parsing and reference right ENV (#25633)
1 parent 660ff67 commit 6f1653c

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

scripts/semantic-commits/get-binary-release-data.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const { getCurrentReleaseData } = require('./get-current-release-data')
77
const { getNextVersionForBinary } = require('../get-next-version')
88
const { getLinkedIssues } = require('./get-linked-issues')
99

10-
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
10+
if (process.env.CIRCLECI && !process.env.GH_TOKEN) {
11+
throw new Error('The GITHUB_TOKEN env is not set.')
12+
}
13+
14+
const octokit = new Octokit({ auth: process.env.GH_TOKEN })
1115

1216
/**
1317
* Get the list of file names that have been added, deleted or changed since the git

scripts/semantic-commits/parse-changelog.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
const fs = require('fs')
33
const path = require('path')
44
const { userFacingChanges } = require('./change-categories')
5-
6-
const isValidSection = (section) => {
7-
return Object.values(userFacingChanges).some((set) => {
8-
return set.section === section
9-
})
10-
}
5+
const userFacingSections = Object.values(userFacingChanges).map(({ section }) => section)
116

127
async function parseChangelog (pendingRelease = true) {
138
const changelog = fs.readFileSync(path.join(__dirname, '..', '..', 'cli', 'CHANGELOG.md'), 'utf8')
@@ -38,35 +33,39 @@ async function parseChangelog (pendingRelease = true) {
3833

3934
if (index === 1) {
4035
if (!/^## \d+\.\d+\.\d+/.test(line)) {
41-
throw new Error(`Expected line number ${index} to include "## x.x.x"`)
36+
throw new Error(`Expected line number ${index + 1} to include "## x.x.x"`)
4237
}
4338

4439
sections['version'] = line
4540
} else if (index === 3) {
4641
nextKnownLineBreak = index + 1
4742
if (pendingRelease && !/_Released \d+\/\d+\/\d+ \(PENDING\)_/.test(line)) {
48-
throw new Error(`Expected line number ${index} to include "_Released xx/xx/xxxx (PENDING)_"`)
43+
throw new Error(`Expected line number ${index + 1} to include "_Released xx/xx/xxxx (PENDING)_"`)
4944
} else if (!pendingRelease && !/_Released \d+\/\d+\/\d+__/.test(line)) {
50-
throw new Error(`Expected line number ${index} to include "_Released xx/xx/xxxx_"`)
45+
throw new Error(`Expected line number ${index + 1} to include "_Released xx/xx/xxxx_"`)
5146
}
5247

5348
sections['releaseDate'] = line
5449
} else if (index === nextKnownLineBreak) {
5550
if (line !== '') {
56-
throw new Error(`Expected line number ${index} to be a line break`)
51+
throw new Error(`Expected line number ${index + 1} to be a line break`)
5752
}
5853
} else {
59-
const result = /\*\*([A-Z])\w+:\*\*/.exec(line)
54+
const result = /\*\*.+?:\*\*/.exec(line)
55+
56+
if (currentSection === '' && !result) {
57+
throw new Error(`Expected line number ${index + 1} to be a valid section header. Received ${line}. Expected one of ...\n - ${userFacingSections.join('\n - ')}`)
58+
}
6059

6160
if (result) {
6261
const section = result[0]
6362

64-
if (!isValidSection(section)) {
65-
throw new Error(`Expected line number ${index} to be a valid section header. Received ${section}. Expected one of ...`)
63+
if (!userFacingSections.includes(section)) {
64+
throw new Error(`Expected line number ${index + 1} to be a valid section header. Received ${section}. Expected one of ...\n - ${userFacingSections.join('\n - ')}`)
6665
}
6766

6867
if (result === currentSection || sections[section]) {
69-
throw new Error(`Duplicate section header of "${section}" on line number ${index}. Condense change content under a single section header.`)
68+
throw new Error(`Duplicate section header of "${section}" on line number ${index + 1}. Condense change content under a single section header.`)
7069
}
7170

7271
if (currentSection !== '') {

scripts/semantic-commits/validate-binary-changelog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const changelog = async () => {
1212

1313
const hasVersionBump = checkedInBinaryVersion !== latestReleaseInfo.version
1414

15-
if (process.env.CIRCLE_BRANCH !== 'develop' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) {
15+
if (process.env.CIRCLE_BRANCH !== 'develop' && process.env.CIRCLE_BRANCH !== 'emily/changelog2' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) {
1616
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.')
1717

1818
return

0 commit comments

Comments
 (0)