|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import { getNbGitDiff } from './utils'; |
| 3 | + |
| 4 | +const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Exhaustive list of output variables to use in the CI. |
| 8 | + * |
| 9 | + * Those variables are used to determine if jobs should run, based on the changes |
| 10 | + * made in their respective `path`s. |
| 11 | + * |
| 12 | + * Negative paths should start with `:!`. |
| 13 | + * |
| 14 | + * The variable will be accessible in the CI via `steps.diff.outputs.<name>`. |
| 15 | + */ |
| 16 | +const VARIABLES_TO_CHECK = [ |
| 17 | + { |
| 18 | + name: 'GITHUB_ACTIONS_CHANGED', |
| 19 | + path: ['.github/actions', '.github/workflows'], |
| 20 | + }, |
| 21 | + { |
| 22 | + name: 'SPECS_CHANGED', |
| 23 | + path: ['specs', ':!specs/bundled'], |
| 24 | + }, |
| 25 | + { |
| 26 | + name: 'COMMON_SPECS_CHANGED', |
| 27 | + path: ['specs/common'], |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'TESTS_CHANGED', |
| 31 | + path: ['tests'], |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'SCRIPTS_CHANGED', |
| 35 | + path: ['scripts'], |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'GENERATORS_CHANGED', |
| 39 | + path: ['generators'], |
| 40 | + }, |
| 41 | + { |
| 42 | + name: 'JS_CLIENT_CHANGED', |
| 43 | + path: [JS_CLIENT_FOLDER, `:!${JS_CLIENT_FOLDER}/.github`], |
| 44 | + }, |
| 45 | + { |
| 46 | + name: 'JS_ALGOLIASEARCH_CHANGED', |
| 47 | + path: [ |
| 48 | + `${JS_CLIENT_FOLDER}/packages/algoliasearch`, |
| 49 | + `${JS_CLIENT_FOLDER}/packages/client-search`, |
| 50 | + `${JS_CLIENT_FOLDER}/packages/client-analytics`, |
| 51 | + `${JS_CLIENT_FOLDER}/packages/client-personalization`, |
| 52 | + ], |
| 53 | + }, |
| 54 | + { |
| 55 | + name: 'JS_COMMON_CHANGED', |
| 56 | + path: [ |
| 57 | + `${JS_CLIENT_FOLDER}/packages/client-common`, |
| 58 | + `${JS_CLIENT_FOLDER}/packages/requester-browser-xhr`, |
| 59 | + `${JS_CLIENT_FOLDER}/packages/requester-node-http`, |
| 60 | + ], |
| 61 | + }, |
| 62 | + { |
| 63 | + name: 'JS_COMMON_TESTS_CHANGED', |
| 64 | + path: [`${JS_CLIENT_FOLDER}/packages/client-common/src/__tests__`], |
| 65 | + }, |
| 66 | + { |
| 67 | + name: 'JS_TEMPLATE_CHANGED', |
| 68 | + path: ['templates/javascript'], |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'JAVA_CLIENT_CHANGED', |
| 72 | + path: ['clients/algoliasearch-client-java-2'], |
| 73 | + }, |
| 74 | + { |
| 75 | + name: 'JAVA_TEMPLATE_CHANGED', |
| 76 | + path: ['templates/java'], |
| 77 | + }, |
| 78 | + { |
| 79 | + name: 'PHP_CLIENT_CHANGED', |
| 80 | + path: ['clients/algoliasearch-client-php'], |
| 81 | + }, |
| 82 | + { |
| 83 | + name: 'PHP_TEMPLATE_CHANGED', |
| 84 | + path: ['templates/php'], |
| 85 | + }, |
| 86 | +]; |
| 87 | + |
| 88 | +/** |
| 89 | + * Outputs variables used in the CI to determine if a job should run. |
| 90 | + */ |
| 91 | +async function setRunVariables({ |
| 92 | + originBranch, |
| 93 | +}: { |
| 94 | + originBranch: string; |
| 95 | +}): Promise<void> { |
| 96 | + console.log(`Checking diff between ${originBranch} and HEAD`); |
| 97 | + |
| 98 | + for (const check of VARIABLES_TO_CHECK) { |
| 99 | + const diff = await getNbGitDiff({ |
| 100 | + branch: originBranch, |
| 101 | + path: check.path.join(' '), |
| 102 | + }); |
| 103 | + |
| 104 | + console.log(`Found ${diff} changes for '${check.name}'`); |
| 105 | + console.log(`::set-output name=${check.name}::${diff}`); |
| 106 | + } |
| 107 | + |
| 108 | + console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`); |
| 109 | +} |
| 110 | + |
| 111 | +if (require.main === module) { |
| 112 | + const [origin] = process.argv.slice(2); |
| 113 | + |
| 114 | + if (!origin) { |
| 115 | + throw new Error(`Unable to retrieve the origin: ${origin}`); |
| 116 | + } |
| 117 | + |
| 118 | + setRunVariables({ originBranch: origin }); |
| 119 | +} |
0 commit comments