chore: download android driver from the cdn (#18466)

This commit is contained in:
Pavel Feldman 2022-10-31 16:08:26 -07:00 committed by GitHub
parent 9cc5ca0cd4
commit 4d53fd9c63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 11 deletions

View file

@ -46,6 +46,11 @@
"name": "ffmpeg", "name": "ffmpeg",
"revision": "1008", "revision": "1008",
"installByDefault": true "installByDefault": true
},
{
"name": "android",
"revision": "1000",
"installByDefault": false
} }
] ]
} }

View file

@ -5,3 +5,4 @@
../../utils/ ../../utils/
../../utilsBundle.ts ../../utilsBundle.ts
../chromium/ ../chromium/
../registry/

View file

@ -36,6 +36,7 @@ import { TimeoutSettings } from '../../common/timeoutSettings';
import type * as channels from '@protocol/channels'; import type * as channels from '@protocol/channels';
import { SdkObject, serverSideCallMetadata } from '../instrumentation'; import { SdkObject, serverSideCallMetadata } from '../instrumentation';
import { DEFAULT_ARGS } from '../chromium/chromium'; import { DEFAULT_ARGS } from '../chromium/chromium';
import { registry } from '../registry';
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-'); const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
@ -186,8 +187,13 @@ export class AndroidDevice extends SdkObject {
await this.shell(`cmd package uninstall com.microsoft.playwright.androiddriver.test`); await this.shell(`cmd package uninstall com.microsoft.playwright.androiddriver.test`);
debug('pw:android')('Installing the new driver'); debug('pw:android')('Installing the new driver');
for (const file of ['android-driver.apk', 'android-driver-target.apk']) const executable = registry.findExecutable('android')!;
await this.installApk(await fs.promises.readFile(require.resolve(`../../../bin/${file}`))); for (const file of ['android-driver.apk', 'android-driver-target.apk']) {
const fullName = path.join(executable.directory!, file);
if (!fs.existsSync(fullName))
throw new Error('Please install Android driver apk using `npx playwright install android`');
await this.installApk(await fs.promises.readFile(fullName));
}
} else { } else {
debug('pw:android')('Skipping the driver installation'); debug('pw:android')('Skipping the driver installation');
} }

View file

