From 6c436f1a65a921121f582f7547563fbc912a81d2 Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Tue, 21 Mar 2023 14:55:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Reorganise=20`scripts`=20directo?= =?UTF-8?q?ry=20(#2059)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ group build scripts * ♻️ group release scripts * ♻️ group deploy scripts * ♻️ group test scripts * 👌 separate lib from executables * 👌 move build-env to lib * 👌 colocate deployment utils with deploy scripts * Trigger ci --- .gitlab-ci.yml | 36 +++++++++---------- package.json | 4 +-- packages/core/package.json | 2 +- packages/logs/package.json | 2 +- packages/rum-core/package.json | 2 +- scripts/{ => build}/replace-build-env.js | 4 +-- scripts/check-licenses.js | 2 +- scripts/cli | 4 +-- scripts/{ => deploy}/deploy.js | 4 +-- scripts/{ => deploy/lib}/deployment-utils.js | 0 scripts/{ => deploy}/publish-npm.sh | 0 scripts/{ => deploy}/upload-source-maps.js | 6 ++-- scripts/dev-server.js | 2 +- scripts/generate-schema-types.js | 2 +- scripts/{ => lib}/build-env.js | 2 +- scripts/{ => lib}/utils.js | 2 +- scripts/{ => release}/check-release.js | 4 +-- scripts/{ => release}/generate-changelog.js | 4 +-- .../update-peer-dependency-versions.js | 4 +-- .../staging-ci/check-squash-into-staging.js | 2 +- scripts/staging-ci/check-staging-merge.js | 2 +- scripts/staging-ci/merge-into-staging.js | 2 +- scripts/staging-ci/staging-reset.js | 2 +- scripts/{ => test}/bs-wrapper.js | 2 +- .../{ => test}/bump-chrome-driver-version.js | 2 +- scripts/{ => test}/ci-bs.sh | 0 scripts/{ => test}/codecov.sh | 0 scripts/{ => test}/export-test-result.js | 2 +- webpack.base.js | 2 +- 29 files changed, 51 insertions(+), 51 deletions(-) rename scripts/{ => build}/replace-build-env.js (86%) rename scripts/{ => deploy}/deploy.js (96%) rename scripts/{ => deploy/lib}/deployment-utils.js (100%) rename scripts/{ => deploy}/publish-npm.sh (100%) rename scripts/{ => deploy}/upload-source-maps.js (94%) rename scripts/{ => lib}/build-env.js (95%) rename scripts/{ => lib}/utils.js (99%) rename scripts/{ => release}/check-release.js (96%) rename scripts/{ => release}/generate-changelog.js (97%) rename scripts/{ => release}/update-peer-dependency-versions.js (89%) rename scripts/{ => test}/bs-wrapper.js (98%) rename scripts/{ => test}/bump-chrome-driver-version.js (99%) rename scripts/{ => test}/ci-bs.sh (100%) rename scripts/{ => test}/codecov.sh (100%) rename scripts/{ => test}/export-test-result.js (86%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index df64ecd032..89dcac9a8e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -166,9 +166,9 @@ unit: script: - yarn - yarn test:unit - - ./scripts/codecov.sh + - ./scripts/test/codecov.sh after_script: - - node ./scripts/export-test-result.js unit + - node ./scripts/test/export-test-result.js unit e2e: extends: @@ -184,7 +184,7 @@ e2e: - yarn - yarn test:e2e after_script: - - node ./scripts/export-test-result.js e2e + - node ./scripts/test/export-test-result.js e2e check-licenses: extends: @@ -203,7 +203,7 @@ check-release: script: - yarn - BUILD_MODE=release yarn build - - node scripts/check-release.js + - node scripts/release/check-release.js unit-bs: stage: browserstack @@ -217,9 +217,9 @@ unit-bs: junit: test-report/unit-bs/*.xml script: - yarn - - ./scripts/ci-bs.sh test:unit + - ./scripts/test/ci-bs.sh test:unit after_script: - - node ./scripts/export-test-result.js unit-bs + - node ./scripts/test/export-test-result.js unit-bs e2e-bs: stage: browserstack @@ -235,9 +235,9 @@ e2e-bs: junit: test-report/e2e-bs/*.xml script: - yarn - - ./scripts/ci-bs.sh test:e2e + - ./scripts/test/ci-bs.sh test:e2e after_script: - - node ./scripts/export-test-result.js e2e-bs + - node ./scripts/test/export-test-result.js e2e-bs ######################################################################################################################## # Deploy @@ -252,8 +252,8 @@ deploy-staging: - export BUILD_MODE=canary - yarn - yarn build:bundle - - node ./scripts/deploy.js staging staging root - - node ./scripts/upload-source-maps.js staging root + - node ./scripts/deploy/deploy.js staging staging root + - node ./scripts/deploy/upload-source-maps.js staging root deploy-prod-canary: stage: deploy:canary @@ -264,8 +264,8 @@ deploy-prod-canary: - export BUILD_MODE=canary - yarn - yarn build:bundle - - node ./scripts/deploy.js prod canary root - - node ./scripts/upload-source-maps.js canary root + - node ./scripts/deploy/deploy.js prod canary root + - node ./scripts/deploy/upload-source-maps.js canary root deploy-prod-all-dcs: stage: deploy @@ -279,8 +279,8 @@ deploy-prod-all-dcs: - VERSION=$(node -p -e "require('./lerna.json').version") - yarn - yarn build:bundle - - node ./scripts/deploy.js prod v${VERSION%%.*} us1,eu1,us3,us5,ap1 - - node ./scripts/upload-source-maps.js v${VERSION%%.*} us1,eu1,us3,us5,ap1 + - node ./scripts/deploy/deploy.js prod v${VERSION%%.*} us1,eu1,us3,us5,ap1 + - node ./scripts/deploy/upload-source-maps.js v${VERSION%%.*} us1,eu1,us3,us5,ap1 deploy-prod-root: stage: deploy @@ -294,8 +294,8 @@ deploy-prod-root: - VERSION=$(node -p -e "require('./lerna.json').version") - yarn - yarn build:bundle - - node ./scripts/deploy.js prod v${VERSION%%.*} root - - node ./scripts/upload-source-maps.js v${VERSION%%.*} root + - node ./scripts/deploy/deploy.js prod v${VERSION%%.*} root + - node ./scripts/deploy/upload-source-maps.js v${VERSION%%.*} root publish-npm: stage: deploy @@ -306,7 +306,7 @@ publish-npm: allow_failure: false script: - yarn - - ./scripts/publish-npm.sh + - ./scripts/deploy/publish-npm.sh ######################################################################################################################## # Notify @@ -485,7 +485,7 @@ bump-chrome-version-scheduled: before_script: - eval $(ssh-agent -s) script: - - node scripts/bump-chrome-driver-version.js + - node scripts/test/bump-chrome-driver-version.js artifacts: reports: dotenv: build.env diff --git a/package.json b/package.json index 1845b57727..086dc68b56 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "test": "yarn test:unit:watch", "test:unit": "karma start ./test/unit/karma.local.conf.js", "test:unit:watch": "yarn test:unit --no-single-run", - "test:unit:bs": "node ./scripts/bs-wrapper.js karma start test/unit/karma.bs.conf.js", + "test:unit:bs": "node ./scripts/test/bs-wrapper.js karma start test/unit/karma.bs.conf.js", "test:e2e": "yarn build && (cd test/app && rm -rf node_modules && yarn && yarn build) && wdio test/e2e/wdio.local.conf.js", - "test:e2e:bs": "yarn build && (cd test/app && rm -rf node_modules && yarn && yarn build) && node ./scripts/bs-wrapper.js wdio test/e2e/wdio.bs.conf.js", + "test:e2e:bs": "yarn build && (cd test/app && rm -rf node_modules && yarn && yarn build) && node ./scripts/test/bs-wrapper.js wdio test/e2e/wdio.bs.conf.js", "test:compat:tsc": "scripts/cli check_typescript_compatibility", "test:compat:ssr": "scripts/cli check_server_side_rendering_compatibility", "rum-events-format:sync": "scripts/cli update_submodule && scripts/cli build_json2type && node scripts/generate-schema-types.js", diff --git a/packages/core/package.json b/packages/core/package.json index 29ea94dc22..0dc9720f97 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -10,7 +10,7 @@ "build": "run-p build:cjs build:esm", "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs", "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm", - "replace-build-env": "node ../../scripts/replace-build-env.js" + "replace-build-env": "node ../../scripts/build/replace-build-env.js" }, "devDependencies": { "@types/sinon": "9.0.10", diff --git a/packages/logs/package.json b/packages/logs/package.json index b71c487cd8..cda1e3e135 100644 --- a/packages/logs/package.json +++ b/packages/logs/package.json @@ -10,7 +10,7 @@ "build:bundle": "rm -rf bundle && webpack --mode=production", "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs", "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm", - "replace-build-env": "node ../../scripts/replace-build-env.js" + "replace-build-env": "node ../../scripts/build/replace-build-env.js" }, "dependencies": { "@datadog/browser-core": "4.35.0" diff --git a/packages/rum-core/package.json b/packages/rum-core/package.json index 4aae246167..d249429fba 100644 --- a/packages/rum-core/package.json +++ b/packages/rum-core/package.json @@ -9,7 +9,7 @@ "build": "run-p build:cjs build:esm", "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs", "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm", - "replace-build-env": "node ../../scripts/replace-build-env.js" + "replace-build-env": "node ../../scripts/build/replace-build-env.js" }, "dependencies": { "@datadog/browser-core": "4.35.0" diff --git a/scripts/replace-build-env.js b/scripts/build/replace-build-env.js similarity index 86% rename from scripts/replace-build-env.js rename to scripts/build/replace-build-env.js index c91cdd0439..0f38785a4f 100644 --- a/scripts/replace-build-env.js +++ b/scripts/build/replace-build-env.js @@ -1,6 +1,6 @@ const glob = require('glob') -const buildEnv = require('./build-env') -const { printLog, runMain, modifyFile } = require('./utils') +const { printLog, runMain, modifyFile } = require('../lib/utils') +const buildEnv = require('../lib/build-env') /** * Replace BuildEnv in build files diff --git a/scripts/check-licenses.js b/scripts/check-licenses.js index ec06d03d08..c649ba5609 100644 --- a/scripts/check-licenses.js +++ b/scripts/check-licenses.js @@ -3,7 +3,7 @@ const fs = require('fs') const path = require('path') const readline = require('readline') -const { printLog, printError, runMain, findBrowserSdkPackageJsonFiles } = require('./utils') +const { printLog, printError, runMain, findBrowserSdkPackageJsonFiles } = require('./lib/utils') const LICENSE_FILE = 'LICENSE-3rdparty.csv' diff --git a/scripts/cli b/scripts/cli index aed1af0f0d..a65632f6b1 100755 --- a/scripts/cli +++ b/scripts/cli @@ -60,8 +60,8 @@ cmd_release () { } cmd_version () { - node ./scripts/generate-changelog.js - node ./scripts/update-peer-dependency-versions.js + node ./scripts/release/generate-changelog.js + node ./scripts/release/update-peer-dependency-versions.js # keep test app lockfile up to date cd test/app yarn upgrade diff --git a/scripts/deploy.js b/scripts/deploy/deploy.js similarity index 96% rename from scripts/deploy.js rename to scripts/deploy/deploy.js index 6b92b0aa00..43a3971b1e 100644 --- a/scripts/deploy.js +++ b/scripts/deploy/deploy.js @@ -1,13 +1,13 @@ 'use strict' -const { printLog, command, runMain } = require('./utils') +const { printLog, command, runMain } = require('../lib/utils') const { buildRootUploadPath, buildDatacenterUploadPath, buildBundleFolder, buildBundleFileName, packages, -} = require('./deployment-utils') +} = require('./lib/deployment-utils') const ONE_MINUTE_IN_SECOND = 60 const ONE_HOUR_IN_SECOND = 60 * ONE_MINUTE_IN_SECOND diff --git a/scripts/deployment-utils.js b/scripts/deploy/lib/deployment-utils.js similarity index 100% rename from scripts/deployment-utils.js rename to scripts/deploy/lib/deployment-utils.js diff --git a/scripts/publish-npm.sh b/scripts/deploy/publish-npm.sh similarity index 100% rename from scripts/publish-npm.sh rename to scripts/deploy/publish-npm.sh diff --git a/scripts/upload-source-maps.js b/scripts/deploy/upload-source-maps.js similarity index 94% rename from scripts/upload-source-maps.js rename to scripts/deploy/upload-source-maps.js index ba86f50e7b..c22dfb4b6b 100644 --- a/scripts/upload-source-maps.js +++ b/scripts/deploy/upload-source-maps.js @@ -1,15 +1,15 @@ 'use strict' const path = require('path') -const { getSecretKey, command, printLog, runMain } = require('./utils') +const { getSecretKey, command, printLog, runMain } = require('../lib/utils') +const { SDK_VERSION } = require('../lib/build-env') const { buildRootUploadPath, buildDatacenterUploadPath, buildBundleFolder, buildBundleFileName, packages, -} = require('./deployment-utils') -const { SDK_VERSION } = require('./build-env') +} = require('./lib/deployment-utils') /** * Upload source maps to datadog diff --git a/scripts/dev-server.js b/scripts/dev-server.js index 6e9c9958f8..b70eb1b173 100644 --- a/scripts/dev-server.js +++ b/scripts/dev-server.js @@ -6,7 +6,7 @@ const webpack = require('webpack') const logsConfig = require('../packages/logs/webpack.config') const rumSlimConfig = require('../packages/rum-slim/webpack.config') const rumConfig = require('../packages/rum/webpack.config') -const { printLog } = require('./utils') +const { printLog } = require('./lib/utils') const port = 8080 const app = express() diff --git a/scripts/generate-schema-types.js b/scripts/generate-schema-types.js index daffa48542..e1abc99e10 100644 --- a/scripts/generate-schema-types.js +++ b/scripts/generate-schema-types.js @@ -2,7 +2,7 @@ const fs = require('fs') const path = require('path') const { compileFromFile } = require('json-schema-to-typescript') const prettier = require('prettier') -const { printLog, runMain } = require('./utils') +const { printLog, runMain } = require('./lib/utils') const schemasDirectoryPath = path.join(__dirname, '../rum-events-format/schemas') const prettierConfigPath = path.join(__dirname, '../.prettierrc.yml') diff --git a/scripts/build-env.js b/scripts/lib/build-env.js similarity index 95% rename from scripts/build-env.js rename to scripts/lib/build-env.js index ba38309e56..56c8b28f2f 100644 --- a/scripts/build-env.js +++ b/scripts/lib/build-env.js @@ -1,5 +1,5 @@ const execSync = require('child_process').execSync -const lernaJson = require('../lerna.json') +const lernaJson = require('../../lerna.json') /** * Allows to define which sdk_version to send to the intake. diff --git a/scripts/utils.js b/scripts/lib/utils.js similarity index 99% rename from scripts/utils.js rename to scripts/lib/utils.js index 1d01509950..58b9a35008 100644 --- a/scripts/utils.js +++ b/scripts/lib/utils.js @@ -244,7 +244,7 @@ function findBrowserSdkPackageJsonFiles() { .trim() .split('\n') .map((manifestPath) => { - const absoluteManifestPath = path.join(__dirname, '..', manifestPath) + const absoluteManifestPath = path.join(__dirname, '../..', manifestPath) return { relativePath: manifestPath, path: absoluteManifestPath, diff --git a/scripts/check-release.js b/scripts/release/check-release.js similarity index 96% rename from scripts/check-release.js rename to scripts/release/check-release.js index 4d35b17805..8b26f74d9a 100644 --- a/scripts/check-release.js +++ b/scripts/release/check-release.js @@ -2,8 +2,8 @@ const fs = require('fs') const path = require('path') -const { version: releaseVersion } = require('../lerna.json') -const { findBrowserSdkPackageJsonFiles, printLog, runMain, command } = require('./utils') +const { version: releaseVersion } = require('../../lerna.json') +const { findBrowserSdkPackageJsonFiles, printLog, runMain, command } = require('../lib/utils') runMain(() => { checkGitTag() diff --git a/scripts/generate-changelog.js b/scripts/release/generate-changelog.js similarity index 97% rename from scripts/generate-changelog.js rename to scripts/release/generate-changelog.js index 6f1688b323..809402f7f7 100644 --- a/scripts/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -5,8 +5,8 @@ const readFile = util.promisify(require('fs').readFile) const emojiNameMap = require('emoji-name-map') -const lernaConfig = require('../lerna.json') -const { command, spawnCommand, printError, runMain, modifyFile } = require('./utils') +const lernaConfig = require('../../lerna.json') +const { command, spawnCommand, printError, runMain, modifyFile } = require('../lib/utils') const CHANGELOG_FILE = 'CHANGELOG.md' const CONTRIBUTING_FILE = 'CONTRIBUTING.md' diff --git a/scripts/update-peer-dependency-versions.js b/scripts/release/update-peer-dependency-versions.js similarity index 89% rename from scripts/update-peer-dependency-versions.js rename to scripts/release/update-peer-dependency-versions.js index 0108531be1..b8b7d32303 100644 --- a/scripts/update-peer-dependency-versions.js +++ b/scripts/release/update-peer-dependency-versions.js @@ -1,5 +1,5 @@ -const lernaConfig = require('../lerna.json') -const { runMain, modifyFile } = require('./utils') +const lernaConfig = require('../../lerna.json') +const { runMain, modifyFile } = require('../lib/utils') // This script updates the peer dependency versions between rum and logs packages to match the new // version during a release. diff --git a/scripts/staging-ci/check-squash-into-staging.js b/scripts/staging-ci/check-squash-into-staging.js index 2098bd5cc9..5e5422ca9a 100644 --- a/scripts/staging-ci/check-squash-into-staging.js +++ b/scripts/staging-ci/check-squash-into-staging.js @@ -1,6 +1,6 @@ 'use strict' -const { initGitConfig, command, printLog, printError, runMain } = require('../utils') +const { initGitConfig, command, printLog, printError, runMain } = require('../lib/utils') const REPOSITORY = process.env.GIT_REPOSITORY const CI_COMMIT_SHA = process.env.CI_COMMIT_SHA diff --git a/scripts/staging-ci/check-staging-merge.js b/scripts/staging-ci/check-staging-merge.js index 50ddbcfeed..28ffd84fc9 100644 --- a/scripts/staging-ci/check-staging-merge.js +++ b/scripts/staging-ci/check-staging-merge.js @@ -1,6 +1,6 @@ 'use strict' -const { initGitConfig, command, printLog, printError, runMain } = require('../utils') +const { initGitConfig, command, printLog, printError, runMain } = require('../lib/utils') const REPOSITORY = process.env.GIT_REPOSITORY const CI_COMMIT_SHA = process.env.CI_COMMIT_SHA diff --git a/scripts/staging-ci/merge-into-staging.js b/scripts/staging-ci/merge-into-staging.js index 3045220af9..e31d35f2e1 100644 --- a/scripts/staging-ci/merge-into-staging.js +++ b/scripts/staging-ci/merge-into-staging.js @@ -1,6 +1,6 @@ 'use strict' -const { initGitConfig, command, printLog, printError, runMain } = require('../utils') +const { initGitConfig, command, printLog, printError, runMain } = require('../lib/utils') const REPOSITORY = process.env.GIT_REPOSITORY const CURRENT_STAGING_BRANCH = process.env.CURRENT_STAGING diff --git a/scripts/staging-ci/staging-reset.js b/scripts/staging-ci/staging-reset.js index 5d22b93633..82ae7403cb 100755 --- a/scripts/staging-ci/staging-reset.js +++ b/scripts/staging-ci/staging-reset.js @@ -9,7 +9,7 @@ const { runMain, replaceCiFileVariable, readCiFileVariable, -} = require('../utils') +} = require('../lib/utils') const REPOSITORY = process.env.GIT_REPOSITORY const MAIN_BRANCH = process.env.MAIN_BRANCH diff --git a/scripts/bs-wrapper.js b/scripts/test/bs-wrapper.js similarity index 98% rename from scripts/bs-wrapper.js rename to scripts/test/bs-wrapper.js index ad380c5e34..62435b5595 100644 --- a/scripts/bs-wrapper.js +++ b/scripts/test/bs-wrapper.js @@ -14,7 +14,7 @@ // after killing it. There might be a better way of prematurely aborting the test command if we need // to in the future. -const { spawnCommand, printLog, runMain, command, fetch } = require('./utils') +const { spawnCommand, printLog, runMain, command, fetch } = require('../lib/utils') const AVAILABILITY_CHECK_DELAY = 30_000 const BS_USERNAME = process.env.BS_USERNAME diff --git a/scripts/bump-chrome-driver-version.js b/scripts/test/bump-chrome-driver-version.js similarity index 99% rename from scripts/bump-chrome-driver-version.js rename to scripts/test/bump-chrome-driver-version.js index 50b0b2a04a..2684f5bda9 100644 --- a/scripts/bump-chrome-driver-version.js +++ b/scripts/test/bump-chrome-driver-version.js @@ -11,7 +11,7 @@ const { getSecretKey, fetch, CI_FILE, -} = require('./utils') +} = require('../lib/utils') const REPOSITORY = process.env.GIT_REPOSITORY const MAIN_BRANCH = process.env.MAIN_BRANCH diff --git a/scripts/ci-bs.sh b/scripts/test/ci-bs.sh similarity index 100% rename from scripts/ci-bs.sh rename to scripts/test/ci-bs.sh diff --git a/scripts/codecov.sh b/scripts/test/codecov.sh similarity index 100% rename from scripts/codecov.sh rename to scripts/test/codecov.sh diff --git a/scripts/export-test-result.js b/scripts/test/export-test-result.js similarity index 86% rename from scripts/export-test-result.js rename to scripts/test/export-test-result.js index 31ede23703..0b6d604ae8 100644 --- a/scripts/export-test-result.js +++ b/scripts/test/export-test-result.js @@ -1,6 +1,6 @@ 'use strict' -const { getSecretKey, command, printLog, runMain } = require('./utils') +const { getSecretKey, command, printLog, runMain } = require('../lib/utils') /** * Upload test result to datadog diff --git a/webpack.base.js b/webpack.base.js index 434999bfd0..a3cd848260 100644 --- a/webpack.base.js +++ b/webpack.base.js @@ -2,7 +2,7 @@ const path = require('path') const webpack = require('webpack') const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin') const TerserPlugin = require('terser-webpack-plugin') -const buildEnv = require('./scripts/build-env') +const buildEnv = require('./scripts/lib/build-env') const tsconfigPath = path.join(__dirname, 'tsconfig.webpack.json')