-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
test: add test to validate changelogs for releases #45325
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| 'use strict'; | ||
|
|
||
| // This test checks that the changelogs contain an entry for releases. | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const getDefine = (text, name) => { | ||
| const regexp = new RegExp(`#define\\s+${name}\\s+(.*)`); | ||
| const match = regexp.exec(text); | ||
| assert.notStrictEqual(match, null); | ||
| return match[1]; | ||
| }; | ||
|
|
||
| const srcRoot = path.join(__dirname, '..', '..'); | ||
RafaelGSS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const mainChangelogFile = path.join(srcRoot, 'CHANGELOG.md'); | ||
| const versionFile = path.join(srcRoot, 'src', 'node_version.h'); | ||
| const versionText = fs.readFileSync(versionFile, { encoding: 'utf8' }); | ||
| const release = getDefine(versionText, 'NODE_VERSION_IS_RELEASE') !== '0'; | ||
|
|
||
| if (!release) { | ||
| common.skip('release bit is not set'); | ||
| } | ||
|
|
||
| const major = getDefine(versionText, 'NODE_MAJOR_VERSION'); | ||
| const minor = getDefine(versionText, 'NODE_MINOR_VERSION'); | ||
| const patch = getDefine(versionText, 'NODE_PATCH_VERSION'); | ||
| const versionForRegex = `${major}\\.${minor}\\.${patch}`; | ||
|
|
||
| const lts = getDefine(versionText, 'NODE_VERSION_IS_LTS') !== '0'; | ||
| const codename = getDefine(versionText, 'NODE_VERSION_LTS_CODENAME').slice(1, -1); | ||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // If the LTS bit is set there should be a codename. | ||
| if (lts) { | ||
| assert.notStrictEqual(codename, ''); | ||
| } | ||
|
|
||
| const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`; | ||
| // Check CHANGELOG_V*.md | ||
| { | ||
| const changelog = fs.readFileSync(path.join(srcRoot, changelogPath), { encoding: 'utf8' }); | ||
| // Check title matches major version. | ||
| assert.match(changelog, new RegExp(`# Node\\.js ${major} ChangeLog`)); | ||
| // Check table header | ||
| let tableHeader; | ||
| if (lts) { | ||
| tableHeader = new RegExp(`<th>LTS '${codename}'</th>`); | ||
| } else { | ||
| tableHeader = /<th>Current<\/th>/; | ||
| } | ||
| assert.match(changelog, tableHeader); | ||
| // Check table contains link to this release. | ||
| assert.match(changelog, new RegExp(`<a href="#${versionForRegex}">${versionForRegex}</a>`)); | ||
| // Check anchor for this release. | ||
| assert.match(changelog, new RegExp(`<a id="${versionForRegex}"></a>`)); | ||
| // Check title for changelog entry. | ||
| let title; | ||
| if (lts) { | ||
| title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${codename}' \\(LTS\\), @\\S+`); | ||
| } else { | ||
| title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} \\(Current\\), @\\S+`); | ||
| } | ||
| assert.match(changelog, title); | ||
| } | ||
|
|
||
| // Main CHANGELOG.md checks | ||
| { | ||
| const mainChangelog = fs.readFileSync(mainChangelogFile, { encoding: 'utf8' }); | ||
| // Check for the link to the appropriate CHANGELOG_V*.md file. | ||
| let linkToChangelog; | ||
| if (lts) { | ||
| linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Long Term Support\\*\\*`); | ||
| } else { | ||
| linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Current\\*\\*`); | ||
| } | ||
| assert.match(mainChangelog, linkToChangelog); | ||
| // Check table header. | ||
| let tableHeader; | ||
| if (lts) { | ||
| tableHeader = new RegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${changelogPath}">${major}</a> \\(LTS\\)</th>`); | ||
| } else { | ||
| tableHeader = new RegExp(`<th title="Current"><a href="${changelogPath}">${major}</a> \\(Current\\)</th>`); | ||
| } | ||
| assert.match(mainChangelog, tableHeader); | ||
| // Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file. | ||
| const linkToVersion = new RegExp(`<b><a href="${changelogPath}#${versionForRegex}">${versionForRegex}</a></b><br/>`); | ||
| assert.match(mainChangelog, linkToVersion); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.