Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix changlelog section parsing and reference right ENV #25633

Merged
merged 5 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/semantic-commits/get-binary-release-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions scripts/semantic-commits/parse-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 !== '') {
Expand Down
2 changes: 1 addition & 1 deletion scripts/semantic-commits/validate-binary-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down