Skip to content

Check if tests needed before build for the Test Auth workflow #5056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-changed-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
cp config/ci.config.json config/project.json
yarn
- name: build
run: yarn build
run: yarn build:changed auth --buildAll
- name: Run tests on changed packages
run: xvfb-run yarn test:changed auth
28 changes: 22 additions & 6 deletions scripts/ci-test/build_changed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

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

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

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

const config = testConfig[inputTestConfigName]!;

buildForTests(config, buildAppExp, buildAppCompat);
buildForTests(config, argv);

interface Options {
buildAppExp?: boolean;
buildAppCompat?: boolean;
buildAll?: boolean;
}

async function buildForTests(
config: TestConfig,
buildAppExp = false,
buildAppCompat = false
{ buildAppExp = false, buildAppCompat = false, buildAll = false }: Options
) {
try {
const testTasks = filterTasks(await getTestTasks(), config);

// print tasks for info
logTasks(testTasks);
if (testTasks.length === 0) {
console.log(chalk`{green No test tasks. Skipping all builds }`);
return;
}

// build all and return
if (buildAll) {
await spawn('yarn', ['build'], { stdio: 'inherit', cwd: root });
return;
}

// hack to build Firestore which depends on @firebase/app-exp (because of firestore exp),
// but doesn't list it as a dependency in its package.json
// TODO: remove once modular SDKs become official
Expand Down
17 changes: 17 additions & 0 deletions scripts/ci-test/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,20 @@ export function filterTasks(

return filteredTasks;
}

export function logTasks(testTasks: TestTask[]): void {
for (const task of testTasks) {
switch (task.reason) {
case TestReason.Changed:
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
break;
case TestReason.Dependent:
console.log(
chalk`{yellow ${task.pkgName} (depends on modified files)}`
);
break;
default:
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
}
}
}
4 changes: 3 additions & 1 deletion scripts/ci-test/test_changed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { resolve } from 'path';
import { spawn } from 'child-process-promise';
import { TestReason, filterTasks, getTestTasks } from './tasks';
import { TestReason, filterTasks, getTestTasks, logTasks } from './tasks';
import chalk from 'chalk';
import { argv } from 'yargs';
import { TestConfig, testConfig } from './testConfig';
Expand Down Expand Up @@ -51,6 +51,8 @@ async function runTests(config: TestConfig) {
try {
const testTasks = filterTasks(await getTestTasks(), config);

// print tasks for info
logTasks(testTasks);
if (testTasks.length === 0) {
chalk`{green No test tasks. Skipping all tests }`;
process.exit(0);
Expand Down