Skip to content
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

Prevent build failing when PSI fails #178

Merged
merged 2 commits into from
May 20, 2020
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
14 changes: 10 additions & 4 deletions packages/cli/src/lib/cmds/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ export async function build(

if (!args.skipPwaValidation) {
log.info('Checking PWA Quality Criteria...');
const pwaValidationResult = (await pwaValidationPromise)!;
printValidationResult(pwaValidationResult, log);
if (pwaValidationResult.status === 'FAIL') {
log.warn('PWA Quality Criteria check failed.');
try {
const pwaValidationResult = (await pwaValidationPromise)!;
printValidationResult(pwaValidationResult, log);
if (pwaValidationResult.status === 'FAIL') {
log.warn('PWA Quality Criteria check failed.');
}
} catch (e) {
const message = 'Failed to run the PWA Quality Criteria checks. Skipping.';
log.debug(e);
log.warn(message);
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/lib/cmds/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import {AndroidSdkTools, Config, JdkHelper, Log} from '@bubblewrap/core';
import {ParsedArgs} from 'minimist';

const APK_FILE_PARAM = '--apkFile';
const VERBOSE_PARAM = '--verbose';
const DEFAULT_APK_FILE = './app-release-signed.apk';

const PARAMETERS_TO_IGNORE = ['--verbose', '-r'];

export async function install(
args: ParsedArgs, config: Config, log = new Log('install')): Promise<boolean> {
const jdkHelper = new JdkHelper(process, config);
Expand All @@ -34,7 +35,7 @@ export async function install(
// 2. So, we want to start collecting args from parameter 3 and ignore any a possible
// `--apkFile`, which is specific to install. Extra parameters are passed through to `adb`.
const originalArgs = process.argv.slice(3).filter(
(v) => !v.startsWith(APK_FILE_PARAM) && !v.startsWith(VERBOSE_PARAM));
(v) => !v.startsWith(APK_FILE_PARAM) && PARAMETERS_TO_IGNORE.indexOf(v) < 0);
await androidSdkTools.install(apkFile, originalArgs);
return true;
}
4 changes: 2 additions & 2 deletions packages/core/src/lib/Log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export default class Log {
* @param args extra arguments for the console.
*/
error(message: string, ...args: string[]): void {
this.output.log('\n');
this.output.error('\n');
this.log(this.output.error, this.red('ERROR ' + message), ...args);
this.output.log('\n');
this.output.error('\n');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lib/androidSdk/AndroidSdkTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ export class AndroidSdkTools {
const env = this.getEnv();
const installCmd = [
`"${this.pathJoin(this.getAndroidHome(), '/platform-tools/adb')}"`,
...passthroughArgs,
'install',
'-r', // Replace app if another with the same package id already installed.
...passthroughArgs,
apkFilePath,
];
await util.execute(installCmd, env, this.log);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,21 @@ describe('AndroidSdkTools', () => {
expectedCwd: [
'"/home/user/android-sdk/platform-tools/adb"',
'install',
'-r',
'app-release-signed.apk',
]},
{platform: 'darwin',
expectedCwd: [
'"/home/user/android-sdk/platform-tools/adb"',
'install',
'-r',
'app-release-signed.apk',
]},
{platform: 'win32',
expectedCwd: [
'"C:\\Users\\user\\android-sdk\\platform-tools\\adb"',
'install',
'-r',
'app-release-signed.apk',
]},
];
Expand Down
8 changes: 7 additions & 1 deletion packages/validator/src/lib/PwaValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ export class PwaValidator {
.setStrategy('mobile')
.build();

const psiResult = await this.psi.runPageSpeedInsights(psiRequest);
let psiResult;
try {
psiResult = await this.psi.runPageSpeedInsights(psiRequest);
} catch (e) {
throw new Error('Error calling the PageSpeed Insights API: ' + e);
}

const pwaScore = psiResult.lighthouseResult.categories.pwa.score;
const performanceScore = psiResult.lighthouseResult.categories.performance.score;
if (pwaScore === null || performanceScore === null || isNaN(pwaScore) ||
Expand Down