From ecd33a77617c7f412d6c929eb74661a13c31fd78 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Fri, 9 Feb 2024 14:04:07 +0100 Subject: [PATCH 01/21] =?UTF-8?q?=E2=9C=A8[RUM-3151]=20Report=20bundle=20s?= =?UTF-8?q?izes=20to=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ .gitlab-ci.yml | 1 + scripts/export-bundles-sizes.js | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 scripts/export-bundles-sizes.js diff --git a/.gitignore b/.gitignore index d6b930e824..289cfe6578 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ browserstack.err !.yarn/releases !.yarn/sdks !.yarn/versions + +.DS_Store +.vscode/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 857613e610..d52b36d351 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -140,6 +140,7 @@ build-and-lint: - yarn build - yarn lint - node scripts/check-packages.js + - node scripts/export-bundles-sizes.js build-bundle: extends: diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js new file mode 100644 index 0000000000..f13ecb25ec --- /dev/null +++ b/scripts/export-bundles-sizes.js @@ -0,0 +1,55 @@ +const fs = require('fs') +const path = require('path') +const childProcess = require('child_process') +const { getOrg2ApiKey } = require('./lib/secrets') +const { runMain } = require('./lib/execution-utils') +const url = 'https://http-intake.logs.datadoghq.com/api/v2/logs' +const rumPath = path.join(__dirname, '../packages/rum/bundle/datadog-rum.js') +const logsPath = path.join(__dirname, '../packages/logs/bundle/datadog-logs.js') +const rumSlimPath = path.join(__dirname, '../packages/rum-slim/bundle/datadog-rum-slim.js') +const workerPath = path.join(__dirname, '../packages/worker/bundle/worker.js') +const versionPath = path.join(__dirname, '../packages/rum/package.json') + +runMain(() => { + const logData = [ + { + message: 'Browser SDK bundles sizes', + service: 'browser-sdk', + env: 'ci', + bundle_sizes: { + rum: getBundleSize(rumPath), + logs: getBundleSize(logsPath), + rum_slim: getBundleSize(rumSlimPath), + worker: getBundleSize(workerPath), + }, + version: getVersion(), + commit: getCommitId(), + }, + ] + PostBundleSize(url, logData) +}) + +const getCommitId = () => childProcess.execSync('git rev-parse HEAD').toString().trim() + +function getVersion() { + const versionJson = fs.readFileSync(versionPath, 'utf8') + return JSON.parse(versionJson).version +} + +function getBundleSize(pathBundle) { + const file = fs.statSync(pathBundle) + return file.size +} + +function PostBundleSize(url = '', bundleData = {}) { + fetch(url, { + method: 'POST', + headers: { + 'DD-API-KEY': getOrg2ApiKey(), + 'Content-Type': 'application/json', + }, + body: JSON.stringify(bundleData), + }).catch((error) => { + throw new Error(`Fetch request failed: ${error.message}`) + }) +} From e61ca3823809f1f4897266b123e4e39d6d5ba341 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 11:00:44 +0100 Subject: [PATCH 02/21] added ddsource in request and PostBundleSize is now async --- scripts/export-bundles-sizes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index f13ecb25ec..44e0dbf001 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -15,6 +15,7 @@ runMain(() => { { message: 'Browser SDK bundles sizes', service: 'browser-sdk', + ddsource: 'browser-sdk', env: 'ci', bundle_sizes: { rum: getBundleSize(rumPath), @@ -41,15 +42,14 @@ function getBundleSize(pathBundle) { return file.size } -function PostBundleSize(url = '', bundleData = {}) { - fetch(url, { +async function PostBundleSize(url = '', bundleData = {}) { + const response = await fetch(url, { method: 'POST', headers: { 'DD-API-KEY': getOrg2ApiKey(), 'Content-Type': 'application/json', }, body: JSON.stringify(bundleData), - }).catch((error) => { - throw new Error(`Fetch request failed: ${error.message}`) }) + console.log(await response.text()) } From 46f89eabf30ace35fcba3f37d01c7b86b729e15a Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 11:07:16 +0100 Subject: [PATCH 03/21] fix lint error --- scripts/export-bundles-sizes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 44e0dbf001..28a786aeb7 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -10,7 +10,7 @@ const rumSlimPath = path.join(__dirname, '../packages/rum-slim/bundle/datadog-ru const workerPath = path.join(__dirname, '../packages/worker/bundle/worker.js') const versionPath = path.join(__dirname, '../packages/rum/package.json') -runMain(() => { +runMain(async () => { const logData = [ { message: 'Browser SDK bundles sizes', @@ -27,7 +27,7 @@ runMain(() => { commit: getCommitId(), }, ] - PostBundleSize(url, logData) + await postBundleSize(url, logData) }) const getCommitId = () => childProcess.execSync('git rev-parse HEAD').toString().trim() @@ -42,7 +42,7 @@ function getBundleSize(pathBundle) { return file.size } -async function PostBundleSize(url = '', bundleData = {}) { +async function postBundleSize(url = '', bundleData = {}) { const response = await fetch(url, { method: 'POST', headers: { From 369a184ac1e4617c26a1bf6e141e5db884f7fc2a Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 11:48:12 +0100 Subject: [PATCH 04/21] added function getGitInformation, branch name in request and error handling --- scripts/export-bundles-sizes.js | 54 +++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 28a786aeb7..8ac3c925c1 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -1,15 +1,21 @@ const fs = require('fs') const path = require('path') -const childProcess = require('child_process') +const { execSync } = require('child_process') const { getOrg2ApiKey } = require('./lib/secrets') -const { runMain } = require('./lib/execution-utils') -const url = 'https://http-intake.logs.datadoghq.com/api/v2/logs' +const { runMain, fetch: fetchWrapper } = require('./lib/execution-utils') + const rumPath = path.join(__dirname, '../packages/rum/bundle/datadog-rum.js') const logsPath = path.join(__dirname, '../packages/logs/bundle/datadog-logs.js') const rumSlimPath = path.join(__dirname, '../packages/rum-slim/bundle/datadog-rum-slim.js') const workerPath = path.join(__dirname, '../packages/worker/bundle/worker.js') const versionPath = path.join(__dirname, '../packages/rum/package.json') +const URL = 'https://http-intake.logs.datadoghq.com/api/v2/logs' +const HEADERS = { + 'DD-API-KEY': getOrg2ApiKey(), + 'Content-Type': 'application/json', +} + runMain(async () => { const logData = [ { @@ -24,32 +30,48 @@ runMain(async () => { worker: getBundleSize(workerPath), }, version: getVersion(), - commit: getCommitId(), + commit: getGitInformation('git rev-parse HEAD'), + branch: getGitInformation('git rev-parse --abbrev-ref HEAD'), }, ] - await postBundleSize(url, logData) + await postBundleSize(URL, logData) }) -const getCommitId = () => childProcess.execSync('git rev-parse HEAD').toString().trim() +function getGitInformation(command) { + try { + return execSync(command) + .toString('utf8') + .replace(/[\n\r\s]+$/, '') + } catch (error) { + console.error('Failed to execute git command:', error) + return null + } +} function getVersion() { - const versionJson = fs.readFileSync(versionPath, 'utf8') - return JSON.parse(versionJson).version + try { + const versionJson = fs.readFileSync(versionPath, 'utf8') + return JSON.parse(versionJson).version + } catch (error) { + console.error('Failed to get version:', error) + return null + } } function getBundleSize(pathBundle) { - const file = fs.statSync(pathBundle) - return file.size + try { + const file = fs.statSync(pathBundle) + return file.size + } catch (error) { + console.error('Failed to get bundle size:', error) + return null + } } async function postBundleSize(url = '', bundleData = {}) { - const response = await fetch(url, { + await fetchWrapper(url, { method: 'POST', - headers: { - 'DD-API-KEY': getOrg2ApiKey(), - 'Content-Type': 'application/json', - }, + headers: HEADERS, body: JSON.stringify(bundleData), }) - console.log(await response.text()) } From d0ee5a3e5801578008388621fe749012f2ee6229 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 12:02:50 +0100 Subject: [PATCH 05/21] changed branch's retrieve function --- scripts/export-bundles-sizes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 8ac3c925c1..6959989956 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -31,7 +31,7 @@ runMain(async () => { }, version: getVersion(), commit: getGitInformation('git rev-parse HEAD'), - branch: getGitInformation('git rev-parse --abbrev-ref HEAD'), + branch: process.env.GITHUB_REF ? process.env.GITHUB_REF.split('/').pop() : null, }, ] await postBundleSize(URL, logData) From bee50357a2443aa2db116d86d5f064464a028320 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 12:55:52 +0100 Subject: [PATCH 06/21] changed get branch method --- scripts/export-bundles-sizes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 6959989956..74801ca3be 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -31,7 +31,7 @@ runMain(async () => { }, version: getVersion(), commit: getGitInformation('git rev-parse HEAD'), - branch: process.env.GITHUB_REF ? process.env.GITHUB_REF.split('/').pop() : null, + branch: process.env.GITHUB_HEAD_REF || (process.env.GITHUB_REF ? process.env.GITHUB_REF.split('/').pop() : null), }, ] await postBundleSize(URL, logData) From 039adfbf51c4298c0fa43585848275544f8e46ef Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 13:08:25 +0100 Subject: [PATCH 07/21] changed branch method --- scripts/export-bundles-sizes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 74801ca3be..1d922cf081 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -31,7 +31,7 @@ runMain(async () => { }, version: getVersion(), commit: getGitInformation('git rev-parse HEAD'), - branch: process.env.GITHUB_HEAD_REF || (process.env.GITHUB_REF ? process.env.GITHUB_REF.split('/').pop() : null), + branch: process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME, }, ] await postBundleSize(URL, logData) From 4b4cbf19de1584f071056b85ffbe3be9024c5244 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 13:49:53 +0100 Subject: [PATCH 08/21] test merging --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d52b36d351..f57f610dde 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -136,6 +136,7 @@ build-and-lint: - .test-allowed-branches interruptible: true script: + - echo "Target branch: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME" - yarn - yarn build - yarn lint From 8341cdabaebbff14b55c4121a7f87397296e6c1e Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 13:57:19 +0100 Subject: [PATCH 09/21] echo target branch name --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f57f610dde..31be55b381 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -136,7 +136,7 @@ build-and-lint: - .test-allowed-branches interruptible: true script: - - echo "Target branch: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME" + - echo ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} - yarn - yarn build - yarn lint From 07f65d46a847e42138d6606b1c8095ab8618e495 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 14:10:42 +0100 Subject: [PATCH 10/21] update gitlab yaml echo --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 31be55b381..33d4914dc4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -136,7 +136,7 @@ build-and-lint: - .test-allowed-branches interruptible: true script: - - echo ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} + - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - yarn - yarn build - yarn lint From ff01b8d2d1f8b1905cf511c949e831c303f50d1e Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 14:49:35 +0100 Subject: [PATCH 11/21] added merge request tag in built and lint --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 33d4914dc4..966a4940d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -135,6 +135,9 @@ build-and-lint: - .base-configuration - .test-allowed-branches interruptible: true + only: + - merge_requests + - branches script: - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - yarn From 904e9fe96bd61c246f1a6d9168a9c177e39cc98b Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 15:13:53 +0100 Subject: [PATCH 12/21] only merge request --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 966a4940d4..77701b8ee4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -137,7 +137,6 @@ build-and-lint: interruptible: true only: - merge_requests - - branches script: - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - yarn From f7db3eb8164cbc5d7946d2b3abe5e5ea35dcf36e Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 15:17:16 +0100 Subject: [PATCH 13/21] revert changes gitlab yml --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 77701b8ee4..d52b36d351 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -135,10 +135,7 @@ build-and-lint: - .base-configuration - .test-allowed-branches interruptible: true - only: - - merge_requests script: - - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - yarn - yarn build - yarn lint From 8b13c6c525ed431d58d18ce42176d171a560b595 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Mon, 12 Feb 2024 15:24:40 +0100 Subject: [PATCH 14/21] added branch new method --- scripts/export-bundles-sizes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 1d922cf081..18c2cd655f 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -30,14 +30,14 @@ runMain(async () => { worker: getBundleSize(workerPath), }, version: getVersion(), - commit: getGitInformation('git rev-parse HEAD'), - branch: process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME, + commit: executeGitCommand('git rev-parse HEAD'), + branch: process.env.CI_COMMIT_REF_NAME, }, ] await postBundleSize(URL, logData) }) -function getGitInformation(command) { +function executeGitCommand(command) { try { return execSync(command) .toString('utf8') From e273ea37c1e430bb2da3d78dbf9d2d34674156a5 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Tue, 13 Feb 2024 09:36:32 +0100 Subject: [PATCH 15/21] Changed name intake, source version file and commit retrieve process --- scripts/export-bundles-sizes.js | 42 ++++++++------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 18c2cd655f..4b0e786e80 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -1,6 +1,7 @@ const fs = require('fs') const path = require('path') const { execSync } = require('child_process') +const lernaJson = require('../lerna.json') const { getOrg2ApiKey } = require('./lib/secrets') const { runMain, fetch: fetchWrapper } = require('./lib/execution-utils') @@ -8,10 +9,9 @@ const rumPath = path.join(__dirname, '../packages/rum/bundle/datadog-rum.js') const logsPath = path.join(__dirname, '../packages/logs/bundle/datadog-logs.js') const rumSlimPath = path.join(__dirname, '../packages/rum-slim/bundle/datadog-rum-slim.js') const workerPath = path.join(__dirname, '../packages/worker/bundle/worker.js') -const versionPath = path.join(__dirname, '../packages/rum/package.json') -const URL = 'https://http-intake.logs.datadoghq.com/api/v2/logs' -const HEADERS = { +const LOG_INTAKE_URL = 'https://http-intake.logs.datadoghq.com/api/v2/logs' +const LOG_INTAKE_REQUEST_HEADERS = { 'DD-API-KEY': getOrg2ApiKey(), 'Content-Type': 'application/json', } @@ -29,49 +29,27 @@ runMain(async () => { rum_slim: getBundleSize(rumSlimPath), worker: getBundleSize(workerPath), }, - version: getVersion(), - commit: executeGitCommand('git rev-parse HEAD'), + version: lernaJson.version, + commit: process.env.CI_COMMIT_SHORT_SHA, branch: process.env.CI_COMMIT_REF_NAME, }, ] - await postBundleSize(URL, logData) + await sendLogToOrg2(logData) }) -function executeGitCommand(command) { - try { - return execSync(command) - .toString('utf8') - .replace(/[\n\r\s]+$/, '') - } catch (error) { - console.error('Failed to execute git command:', error) - return null - } -} - -function getVersion() { - try { - const versionJson = fs.readFileSync(versionPath, 'utf8') - return JSON.parse(versionJson).version - } catch (error) { - console.error('Failed to get version:', error) - return null - } -} - function getBundleSize(pathBundle) { try { const file = fs.statSync(pathBundle) return file.size } catch (error) { - console.error('Failed to get bundle size:', error) - return null + throw new Error('Failed to get bundle size', { cause: error }) } } -async function postBundleSize(url = '', bundleData = {}) { - await fetchWrapper(url, { +async function sendLogToOrg2(bundleData = {}) { + await fetchWrapper(LOG_INTAKE_URL, { method: 'POST', - headers: HEADERS, + headers: LOG_INTAKE_REQUEST_HEADERS, body: JSON.stringify(bundleData), }) } From f532ec79b79eb8f481398ca2cd00502e28a81900 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Tue, 13 Feb 2024 10:04:09 +0100 Subject: [PATCH 16/21] added browser-sdk-version function / added error.cause to run main function --- scripts/export-bundles-sizes.js | 5 ++--- scripts/lib/browser-sdk-version.js | 9 +++++++++ scripts/lib/build-env.js | 6 +++--- scripts/lib/execution-utils.js | 1 + scripts/release/generate-changelog.js | 4 ++-- scripts/release/update-peer-dependency-versions.js | 4 ++-- 6 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 scripts/lib/browser-sdk-version.js diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 4b0e786e80..4ca4b40968 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -1,7 +1,6 @@ const fs = require('fs') const path = require('path') -const { execSync } = require('child_process') -const lernaJson = require('../lerna.json') +const { getBrowserSdkVersion } = require('./lib/browser-sdk-version') const { getOrg2ApiKey } = require('./lib/secrets') const { runMain, fetch: fetchWrapper } = require('./lib/execution-utils') @@ -29,7 +28,7 @@ runMain(async () => { rum_slim: getBundleSize(rumSlimPath), worker: getBundleSize(workerPath), }, - version: lernaJson.version, + version: getBrowserSdkVersion(), commit: process.env.CI_COMMIT_SHORT_SHA, branch: process.env.CI_COMMIT_REF_NAME, }, diff --git a/scripts/lib/browser-sdk-version.js b/scripts/lib/browser-sdk-version.js new file mode 100644 index 0000000000..b38226f333 --- /dev/null +++ b/scripts/lib/browser-sdk-version.js @@ -0,0 +1,9 @@ +const lernaJson = require('../../lerna.json') + +function getBrowserSdkVersion() { + return lernaJson.version +} + +module.exports = { + getBrowserSdkVersion, +} diff --git a/scripts/lib/build-env.js b/scripts/lib/build-env.js index de9d6b532b..f94826117c 100644 --- a/scripts/lib/build-env.js +++ b/scripts/lib/build-env.js @@ -1,7 +1,7 @@ const { readFileSync } = require('fs') const path = require('path') const execSync = require('child_process').execSync -const lernaJson = require('../../lerna.json') +const { getBrowserSdkVersion } = require('./browser-sdk-version') const { command } = require('./command') /** @@ -24,12 +24,12 @@ const buildEnvFactories = { SDK_VERSION: () => { switch (getBuildMode()) { case 'release': - return lernaJson.version + return getBrowserSdkVersion() case 'canary': { const commitSha1 = execSync('git rev-parse HEAD').toString().trim() // TODO when tags would allow '+' characters // use build separator (+) instead of prerelease separator (-) - return `${lernaJson.version}-${commitSha1}` + return `${getBrowserSdkVersion()}-${commitSha1}` } default: return 'dev' diff --git a/scripts/lib/execution-utils.js b/scripts/lib/execution-utils.js index 1c73a2794e..20b1ff91e5 100644 --- a/scripts/lib/execution-utils.js +++ b/scripts/lib/execution-utils.js @@ -27,6 +27,7 @@ function runMain(mainFunction) { .catch((error) => { printError('\nScript exited with error:') printError(error) + printError(error.cause) process.exit(1) }) } diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index a0974da97f..2ae7be9b13 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -5,7 +5,7 @@ const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') -const lernaConfig = require('../../lerna.json') +const { getBrowserSdkVersion } = require('../lib/browser-sdk-version') const { spawnCommand, printError, runMain } = require('../lib/execution-utils') const { command } = require('../lib/command') const { modifyFile } = require('../lib/files-utils') @@ -33,7 +33,7 @@ ${emojisLegend} --- -## v${lernaConfig.version} +## v${getBrowserSdkVersion()} ${changesList} ${content.slice(content.indexOf('\n##'))}` diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index d884281caf..bf07a765c8 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -1,7 +1,7 @@ -const lernaConfig = require('../../lerna.json') const { runMain } = require('../lib/execution-utils') const { modifyFile } = require('../lib/files-utils') const { command } = require('../lib/command') +const { getBrowserSdkVersion } = require('../lib/browser-sdk-version') const JSON_FILES = ['rum', 'rum-slim', 'logs'].map((packageName) => `./packages/${packageName}/package.json`) @@ -25,7 +25,7 @@ runMain(async () => { function updateJsonPeerDependencies(content) { const json = JSON.parse(content) Object.keys(json.peerDependencies).forEach((key) => { - json.peerDependencies[key] = lernaConfig.version + json.peerDependencies[key] = getBrowserSdkVersion() }) return `${JSON.stringify(json, null, 2)}\n` } From bc7f0c629071c298022578169ddd7283c47b2d7e Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Tue, 13 Feb 2024 14:13:03 +0100 Subject: [PATCH 17/21] added function printErrorWithCause --- scripts/lib/execution-utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/lib/execution-utils.js b/scripts/lib/execution-utils.js index 20b1ff91e5..f1e7203453 100644 --- a/scripts/lib/execution-utils.js +++ b/scripts/lib/execution-utils.js @@ -26,8 +26,7 @@ function runMain(mainFunction) { .then(() => mainFunction()) .catch((error) => { printError('\nScript exited with error:') - printError(error) - printError(error.cause) + printErrorWithCause(error) process.exit(1) }) } @@ -39,6 +38,14 @@ function printError(...params) { console.log(redColor, ...params, resetColor) } +function printErrorWithCause(error) { + printError(error) + if (error.cause) { + printError('Caused by:') + printErrorWithCause(error.cause) + } +} + function printLog(...params) { const greenColor = '\x1b[32;1m' console.log(greenColor, ...params, resetColor) From 269ff1f82bc30387d7c6bb834ee47e95ce411e13 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Wed, 14 Feb 2024 11:23:27 +0100 Subject: [PATCH 18/21] deleted getter and added a simple return of lerna version. Changed fetch wrapper into fetch in export bundle script. Deleted local preferences in gitignore --- .gitignore | 3 --- scripts/export-bundles-sizes.js | 6 +++--- scripts/lib/browser-sdk-version.js | 6 +----- scripts/lib/build-env.js | 2 +- scripts/release/generate-changelog.js | 2 +- scripts/release/update-peer-dependency-versions.js | 2 +- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 289cfe6578..d6b930e824 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,3 @@ browserstack.err !.yarn/releases !.yarn/sdks !.yarn/versions - -.DS_Store -.vscode/* diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 4ca4b40968..8d7c5dbd41 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -2,7 +2,7 @@ const fs = require('fs') const path = require('path') const { getBrowserSdkVersion } = require('./lib/browser-sdk-version') const { getOrg2ApiKey } = require('./lib/secrets') -const { runMain, fetch: fetchWrapper } = require('./lib/execution-utils') +const { runMain, fetch } = require('./lib/execution-utils') const rumPath = path.join(__dirname, '../packages/rum/bundle/datadog-rum.js') const logsPath = path.join(__dirname, '../packages/logs/bundle/datadog-logs.js') @@ -28,7 +28,7 @@ runMain(async () => { rum_slim: getBundleSize(rumSlimPath), worker: getBundleSize(workerPath), }, - version: getBrowserSdkVersion(), + version: getBrowserSdkVersion, commit: process.env.CI_COMMIT_SHORT_SHA, branch: process.env.CI_COMMIT_REF_NAME, }, @@ -46,7 +46,7 @@ function getBundleSize(pathBundle) { } async function sendLogToOrg2(bundleData = {}) { - await fetchWrapper(LOG_INTAKE_URL, { + await fetch(LOG_INTAKE_URL, { method: 'POST', headers: LOG_INTAKE_REQUEST_HEADERS, body: JSON.stringify(bundleData), diff --git a/scripts/lib/browser-sdk-version.js b/scripts/lib/browser-sdk-version.js index b38226f333..a36659a81b 100644 --- a/scripts/lib/browser-sdk-version.js +++ b/scripts/lib/browser-sdk-version.js @@ -1,9 +1,5 @@ const lernaJson = require('../../lerna.json') -function getBrowserSdkVersion() { - return lernaJson.version -} - module.exports = { - getBrowserSdkVersion, + getBrowserSdkVersion: lernaJson.version, } diff --git a/scripts/lib/build-env.js b/scripts/lib/build-env.js index f94826117c..3eb2e7606f 100644 --- a/scripts/lib/build-env.js +++ b/scripts/lib/build-env.js @@ -29,7 +29,7 @@ const buildEnvFactories = { const commitSha1 = execSync('git rev-parse HEAD').toString().trim() // TODO when tags would allow '+' characters // use build separator (+) instead of prerelease separator (-) - return `${getBrowserSdkVersion()}-${commitSha1}` + return `${getBrowserSdkVersion}-${commitSha1}` } default: return 'dev' diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 2ae7be9b13..9da64d5807 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -33,7 +33,7 @@ ${emojisLegend} --- -## v${getBrowserSdkVersion()} +## v${getBrowserSdkVersion} ${changesList} ${content.slice(content.indexOf('\n##'))}` diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index bf07a765c8..8e0083da24 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -25,7 +25,7 @@ runMain(async () => { function updateJsonPeerDependencies(content) { const json = JSON.parse(content) Object.keys(json.peerDependencies).forEach((key) => { - json.peerDependencies[key] = getBrowserSdkVersion() + json.peerDependencies[key] = getBrowserSdkVersion }) return `${JSON.stringify(json, null, 2)}\n` } From 499851c4ba2efbe5d6fc7918b71b4754d7700af3 Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Wed, 14 Feb 2024 11:28:06 +0100 Subject: [PATCH 19/21] build env getbrowserversion --- scripts/lib/build-env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lib/build-env.js b/scripts/lib/build-env.js index 3eb2e7606f..409dd70a97 100644 --- a/scripts/lib/build-env.js +++ b/scripts/lib/build-env.js @@ -24,7 +24,7 @@ const buildEnvFactories = { SDK_VERSION: () => { switch (getBuildMode()) { case 'release': - return getBrowserSdkVersion() + return getBrowserSdkVersion case 'canary': { const commitSha1 = execSync('git rev-parse HEAD').toString().trim() // TODO when tags would allow '+' characters From 81855d3793988dba578820b49affa5ee74d8aa1f Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Thu, 15 Feb 2024 13:55:47 +0100 Subject: [PATCH 20/21] changed export name BrowserSdkVersion --- scripts/export-bundles-sizes.js | 4 ++-- scripts/lib/browser-sdk-version.js | 2 +- scripts/lib/build-env.js | 6 +++--- scripts/release/generate-changelog.js | 4 ++-- scripts/release/update-peer-dependency-versions.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 8d7c5dbd41..3ae754c332 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const { getBrowserSdkVersion } = require('./lib/browser-sdk-version') +const { BrowserSdkVersion } = require('./lib/browser-sdk-version') const { getOrg2ApiKey } = require('./lib/secrets') const { runMain, fetch } = require('./lib/execution-utils') @@ -28,7 +28,7 @@ runMain(async () => { rum_slim: getBundleSize(rumSlimPath), worker: getBundleSize(workerPath), }, - version: getBrowserSdkVersion, + version: BrowserSdkVersion, commit: process.env.CI_COMMIT_SHORT_SHA, branch: process.env.CI_COMMIT_REF_NAME, }, diff --git a/scripts/lib/browser-sdk-version.js b/scripts/lib/browser-sdk-version.js index a36659a81b..57d2b06201 100644 --- a/scripts/lib/browser-sdk-version.js +++ b/scripts/lib/browser-sdk-version.js @@ -1,5 +1,5 @@ const lernaJson = require('../../lerna.json') module.exports = { - getBrowserSdkVersion: lernaJson.version, + BrowserSdkVersion: lernaJson.version, } diff --git a/scripts/lib/build-env.js b/scripts/lib/build-env.js index 409dd70a97..15838d2994 100644 --- a/scripts/lib/build-env.js +++ b/scripts/lib/build-env.js @@ -1,7 +1,7 @@ const { readFileSync } = require('fs') const path = require('path') const execSync = require('child_process').execSync -const { getBrowserSdkVersion } = require('./browser-sdk-version') +const { BrowserSdkVersion } = require('./browser-sdk-version') const { command } = require('./command') /** @@ -24,12 +24,12 @@ const buildEnvFactories = { SDK_VERSION: () => { switch (getBuildMode()) { case 'release': - return getBrowserSdkVersion + return BrowserSdkVersion case 'canary': { const commitSha1 = execSync('git rev-parse HEAD').toString().trim() // TODO when tags would allow '+' characters // use build separator (+) instead of prerelease separator (-) - return `${getBrowserSdkVersion}-${commitSha1}` + return `${BrowserSdkVersion}-${commitSha1}` } default: return 'dev' diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 9da64d5807..0447241709 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -5,7 +5,7 @@ const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') -const { getBrowserSdkVersion } = require('../lib/browser-sdk-version') +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') @@ -33,7 +33,7 @@ ${emojisLegend} --- -## v${getBrowserSdkVersion} +## v${BrowserSdkVersion} ${changesList} ${content.slice(content.indexOf('\n##'))}` diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index 8e0083da24..0bcb5557d2 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -1,7 +1,7 @@ const { runMain } = require('../lib/execution-utils') const { modifyFile } = require('../lib/files-utils') const { command } = require('../lib/command') -const { getBrowserSdkVersion } = require('../lib/browser-sdk-version') +const { BrowserSdkVersion } = require('../lib/browser-sdk-version') const JSON_FILES = ['rum', 'rum-slim', 'logs'].map((packageName) => `./packages/${packageName}/package.json`) @@ -25,7 +25,7 @@ runMain(async () => { function updateJsonPeerDependencies(content) { const json = JSON.parse(content) Object.keys(json.peerDependencies).forEach((key) => { - json.peerDependencies[key] = getBrowserSdkVersion + json.peerDependencies[key] = BrowserSdkVersion }) return `${JSON.stringify(json, null, 2)}\n` } From bf1e3dd0499309b6c86f14487815e162570595ad Mon Sep 17 00:00:00 2001 From: "roman.gaignault" Date: Thu, 15 Feb 2024 13:58:51 +0100 Subject: [PATCH 21/21] changed browserSdkVersion export name --- scripts/export-bundles-sizes.js | 4 ++-- scripts/lib/browser-sdk-version.js | 2 +- scripts/lib/build-env.js | 6 +++--- scripts/release/generate-changelog.js | 4 ++-- scripts/release/update-peer-dependency-versions.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/export-bundles-sizes.js b/scripts/export-bundles-sizes.js index 3ae754c332..d846e1e15b 100644 --- a/scripts/export-bundles-sizes.js +++ b/scripts/export-bundles-sizes.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const { BrowserSdkVersion } = require('./lib/browser-sdk-version') +const { browserSdkVersion } = require('./lib/browser-sdk-version') const { getOrg2ApiKey } = require('./lib/secrets') const { runMain, fetch } = require('./lib/execution-utils') @@ -28,7 +28,7 @@ runMain(async () => { rum_slim: getBundleSize(rumSlimPath), worker: getBundleSize(workerPath), }, - version: BrowserSdkVersion, + version: browserSdkVersion, commit: process.env.CI_COMMIT_SHORT_SHA, branch: process.env.CI_COMMIT_REF_NAME, }, diff --git a/scripts/lib/browser-sdk-version.js b/scripts/lib/browser-sdk-version.js index 57d2b06201..6bca8b9398 100644 --- a/scripts/lib/browser-sdk-version.js +++ b/scripts/lib/browser-sdk-version.js @@ -1,5 +1,5 @@ const lernaJson = require('../../lerna.json') module.exports = { - BrowserSdkVersion: lernaJson.version, + browserSdkVersion: lernaJson.version, } diff --git a/scripts/lib/build-env.js b/scripts/lib/build-env.js index 15838d2994..e3824b48c3 100644 --- a/scripts/lib/build-env.js +++ b/scripts/lib/build-env.js @@ -1,7 +1,7 @@ const { readFileSync } = require('fs') const path = require('path') const execSync = require('child_process').execSync -const { BrowserSdkVersion } = require('./browser-sdk-version') +const { browserSdkVersion } = require('./browser-sdk-version') const { command } = require('./command') /** @@ -24,12 +24,12 @@ const buildEnvFactories = { SDK_VERSION: () => { switch (getBuildMode()) { case 'release': - return BrowserSdkVersion + return browserSdkVersion case 'canary': { const commitSha1 = execSync('git rev-parse HEAD').toString().trim() // TODO when tags would allow '+' characters // use build separator (+) instead of prerelease separator (-) - return `${BrowserSdkVersion}-${commitSha1}` + return `${browserSdkVersion}-${commitSha1}` } default: return 'dev' diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 0447241709..9e128f148f 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -5,7 +5,7 @@ const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') -const { BrowserSdkVersion } = require('../lib/browser-sdk-version') +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') @@ -33,7 +33,7 @@ ${emojisLegend} --- -## v${BrowserSdkVersion} +## v${browserSdkVersion} ${changesList} ${content.slice(content.indexOf('\n##'))}` diff --git a/scripts/release/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js index 0bcb5557d2..4494af84da 100644 --- a/scripts/release/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -1,7 +1,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 { browserSdkVersion } = require('../lib/browser-sdk-version') const JSON_FILES = ['rum', 'rum-slim', 'logs'].map((packageName) => `./packages/${packageName}/package.json`) @@ -25,7 +25,7 @@ runMain(async () => { function updateJsonPeerDependencies(content) { const json = JSON.parse(content) Object.keys(json.peerDependencies).forEach((key) => { - json.peerDependencies[key] = BrowserSdkVersion + json.peerDependencies[key] = browserSdkVersion }) return `${JSON.stringify(json, null, 2)}\n` }