Skip to content

Commit c2d0fdc

Browse files
hsubox76Feiyang1
andauthored
Check if tests needed before build for the Test Auth workflow (#5056)
* Check if tests needed before build * Add config name * support buildAll in build_changed.ts Co-authored-by: Feiyang1 <[email protected]>
1 parent 870dd5e commit c2d0fdc

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

.github/workflows/test-changed-auth.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828
cp config/ci.config.json config/project.json
2929
yarn
3030
- name: build
31-
run: yarn build
31+
run: yarn build:changed auth --buildAll
3232
- name: Run tests on changed packages
3333
run: xvfb-run yarn test:changed auth

scripts/ci-test/build_changed.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { TestReason, getTestTasks, filterTasks } from './tasks';
18+
import { TestReason, getTestTasks, filterTasks, logTasks } from './tasks';
1919
import { spawn } from 'child-process-promise';
2020
import chalk from 'chalk';
2121
import { resolve } from 'path';
@@ -34,12 +34,16 @@ const argv = yargs.options({
3434
type: 'boolean',
3535
desc:
3636
'whether or not build @firebase/app-compat first. It is a hack required to build Firestore'
37+
},
38+
buildAll: {
39+
type: 'boolean',
40+
desc:
41+
'if true, build all packages. Used in Test Auth workflow because Auth tests depends on the firebase package'
3742
}
3843
}).argv;
3944

4045
const allTestConfigNames = Object.keys(testConfig);
4146
const inputTestConfigName = argv._[0].toString();
42-
const { buildAppExp, buildAppCompat } = argv;
4347

4448
if (!inputTestConfigName) {
4549
throw Error(`
@@ -59,21 +63,33 @@ if (!allTestConfigNames.includes(inputTestConfigName)) {
5963

6064
const config = testConfig[inputTestConfigName]!;
6165

62-
buildForTests(config, buildAppExp, buildAppCompat);
66+
buildForTests(config, argv);
67+
68+
interface Options {
69+
buildAppExp?: boolean;
70+
buildAppCompat?: boolean;
71+
buildAll?: boolean;
72+
}
6373

6474
async function buildForTests(
6575
config: TestConfig,
66-
buildAppExp = false,
67-
buildAppCompat = false
76+
{ buildAppExp = false, buildAppCompat = false, buildAll = false }: Options
6877
) {
6978
try {
7079
const testTasks = filterTasks(await getTestTasks(), config);
71-
80+
// print tasks for info
81+
logTasks(testTasks);
7282
if (testTasks.length === 0) {
7383
console.log(chalk`{green No test tasks. Skipping all builds }`);
7484
return;
7585
}
7686

87+
// build all and return
88+
if (buildAll) {
89+
await spawn('yarn', ['build'], { stdio: 'inherit', cwd: root });
90+
return;
91+
}
92+
7793
// hack to build Firestore which depends on @firebase/app-exp (because of firestore exp),
7894
// but doesn't list it as a dependency in its package.json
7995
// TODO: remove once modular SDKs become official

scripts/ci-test/tasks.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,20 @@ export function filterTasks(
199199

200200
return filteredTasks;
201201
}
202+
203+
export function logTasks(testTasks: TestTask[]): void {
204+
for (const task of testTasks) {
205+
switch (task.reason) {
206+
case TestReason.Changed:
207+
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
208+
break;
209+
case TestReason.Dependent:
210+
console.log(
211+
chalk`{yellow ${task.pkgName} (depends on modified files)}`
212+
);
213+
break;
214+
default:
215+
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
216+
}
217+
}
218+
}

scripts/ci-test/test_changed.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { resolve } from 'path';
1919
import { spawn } from 'child-process-promise';
20-
import { TestReason, filterTasks, getTestTasks } from './tasks';
20+
import { TestReason, filterTasks, getTestTasks, logTasks } from './tasks';
2121
import chalk from 'chalk';
2222
import { argv } from 'yargs';
2323
import { TestConfig, testConfig } from './testConfig';
@@ -51,6 +51,8 @@ async function runTests(config: TestConfig) {
5151
try {
5252
const testTasks = filterTasks(await getTestTasks(), config);
5353

54+
// print tasks for info
55+
logTasks(testTasks);
5456
if (testTasks.length === 0) {
5557
chalk`{green No test tasks. Skipping all tests }`;
5658
process.exit(0);

0 commit comments

Comments
 (0)