From 0c410df2e97dfee6b426e3eea557eefe90f92c53 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Wed, 24 Jul 2024 02:32:04 +0200 Subject: [PATCH 1/4] Add packages name modified next to commit in CHANGELOG --- scripts/release/generate-changelog.js | 93 ++++++++++++++++++- .../update-peer-dependency-versions.js | 4 +- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 411a6c8fe0..546d3eaf0f 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -1,6 +1,8 @@ 'use strict' const util = require('util') +const fs = require('fs') +const { readdirSync } = require('fs') const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') @@ -13,7 +15,6 @@ const { modifyFile } = require('../lib/files-utils') const CHANGELOG_FILE = 'CHANGELOG.md' const CONTRIBUTING_FILE = 'CONTRIBUTING.md' const PUBLIC_EMOJI_PRIORITY = ['💥', '✨', '🐛', '⚡', '📝'] - const INTERNAL_EMOJI_PRIORITY = [ '👷', '🔧', @@ -29,6 +30,22 @@ const INTERNAL_EMOJI_PRIORITY = [ '⚗️', // experiment ] const EMOJI_REGEX = /^\p{Emoji_Presentation}/u + +const PACKAGES_DIRECTORY_NAMES = readdirSync('packages') + +const PACKAGES_REVERSE_DEPENDENCIES = (() => { + const result = new Map() + PACKAGES_DIRECTORY_NAMES.forEach((packageDirectoryName) => { + for (const dependency of getDepenciesRecursively(packageDirectoryName)) { + if (!result.has(dependency)) { + result.set(dependency, new Set()) + } + result.get(dependency).add(packageDirectoryName) + } + }) + return result +})() + runMain(async () => { if (!process.env.EDITOR) { printError('Please configure your environment variable EDITOR') @@ -88,7 +105,7 @@ function getChangesList() { const lastTagHash = command`git rev-list --tags --max-count=1`.run().trim() const lastTagName = command`git describe --tags ${lastTagHash}`.run() - const commits = command`git log ${lastTagName.trimEnd()}..HEAD --pretty=format:%s`.run() + const commits = command`git log ${[`${lastTagName.trimEnd()}..HEAD`, '--pretty=format:%H %s']}`.run() const changesWithEmojis = emojiNameToUnicode(commits) let changes = changesWithEmojis.split('\n').filter(isNotVersionEntry) @@ -97,10 +114,18 @@ function getChangesList() { changes.forEach((entry) => { let trimmedEntry = entry.trim() - if (PUBLIC_EMOJI_PRIORITY.some((emoji) => trimmedEntry.startsWith(emoji))) { - publicChanges.push(entry) + const hash = trimmedEntry.split(' ')[0] + const message = trimmedEntry.slice(trimmedEntry.indexOf(' ') + 1) + const affectedPackages = getAffectedPackages(hash) + + const formattedPackages = affectedPackages + .map((packageDirectoryName) => `[${packageDirectoryName.toUpperCase()}]`) + .join(' ') + + if (PUBLIC_EMOJI_PRIORITY.some((emoji) => message.startsWith(emoji))) { + publicChanges.push(`${message} ${formattedPackages}`) } else { - internalChanges.push(entry) + internalChanges.push(`${message} ${formattedPackages}`) } }) @@ -120,6 +145,38 @@ ${internalChanges.join('\n')} `.replace(/\(#(\d+)\)/gm, (_, id) => `([#${id}](https://github.com/DataDog/browser-sdk/pull/${id}))`) } +function getAffectedPackages(hash) { + const changedFiles = command`git diff-tree --no-commit-id --name-only -r ${hash}`.run().trim().split('\n') + const affectedPackages = new Set() + + changedFiles.forEach((filePath) => { + const packageDirectoryName = getPackageDirectoryNameFromFilePath(filePath) + if (packageDirectoryName) { + if (!isToplevelPackage(packageDirectoryName)) { + PACKAGES_REVERSE_DEPENDENCIES.get(packageDirectoryName).forEach((dependentPackageDirectoryName) => { + if (isToplevelPackage(dependentPackageDirectoryName)) { + affectedPackages.add(dependentPackageDirectoryName) + } + }) + } else { + affectedPackages.add(packageDirectoryName) + } + } + }) + + return Array.from(affectedPackages) +} + +function getPackageDirectoryNameFromFilePath(filePath) { + if (filePath.startsWith('packages/')) { + return filePath.split('/')[1] + } +} + +function isToplevelPackage(packageDirectoryName) { + return !PACKAGES_REVERSE_DEPENDENCIES.has(packageDirectoryName) +} + function sortByEmojiPriority(a, b, priorityList) { const getFirstRelevantEmojiIndex = (text) => { const matches = text.match(EMOJI_REGEX) || [] @@ -137,3 +194,29 @@ function emojiNameToUnicode(changes) { function isNotVersionEntry(line) { return !/^v\d+\.\d+\.\d+/.test(line) } +function getPackageDirectoryNameFromPackageName(packageName) { + if (packageName.startsWith('@datadog/browser-')) { + return packageName.slice('@datadog/browser-'.length) + } +} + +function getDepenciesRecursively(packageDirectoryName) { + const packageDirectoryNameJson = JSON.parse( + fs.readFileSync(`packages/${packageDirectoryName}/package.json`, { encoding: 'utf-8' }) + ) + const dependencies = new Set() + if (packageDirectoryNameJson.dependencies) { + for (const dependencyPackageName of Object.keys(packageDirectoryNameJson.dependencies)) { + const packageDirectoryName = getPackageDirectoryNameFromPackageName(dependencyPackageName) + dependencies.add(packageDirectoryName) + for (let transitiveDependency of getDepenciesRecursively(packageDirectoryName)) { + dependencies.add(transitiveDependency) + } + } + } + return dependencies +} + +module.exports = { + packagesDirectoryNames: PACKAGES_DIRECTORY_NAMES, +} diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index cdfea976b7..f46fd65a0b 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -1,10 +1,10 @@ -const { readdirSync } = require('fs') const { runMain } = require('../lib/execution-utils') const { modifyFile } = require('../lib/files-utils') const { command } = require('../lib/command') const { browserSdkVersion } = require('../lib/browser-sdk-version') +const { packagesDirectoryNames } = require('./generate-changelog') -const JSON_FILES = readdirSync('./packages').map((packageName) => `./packages/${packageName}/package.json`) +const JSON_FILES = packagesDirectoryNames.map((packageName) => `./packages/${packageName}/package.json`) // This script updates the peer dependency versions between rum and logs packages to match the new // version during a release. From ee9d076855d0e307f438fb9f403d8c225e6e168b Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Wed, 24 Jul 2024 12:19:27 +0200 Subject: [PATCH 2/4] factorize package name --- scripts/release/generate-changelog.js | 10 ++-------- scripts/release/packages-directory-names.js | 6 ++++++ scripts/release/update-peer-dependency-versions.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 scripts/release/packages-directory-names.js diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 546d3eaf0f..09fc70be87 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -2,7 +2,6 @@ const util = require('util') const fs = require('fs') -const { readdirSync } = require('fs') const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') @@ -11,6 +10,7 @@ const { browserSdkVersion } = require('../lib/browser-sdk-version') const { spawnCommand, printError, runMain } = require('../lib/execution-utils') const { command } = require('../lib/command') const { modifyFile } = require('../lib/files-utils') +const { packagesDirectoryNames } = require('./packages-directory-names') const CHANGELOG_FILE = 'CHANGELOG.md' const CONTRIBUTING_FILE = 'CONTRIBUTING.md' @@ -31,11 +31,9 @@ const INTERNAL_EMOJI_PRIORITY = [ ] const EMOJI_REGEX = /^\p{Emoji_Presentation}/u -const PACKAGES_DIRECTORY_NAMES = readdirSync('packages') - const PACKAGES_REVERSE_DEPENDENCIES = (() => { const result = new Map() - PACKAGES_DIRECTORY_NAMES.forEach((packageDirectoryName) => { + packagesDirectoryNames.forEach((packageDirectoryName) => { for (const dependency of getDepenciesRecursively(packageDirectoryName)) { if (!result.has(dependency)) { result.set(dependency, new Set()) @@ -216,7 +214,3 @@ function getDepenciesRecursively(packageDirectoryName) { } return dependencies } - -module.exports = { - packagesDirectoryNames: PACKAGES_DIRECTORY_NAMES, -} diff --git a/scripts/release/packages-directory-names.js b/scripts/release/packages-directory-names.js new file mode 100644 index 0000000000..bc4882fd2b --- /dev/null +++ b/scripts/release/packages-directory-names.js @@ -0,0 +1,6 @@ +const { readdirSync } = require('fs') +const PACKAGES_DIRECTORY_NAMES = readdirSync('../../packages') + +module.exports = { + packagesDirectoryNames: PACKAGES_DIRECTORY_NAMES, +} diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index f46fd65a0b..e1fa521378 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -2,7 +2,7 @@ const { runMain } = require('../lib/execution-utils') const { modifyFile } = require('../lib/files-utils') const { command } = require('../lib/command') const { browserSdkVersion } = require('../lib/browser-sdk-version') -const { packagesDirectoryNames } = require('./generate-changelog') +const { packagesDirectoryNames } = require('./packages-directory-names') const JSON_FILES = packagesDirectoryNames.map((packageName) => `./packages/${packageName}/package.json`) From b1d1008508a2553707d0fb31f21c3c028b5ed6d7 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Wed, 24 Jul 2024 12:20:35 +0200 Subject: [PATCH 3/4] change path packages --- scripts/release/packages-directory-names.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release/packages-directory-names.js b/scripts/release/packages-directory-names.js index bc4882fd2b..462c5292d5 100644 --- a/scripts/release/packages-directory-names.js +++ b/scripts/release/packages-directory-names.js @@ -1,5 +1,5 @@ const { readdirSync } = require('fs') -const PACKAGES_DIRECTORY_NAMES = readdirSync('../../packages') +const PACKAGES_DIRECTORY_NAMES = readdirSync('packages') module.exports = { packagesDirectoryNames: PACKAGES_DIRECTORY_NAMES, From b2607f6597bafeebc6d942c2d6ce4120e6687181 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Thu, 25 Jul 2024 11:49:20 +0200 Subject: [PATCH 4/4] update folder for package directory name --- scripts/{release => lib}/packages-directory-names.js | 0 scripts/release/generate-changelog.js | 2 +- scripts/release/update-peer-dependency-versions.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename scripts/{release => lib}/packages-directory-names.js (100%) diff --git a/scripts/release/packages-directory-names.js b/scripts/lib/packages-directory-names.js similarity index 100% rename from scripts/release/packages-directory-names.js rename to scripts/lib/packages-directory-names.js diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 09fc70be87..ab15d5fa2d 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -10,7 +10,7 @@ const { browserSdkVersion } = require('../lib/browser-sdk-version') const { spawnCommand, printError, runMain } = require('../lib/execution-utils') const { command } = require('../lib/command') const { modifyFile } = require('../lib/files-utils') -const { packagesDirectoryNames } = require('./packages-directory-names') +const { packagesDirectoryNames } = require('../lib/packages-directory-names') const CHANGELOG_FILE = 'CHANGELOG.md' const CONTRIBUTING_FILE = 'CONTRIBUTING.md' diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index e1fa521378..c6d63dad6e 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -2,7 +2,7 @@ const { runMain } = require('../lib/execution-utils') const { modifyFile } = require('../lib/files-utils') const { command } = require('../lib/command') const { browserSdkVersion } = require('../lib/browser-sdk-version') -const { packagesDirectoryNames } = require('./packages-directory-names') +const { packagesDirectoryNames } = require('../lib/packages-directory-names') const JSON_FILES = packagesDirectoryNames.map((packageName) => `./packages/${packageName}/package.json`)