Skip to content

Commit 1aa9f90

Browse files
authored
chore: update validate changelog to pull target branch (#32561)
1 parent 784a094 commit 1aa9f90

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

.github/workflows/semantic-pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
- name: Checkout
3535
uses: actions/checkout@v4
3636
with:
37-
ref: ${{ github.event.pull_request.head.ref }}
38-
repository: ${{ github.event.pull_request.head.repo.full_name }}
37+
ref: ${{ github.event.pull_request.base.ref }}
38+
repository: ${{ github.event.pull_request.base.repo.full_name }}
3939
- run: npm install
4040
working-directory: scripts/github-actions/semantic-pull-request/
4141
- name: Lint PR Title and Cypress Changelog Entry

scripts/github-actions/semantic-pull-request/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,22 @@ async function run ({ context, core, github }) {
4545

4646
const changedFiles = data.map((fileDetails) => fileDetails.filename)
4747

48+
// retrieve the changelog content from the pull request
49+
let changelogContent = null
50+
51+
if (changedFiles.includes('cli/CHANGELOG.md')) {
52+
const { data: changelogData } = await github.rest.repos.getContent({
53+
owner: contextPullRequest.head.user.login,
54+
repo: contextPullRequest.head.repo.name,
55+
path: 'cli/CHANGELOG.md',
56+
ref: contextPullRequest.head.sha,
57+
})
58+
59+
changelogContent = Buffer.from(changelogData.content, 'base64').toString('utf8')
60+
}
61+
4862
await validateChangelog({
63+
changelogContent,
4964
changedFiles,
5065
commits: [{
5166
commitMessage: header,

scripts/semantic-commits/parse-changelog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const path = require('path')
33
const { userFacingChanges } = require('./change-categories')
44
const userFacingSections = Object.values(userFacingChanges).map(({ section }) => section)
55

6-
async function parseChangelog (pendingRelease = true) {
7-
const changelog = fs.readFileSync(path.join(__dirname, '..', '..', 'cli', 'CHANGELOG.md'), 'utf8')
6+
async function parseChangelog ({ pendingRelease = true, changelogContent = null } = {}) {
7+
const changelog = changelogContent || fs.readFileSync(path.join(__dirname, '..', '..', 'cli', 'CHANGELOG.md'), 'utf8')
88
const changeLogLines = changelog.split('\n')
99

1010
let parseChangelog = true

scripts/semantic-commits/validate-changelog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const _handleErrors = (errors) => {
129129
* environment variable in CircleCI to a branch or comma-separated list of
130130
* branches
131131
*/
132-
async function validateChangelog ({ changedFiles, nextVersion, pendingRelease, commits }) {
132+
async function validateChangelog ({ changedFiles, nextVersion, pendingRelease, commits, changelogContent }) {
133133
if (process.env.SKIP_RELEASE_CHANGELOG_VALIDATION_FOR_BRANCHES) {
134134
const branches = process.env.SKIP_RELEASE_CHANGELOG_VALIDATION_FOR_BRANCHES.split(',')
135135

@@ -171,7 +171,7 @@ async function validateChangelog ({ changedFiles, nextVersion, pendingRelease, c
171171
}
172172
}
173173

174-
const changelog = await parseChangelog(pendingRelease)
174+
const changelog = await parseChangelog({ pendingRelease, changelogContent })
175175

176176
if (nextVersion && !changelog.version === `## ${nextVersion}`) {
177177
errors.push(`The changelog version does not contain the next Cypress version of ${nextVersion}. If the changelog version is correct, please correct the pull request title to correctly reflect the change being made.`)

scripts/unit/semantic-commits/validate-changelog-spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,33 @@ _Released 01/17/2033 (PENDING)_
160160
expect(console.log).to.be.calledWith('It appears at a high-level your changelog entry is correct! The remaining validation is left to the pull request reviewers.')
161161
})
162162

163+
it('verifies changelog entry has been included when the changelog is passed in', async () => {
164+
const changedFiles = [
165+
'packages/driver/lib/index.js',
166+
'cli/CHANGELOG.md',
167+
]
168+
169+
const changelogContent = `
170+
## 120.2.0
171+
172+
_Released 01/17/2033 (PENDING)_
173+
174+
**Performance:**
175+
176+
- Fixed in [#77](https://github.com/cypress-io/cypress/pull/77).`
177+
178+
await validateChangelog({
179+
changelogContent,
180+
changedFiles,
181+
commits: [{
182+
prNumber: 77,
183+
semanticType: 'perf',
184+
}],
185+
})
186+
187+
expect(console.log).to.be.calledWith('It appears at a high-level your changelog entry is correct! The remaining validation is left to the pull request reviewers.')
188+
})
189+
163190
it('verifies changelog with shared entry', async () => {
164191
const changedFiles = [
165192
'packages/driver/lib/index.js',

0 commit comments

Comments
 (0)