From 3267e34e52293083d66c55d43843e7d53c4861a9 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 4 Nov 2022 22:14:50 -0400 Subject: [PATCH 1/2] test: add test to validate changelogs for releases Add a new test to check that the changelog files have been correctly updated for releases. --- test/parallel/test-release-changelog.js | 89 +++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/parallel/test-release-changelog.js diff --git a/test/parallel/test-release-changelog.js b/test/parallel/test-release-changelog.js new file mode 100644 index 00000000000000..0e782cedc86d92 --- /dev/null +++ b/test/parallel/test-release-changelog.js @@ -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, '..', '..'); +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 version = `${major}.${minor}.${patch}`; + +const lts = getDefine(versionText, 'NODE_VERSION_IS_LTS') !== '0'; +const codename = getDefine(versionText, 'NODE_VERSION_LTS_CODENAME').slice(1, -1); +// 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(`LTS '${codename}'`); + } else { + tableHeader = /Current<\/th>/; + } + assert.match(changelog, tableHeader); + // Check table contains link to this release. + assert.match(changelog, new RegExp(`${version}`)); + // Check anchor for this release. + assert.match(changelog, new RegExp(``)); + // Check title for changelog entry. + let title; + if (lts) { + title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${version} '${codename}' \\(LTS\\), @\\S+`); + } else { + title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${version} \\(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(`${major} \\(LTS\\)`); + } else { + tableHeader = new RegExp(`${major} \\(Current\\)`); + } + assert.match(mainChangelog, tableHeader); + // Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file. + const linkToVersion = new RegExp(`${version}
`); + assert.match(mainChangelog, linkToVersion); +} From a2c47c9328d441957499982b8c89b183eb3c40c2 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 4 Nov 2022 23:02:38 -0400 Subject: [PATCH 2/2] fixup! test: add test to validate changelogs for releases --- test/parallel/test-release-changelog.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-release-changelog.js b/test/parallel/test-release-changelog.js index 0e782cedc86d92..99889fa1724014 100644 --- a/test/parallel/test-release-changelog.js +++ b/test/parallel/test-release-changelog.js @@ -27,7 +27,7 @@ if (!release) { const major = getDefine(versionText, 'NODE_MAJOR_VERSION'); const minor = getDefine(versionText, 'NODE_MINOR_VERSION'); const patch = getDefine(versionText, 'NODE_PATCH_VERSION'); -const version = `${major}.${minor}.${patch}`; +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); @@ -51,15 +51,15 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`; } assert.match(changelog, tableHeader); // Check table contains link to this release. - assert.match(changelog, new RegExp(`${version}`)); + assert.match(changelog, new RegExp(`${versionForRegex}`)); // Check anchor for this release. - assert.match(changelog, new RegExp(``)); + assert.match(changelog, new RegExp(``)); // Check title for changelog entry. let title; if (lts) { - title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${version} '${codename}' \\(LTS\\), @\\S+`); + 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 ${version} \\(Current\\), @\\S+`); + title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} \\(Current\\), @\\S+`); } assert.match(changelog, title); } @@ -84,6 +84,6 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`; } assert.match(mainChangelog, tableHeader); // Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file. - const linkToVersion = new RegExp(`${version}
`); + const linkToVersion = new RegExp(`${versionForRegex}
`); assert.match(mainChangelog, linkToVersion); }