|
| 1 | +/** |
| 2 | + * The main entry point for cross-platform build scripts. |
| 3 | + * Usage (in repository root directory): |
| 4 | + * ts-node -P ./scripts ./scripts [step1] [step2 ... stepN] |
| 5 | + * Alias for above: |
| 6 | + * npm run script [step1] [step2 ... stepN] |
| 7 | + */ |
| 8 | + |
| 9 | +const [, , ...steps] = process.argv; |
| 10 | +const { |
| 11 | + CI_PULL_REQUEST, |
| 12 | + TRACE_TEST_EXCLUDE_INTEGRATION, |
| 13 | + TRACE_SYSTEM_TEST_ENCRYPTED_CREDENTIALS_KEY, |
| 14 | + TRACE_SYSTEM_TEST_ENCRYPTED_CREDENTIALS_IV |
| 15 | +} = process.env; |
| 16 | + |
| 17 | +import { checkInstall } from './check-install'; |
| 18 | +import { compile } from './compile'; |
| 19 | +import { encryptCredentials, decryptCredentials } from './credentials'; |
| 20 | +import { initTestFixtures } from './init-test-fixtures'; |
| 21 | +import { reportCoverage } from './report-coverage'; |
| 22 | +import { runTests } from './run-tests'; |
| 23 | +import { testNonInterference } from './test-non-interference'; |
| 24 | +import { BUILD_DIRECTORY, existsP, spawnP } from './utils'; |
| 25 | + |
| 26 | +// The identifying string in the service account credentials file path. |
| 27 | +const keyID = 'de480e4f9023'; |
| 28 | + |
| 29 | +// Globs to exclude when running unit tests only. |
| 30 | +const unitTestExcludeGlobs: string[] = TRACE_TEST_EXCLUDE_INTEGRATION ? [ |
| 31 | + `${BUILD_DIRECTORY}/test/plugins/test-*`, |
| 32 | + `${BUILD_DIRECTORY}/test/test-agent-stopped.js`, |
| 33 | + `${BUILD_DIRECTORY}/test/test-grpc-context.js`, |
| 34 | + `${BUILD_DIRECTORY}/test/test-mysql-pool.js`, |
| 35 | + `${BUILD_DIRECTORY}/test/test-plugins-*`, |
| 36 | + `${BUILD_DIRECTORY}/test/test-trace-web-frameworks.js`, |
| 37 | + `${BUILD_DIRECTORY}/test/test-unpatch.js` |
| 38 | +] : []; |
| 39 | + |
| 40 | +/** |
| 41 | + * Sequentially runs a list of commands. |
| 42 | + */ |
| 43 | +async function run(steps: string[]) { |
| 44 | + for (const step of steps) { |
| 45 | + console.log(`> Running step: ${step}`); |
| 46 | + // If the step string is prefixed with "npm-", treat it as an "npm run" |
| 47 | + // command, and then short-circuit. |
| 48 | + if (step.indexOf('npm-') === 0) { |
| 49 | + const moduleAndArgs = step.split('-'); |
| 50 | + await spawnP( |
| 51 | + 'npm', |
| 52 | + [ |
| 53 | + 'run', |
| 54 | + moduleAndArgs.slice(1).join('-') |
| 55 | + ] |
| 56 | + ); |
| 57 | + continue; |
| 58 | + } else if (step.startsWith('compile-')) { |
| 59 | + const [, languageLevel, strict] = step.split('-'); |
| 60 | + await compile({ strict: !!strict, languageLevel }); |
| 61 | + continue; |
| 62 | + } else { |
| 63 | + switch (step) { |
| 64 | + case 'run-unit-tests': |
| 65 | + await runTests({ |
| 66 | + includeGlobs: [ |
| 67 | + `${BUILD_DIRECTORY}/test/test-*.js`, |
| 68 | + `${BUILD_DIRECTORY}/test/plugins/test-*.js` |
| 69 | + ], |
| 70 | + excludeGlobs: unitTestExcludeGlobs, |
| 71 | + rootDir: BUILD_DIRECTORY, |
| 72 | + coverage: false, |
| 73 | + timeout: 4000 |
| 74 | + }); |
| 75 | + break; |
| 76 | + case 'run-unit-tests-with-coverage': |
| 77 | + await runTests({ |
| 78 | + includeGlobs: [ |
| 79 | + `${BUILD_DIRECTORY}/test/test-*.js`, |
| 80 | + `${BUILD_DIRECTORY}/test/plugins/test-*.js` |
| 81 | + ], |
| 82 | + excludeGlobs: unitTestExcludeGlobs, |
| 83 | + rootDir: BUILD_DIRECTORY, |
| 84 | + coverage: true, |
| 85 | + timeout: 4000 |
| 86 | + }); |
| 87 | + break; |
| 88 | + case 'run-system-tests': |
| 89 | + await spawnP( |
| 90 | + 'npm', ['install'], { cwd: 'system-test' } |
| 91 | + ); |
| 92 | + if (CI_PULL_REQUEST && !(await existsP('node-team-test-d0b0be11c23d.json'))) { |
| 93 | + console.log('> Not running system tests in PRs'); |
| 94 | + } else { |
| 95 | + await runTests({ |
| 96 | + includeGlobs: [ |
| 97 | + `system-test/*.js`, |
| 98 | + ], |
| 99 | + rootDir: '.', |
| 100 | + coverage: false |
| 101 | + }); |
| 102 | + } |
| 103 | + break; |
| 104 | + case 'report-coverage': |
| 105 | + await reportCoverage(); |
| 106 | + break; |
| 107 | + case 'test-non-interference': |
| 108 | + await testNonInterference(); |
| 109 | + break; |
| 110 | + default: |
| 111 | + console.log(`> ${step}: not found`); |
| 112 | + break; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +run(steps).catch((err) => { |
| 119 | + console.error(err); |
| 120 | + process.exit(1); |
| 121 | +}); |
0 commit comments