From 10a5db05f202511eb678d7267f5afa274f4094ae Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 30 Nov 2023 10:14:56 -0800 Subject: [PATCH] test: fix TAV tests for @cucumber/cucumber and @aws-sdk/client-s3 - Switch to 'npm run --ws test-all-versions ...' for running TAV tests, instead of 'lerna run test-all-versions ...' because nx sets 'npm_config_legacy_peer_deps=true' which breaks '@cucumber/cucumber@9.1.2' install and could break other installs by ignoring 'peerDependencies'. - Skip the bad '@aws-sdk/client-s3@3.377.0' release in TAV tests. Also: - Reduce the number of versions of 'aws-sdk' and '@aws-sdk/*' packages test in TAV tests from 249, 143, and 132 versions currently, to 7 each. - Add a top-level `npm run test-all-versions` script to run that script in all packages that have one. This is the equivalent of the "test-all-versions.yml" CI workflow. Fixes: #1828 --- .github/workflows/test-all-versions.pr.yml | 8 +-- .github/workflows/test-all-versions.yml | 9 +-- .github/workflows/unit-test.yml | 7 +-- package.json | 1 + .../.tav.yml | 12 ++-- scripts/parse-lerna-scopes.mjs | 56 ------------------- scripts/pr-labels-to-npm-workspace-args.mjs | 28 ++++++++++ 7 files changed, 45 insertions(+), 76 deletions(-) delete mode 100644 scripts/parse-lerna-scopes.mjs create mode 100644 scripts/pr-labels-to-npm-workspace-args.mjs diff --git a/.github/workflows/test-all-versions.pr.yml b/.github/workflows/test-all-versions.pr.yml index 158ad0d057..f1e35d4e19 100644 --- a/.github/workflows/test-all-versions.pr.yml +++ b/.github/workflows/test-all-versions.pr.yml @@ -16,7 +16,7 @@ jobs: env: PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} outputs: - args: ${{ steps.lerna-args.outputs.args }} + args: ${{ steps.npm-workspace-args.outputs.args }} steps: - name: Checkout uses: actions/checkout@v4 @@ -24,14 +24,14 @@ jobs: - name: Install lerna run: npm install -g lerna@6.6.2 - name: Parse labels into lerna scope arguments - id: lerna-args + id: npm-workspace-args run: | - OUTPUT=`node scripts/parse-lerna-scopes.mjs "$PR_LABELS"` + OUTPUT=`node scripts/pr-labels-to-npm-workspace-args.mjs "$PR_LABELS"` echo "args=$OUTPUT" >> $GITHUB_OUTPUT tav: uses: ./.github/workflows/test-all-versions.yml needs: parse-labels with: - lerna-args: ${{ needs.parse-labels.outputs.args }} + npm-workspace-args: ${{ needs.parse-labels.outputs.args }} if: ${{ needs.parse-labels.outputs.args != '' }} diff --git a/.github/workflows/test-all-versions.yml b/.github/workflows/test-all-versions.yml index 0d5b3f753c..5225010453 100644 --- a/.github/workflows/test-all-versions.yml +++ b/.github/workflows/test-all-versions.yml @@ -4,11 +4,11 @@ on: - cron: "30 4 * * *" workflow_dispatch: inputs: - lerna-args: + npm-workspace-args: type: string workflow_call: inputs: - lerna-args: + npm-workspace-args: required: true type: string @@ -115,9 +115,6 @@ jobs: node-version: ${{ matrix.node }} - name: Set MySQL variables run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} -e "SET GLOBAL log_output='TABLE'; SET GLOBAL general_log = 1;" mysql - - name: Legacy Peer Dependencies for npm 7 - if: matrix.node == '16' - run: npm config set legacy-peer-deps=true - name: Update npm to a version that supports workspaces (v7 or later) if: ${{ matrix.node < 16 }} run: npm install -g npm@9 # npm@9 supports node >=14.17.0 @@ -126,4 +123,4 @@ jobs: - name: Build run: npm run compile - name: Run test-all-versions - run: npx lerna run test-all-versions ${{ inputs.lerna-args }} ${{ matrix.lerna-extra-args }} --stream --concurrency 1 + run: npm run --if-present --workspaces test-all-versions ${{ inputs.npm-workspace-args }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 91f43a82fc..f5bfd63f06 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -123,9 +123,6 @@ jobs: node-version: ${{ matrix.node }} - name: Set MySQL variables run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} -e "SET GLOBAL log_output='TABLE'; SET GLOBAL general_log = 1;" mysql - - name: Legacy Peer Dependencies for npm 7 - if: matrix.node == '16' - run: npm config set legacy-peer-deps=true - name: Update npm to a version that supports workspaces (v7 or later) if: ${{ matrix.node < 16 }} run: npm install -g npm@9 # npm@9 supports node >=14.17.0 @@ -135,10 +132,10 @@ jobs: run: npm run compile - name: Unit tests (Full) if: matrix.code-coverage - run: npm run test -- ${{ matrix.lerna-extra-args }} + run: npm run test - name: Unit tests (Delta) if: ${{ !matrix.code-coverage }} - run: npm run test:ci:changed -- ${{ matrix.lerna-extra-args }} + run: npm run test:ci:changed - name: Build examples run: npm run compile:examples - name: Report Coverage diff --git a/package.json b/package.json index f543cb72a0..53dd98d557 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "test": "lerna run test", "test:ci:changed": "lerna run test --since origin/main", "test:browser": "lerna run test:browser --concurrency 1", + "test-all-versions": "npm run --if-present --workspaces test-all-versions", "bump": "lerna publish", "changelog": "lerna-changelog", "lint": "lerna run lint", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml b/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml index 565fc7382f..b678e4b15c 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml @@ -1,16 +1,18 @@ "aws-sdk": - # there are so many version to test, it can take forever. - # we will just sample few of them - versions: ">=2.1266.0 || 2.1262.0 || 2.1219.0 || 2.1048.0 || 2.1012.0 || 2.647.0 || 2.308.0" + # A small subset of releases in the range [2.308.0, 3) to reduce testing time. + versions: "2.308.0 || 2.548.0 || 2.785.0 || 2.1025.0 || 2.1265.0 || 2.1506.0 || >=2.1508.0" commands: - npm run test "@aws-sdk/client-s3": - versions: ">=3.223.0 || 3.218.0 || 3.216.0 || 3.154.0 || 3.107.0 || 3.54.0 || 3.6.1" + # A small subset of releases in the range [3.6.1, 4) to reduce testing time. + # - 3.377.0 was a bad release (see issue #1828). + versions: "3.6.1 || 3.53.0 || 3.163.0 || 3.266.0 || 3.354.0 || 3.458.0 || >=3.462.0" commands: - npm run test "@aws-sdk/client-sqs": - versions: ">=3.216.0 || 3.171.0 || 3.58.0 || 3.54.0 || 3.43.0 || 3.24.0" + # A small subset of releases in the range [3.24.0, 4) to reduce testing time. + versions: "3.24.0 || 3.85.0 || 3.194.0 || 3.278.0 || 3.357.0 || 3.461.0 || >=3.462.0" commands: - npm run test diff --git a/scripts/parse-lerna-scopes.mjs b/scripts/parse-lerna-scopes.mjs deleted file mode 100644 index 53a10dbd76..0000000000 --- a/scripts/parse-lerna-scopes.mjs +++ /dev/null @@ -1,56 +0,0 @@ -import * as childProcess from 'child_process'; -import { join } from 'path'; -import { readFileSync } from 'fs'; - -/* - Formats `--scope` arguments for lerna from "pkg:"-prefixed labels. - Takes a JSON string as an argument and returns the formatted args in stdout. - Filters out packages that do not have test-all-versions script because it's the only - location we are using this script. - - arg: '["pkg:404", "pkg:", "pkg:instrumentation-pino", "pkg:instrumentation-dns", "pkg:instrumentation-express", "urgent", "pkg:instrumentation-fs"]' - stdout: '--scope @opentelemetry/instrumentation-pino --scope @opentelemetry/instrumentation-express' -*/ - -const labels = JSON.parse(process.argv[2]); -const lernaList = JSON.parse( - childProcess.spawnSync('npx', ['lerna', 'list', '--json']).stdout - .toString('utf8') -); -const packageList = new Map( - lernaList.map((pkg) => { - return [pkg.name, pkg]; - }) -); -// Checking this is not strictly required, but saves the whole setup for TAV workflows -const hasTavScript = (pkgLocation) => { - const { scripts } = JSON.parse(readFileSync(join(pkgLocation, 'package.json'))); - return !!scripts['test-all-versions']; -}; - -console.error('Labels:', labels); -console.error('Packages:', [...packageList.keys()]); - -const scopes = labels - .filter((l) => { - return l.startsWith('pkg:'); - }) - .map((l) => { - return l.replace(/^pkg:/, '@opentelemetry/'); - }) - .filter((pkgName) => { - const info = packageList.get(pkgName); - if (!info) { - return false - } - return hasTavScript(info.location); - }) - -console.error('Scopes:', scopes); - -console.log( - scopes.map((scope) => { - return `--scope ${scope}`; - }) - .join(' ') -); diff --git a/scripts/pr-labels-to-npm-workspace-args.mjs b/scripts/pr-labels-to-npm-workspace-args.mjs new file mode 100644 index 0000000000..a81feff392 --- /dev/null +++ b/scripts/pr-labels-to-npm-workspace-args.mjs @@ -0,0 +1,28 @@ +/* + Formats `-w WORKSPACE` arguments for `npm run` from "pkg:"-prefixed labels. + Takes a JSON string as an argument and returns the formatted args in stdout. + + arg: '["pkg:instrumentation-pino", "urgent", "pkg:instrumentation-fs"]' + stdout: '-w @opentelemetry/instrumentation-pino -w @opentelemetry/instrumentation-fs' +*/ + +const labels = JSON.parse(process.argv[2]); + +console.error('Labels:', labels); + +const workspaces = labels + .filter((l) => { + return l.startsWith('pkg:'); + }) + .map((l) => { + return l.replace(/^pkg:/, '@opentelemetry/'); + }) + +console.error('Workspaces:', workspaces); + +console.log( + workspaces.map((w) => { + return `-w ${w}`; + }) + .join(' ') +);