@ -26,7 +26,7 @@ import { extract } from '../../zipBundle';
import { ManualPromise } from '../../utils/manualPromise'; import { ManualPromise } from '../../utils/manualPromise';
import { colors } from '../../utilsBundle'; import { colors } from '../../utilsBundle';
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise<boolean> { export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string | undefined, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise<boolean> {
if (await existsAsync(browserDirectory)) { if (await existsAsync(browserDirectory)) {
// Already downloaded. // Already downloaded.
debugLogger.log('install', `${title} is already downloaded.`); debugLogger.log('install', `${title} is already downloaded.`);
@ -54,8 +54,10 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec
debugLogger.log('install', `-- zip: ${zipPath}`); debugLogger.log('install', `-- zip: ${zipPath}`);
debugLogger.log('install', `-- location: ${browserDirectory}`); debugLogger.log('install', `-- location: ${browserDirectory}`);
await extract(zipPath, { dir: browserDirectory }); await extract(zipPath, { dir: browserDirectory });
debugLogger.log('install', `fixing permissions at ${executablePath}`); if (executablePath) {
await fs.promises.chmod(executablePath, 0o755); debugLogger.log('install', `fixing permissions at ${executablePath}`);
await fs.promises.chmod(executablePath, 0o755);
}
} catch (e) { } catch (e) {
debugLogger.log('install', `FAILED installation ${title} with error: ${e}`); debugLogger.log('install', `FAILED installation ${title} with error: ${e}`);
process.exitCode = 1; process.exitCode = 1;

View file

@ -214,6 +214,9 @@ const DOWNLOAD_PATHS = {
'mac12-arm64': 'builds/ffmpeg/%s/ffmpeg-mac-arm64.zip', 'mac12-arm64': 'builds/ffmpeg/%s/ffmpeg-mac-arm64.zip',
'win64': 'builds/ffmpeg/%s/ffmpeg-win64.zip', 'win64': 'builds/ffmpeg/%s/ffmpeg-win64.zip',
}, },
'android': {
'<unknown>': 'builds/android/%s/android.zip',
},
}; };
export const registryDirectory = (() => { export const registryDirectory = (() => {
@ -300,7 +303,7 @@ function readDescriptors(browsersJSON: BrowsersJSON) {
} }
export type BrowserName = 'chromium' | 'firefox' | 'webkit'; export type BrowserName = 'chromium' | 'firefox' | 'webkit';
type InternalTool = 'ffmpeg' | 'firefox-beta' | 'chromium-with-symbols' | 'chromium-tip-of-tree'; type InternalTool = 'ffmpeg' | 'firefox-beta' | 'chromium-with-symbols' | 'chromium-tip-of-tree' | 'android';
type ChromiumChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary'; type ChromiumChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary';
const allDownloadable = ['chromium', 'firefox', 'webkit', 'ffmpeg', 'firefox-beta', 'chromium-with-symbols', 'chromium-tip-of-tree']; const allDownloadable = ['chromium', 'firefox', 'webkit', 'ffmpeg', 'firefox-beta', 'chromium-with-symbols', 'chromium-tip-of-tree'];
@ -569,6 +572,21 @@ export class Registry {
_dependencyGroup: 'tools', _dependencyGroup: 'tools',
_isHermeticInstallation: true, _isHermeticInstallation: true,
}); });
const android = descriptors.find(d => d.name === 'android')!;
this._executables.push({
type: 'tool',
name: 'android',
browserName: undefined,
directory: android.dir,
executablePath: () => undefined,
executablePathOrDie: () => '',
installType: 'download-on-demand',
validateHostRequirements: () => Promise.resolve(),
downloadURLs: this._downloadURLs(android),
_install: () => this._downloadExecutable(android),
_dependencyGroup: 'tools',
_isHermeticInstallation: true,
});
} }
private _createChromiumChannel(name: ChromiumChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl { private _createChromiumChannel(name: ChromiumChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl {
@ -743,7 +761,8 @@ export class Registry {
} }
private _downloadURLs(descriptor: BrowsersJSONDescriptor): string[] { private _downloadURLs(descriptor: BrowsersJSONDescriptor): string[] {
const downloadPathTemplate: string|undefined = (DOWNLOAD_PATHS as any)[descriptor.name][hostPlatform]; const paths = (DOWNLOAD_PATHS as any)[descriptor.name];
const downloadPathTemplate: string|undefined = paths[hostPlatform] || paths['<unknown>'];
if (!downloadPathTemplate) if (!downloadPathTemplate)
return []; return [];
const downloadPath = util.format(downloadPathTemplate, descriptor.revision); const downloadPath = util.format(downloadPathTemplate, descriptor.revision);
@ -763,9 +782,9 @@ export class Registry {
return downloadURLs; return downloadURLs;
} }
private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath: string | undefined) { private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string) {
const downloadURLs = this._downloadURLs(descriptor); const downloadURLs = this._downloadURLs(descriptor);
if (!downloadURLs.length || !executablePath) if (!downloadURLs.length)
throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${hostPlatform}`); throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${hostPlatform}`);
if (hostPlatform === 'generic-linux' || hostPlatform === 'generic-linux-arm64') if (hostPlatform === 'generic-linux' || hostPlatform === 'generic-linux-arm64')
logPolitely('BEWARE: your OS is not officially supported by Playwright; downloading fallback build.'); logPolitely('BEWARE: your OS is not officially supported by Playwright; downloading fallback build.');

View file

@ -10,5 +10,6 @@ if [ "$?" -ne "0" ]; then
exit 1 exit 1
fi fi
cp src/server/android/driver/app/build/outputs/apk/debug/app-debug.apk ./bin/android-driver-target.apk # These should be uploaded to the CDN
cp src/server/android/driver/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk ./bin/android-driver.apk # cp src/server/android/driver/app/build/outputs/apk/debug/app-debug.apk ./bin/android-driver-target.apk
# cp src/server/android/driver/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk ./bin/android-driver.apk