|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { resolve } from 'path'; |
| 19 | +import { filterTasks, getTestTasks, TestReason } from './tasks'; |
| 20 | +import { argv } from 'yargs'; |
| 21 | +import { testConfig } from './testConfig'; |
| 22 | +import chalk from 'chalk'; |
| 23 | +const root = resolve(__dirname, '../..'); |
| 24 | + |
| 25 | +const inputTestConfigName = argv._[0].toString(); |
| 26 | +const config = testConfig[inputTestConfigName]!; |
| 27 | + |
| 28 | +async function checkIfTestsNeeded() { |
| 29 | + try { |
| 30 | + const testTasks = filterTasks(await getTestTasks(), config); |
| 31 | + if (testTasks.length > 0) { |
| 32 | + for (const task of testTasks) { |
| 33 | + if (task.reason === TestReason.Changed) { |
| 34 | + console.log( |
| 35 | + chalk`{yellow ${task.pkgName} (contains modified files)}` |
| 36 | + ); |
| 37 | + } else if (task.reason === TestReason.Dependent) { |
| 38 | + console.log( |
| 39 | + chalk`{yellow ${task.pkgName} (depends on modified files)}` |
| 40 | + ); |
| 41 | + } else { |
| 42 | + console.log(chalk`{yellow ${task.pkgName} (running all tests)}`); |
| 43 | + } |
| 44 | + } |
| 45 | + console.log(`::set-output name=NEEDS_TESTS::true`); |
| 46 | + } else { |
| 47 | + console.log(`::set-output name=NEEDS_TESTS::false`); |
| 48 | + } |
| 49 | + process.exit(0); |
| 50 | + } catch (e) { |
| 51 | + console.error(e); |
| 52 | + process.exit(1); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +checkIfTestsNeeded(); |
0 commit comments