chore: migrate away from ps1 in install-deps on Windows (#9876)

This commit is contained in:
Max Schmitt 2021-10-29 19:32:56 +02:00 committed by GitHub
parent 9f3f25916e
commit 59a406a586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 11 deletions

View File

@ -1,5 +0,0 @@
$osInfo = Get-WmiObject -Class Win32_OperatingSystem
# check if running on Windows Server
if ($osInfo.ProductType -eq 3) {
Install-WindowsFeature Server-Media-Foundation
}

View File

@ -22,8 +22,6 @@ import { getUbuntuVersion } from './ubuntuVersion';
import * as utils from './utils';
import { buildPlaywrightCLICommand } from './registry';
const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
const checkExecutable = (filePath: string) => fs.promises.access(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
function isSupportedWindowsVersion(): boolean {
@ -39,11 +37,33 @@ function isSupportedWindowsVersion(): boolean {
export type DependencyGroup = 'chromium' | 'firefox' | 'webkit' | 'tools';
export async function installDependenciesWindows(targets: Set<DependencyGroup>) {
if (targets.has('chromium')) {
const { code } = await utils.spawnAsync('powershell.exe', ['-File', path.join(BIN_DIRECTORY, 'install_media_pack.ps1')], { cwd: BIN_DIRECTORY, stdio: 'inherit' });
if (!targets.has('chromium'))
return;
if (!await isWindowsServer())
return;
const { code } = await utils.spawnAsync('dism.exe', ['/Online', '/Enable-Feature', '/FeatureName:ServerMediaFoundation', '/Quiet'], { stdio: 'inherit' });
if (code !== 0)
throw new Error('Failed to install windows dependencies!');
}
async function isWindowsServer(): Promise<boolean> {
/**
* ProductType Enum:
* 0 = Unknown - Product type is unknown
* 1 = WorkStation - System is a workstation
* 2 = DomainController - System is a domain controller
* 3 = Server - System is a server
* @see https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.producttype?view=powershellsdk-1.1.0
*/
const { code, stdout } = await utils.spawnAsync('wmic.exe', ['path', 'Win32_OperatingSystem', 'get', 'ProductType', '/VALUE']);
if (code !== 0)
throw new Error('Failed to get product type version!');
for (const line of stdout.trim().split('\n')) {
const [key, value] = line.split('=');
if (key === 'ProductType')
return parseInt(value, 10) === 3;
}
throw new Error('Failed to parse product type version!\nstdout:' + stdout);
}
export async function installDependenciesLinux(targets: Set<DependencyGroup>) {