From 57df9006ca489fe0861d92a682d337a7b79a5062 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 10 Mar 2021 12:04:30 -0800 Subject: [PATCH] chore: migrate from gha to explicit npx playwright install --- .github/workflows/tests.yml | 18 +-- src/cli/cli.ts | 22 +-- src/install/installDeps.ts | 266 ++++++++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+), 18 deletions(-) create mode 100644 src/install/installDeps.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 99169720ac2333..b3c035040f79e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,9 +29,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: mkdir -p coredumps # Set core dump file name pattern - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern' @@ -64,9 +64,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json --shard=${{ matrix.shard }}/2 env: BROWSER: ${{ matrix.browser }} @@ -94,9 +94,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json shell: bash env: @@ -125,9 +125,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node_version }} - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: bash packages/installation-tests/installation-tests.sh headful_linux: @@ -142,9 +142,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: mkdir -p coredumps # Set core dump file name pattern - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern' @@ -177,9 +177,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: mkdir -p coredumps # Set core dump file name pattern - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern' @@ -211,9 +211,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: mkdir -p coredumps # Set core dump file name pattern - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern' @@ -240,9 +240,9 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 14 - - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build + - run: node lib/cli/cli install - name: Create Android Emulator run: utils/avd_recreate.sh - name: Start Android Emulator @@ -269,11 +269,11 @@ jobs: - uses: actions/setup-node@v1 with: node-version: 10 - - uses: microsoft/playwright-github-action@v1 - name: Install Chrome Stable run: sudo apt install google-chrome-stable - run: npm ci - run: npm run build + - run: node lib/cli/cli install - run: mkdir -p coredumps # Set core dump file name pattern - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern' diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 625eef63300377..fca738795da5d4 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -31,6 +31,7 @@ import { Page } from '../client/page'; import { BrowserType } from '../client/browserType'; import { BrowserContextOptions, LaunchOptions } from '../client/types'; import { spawn } from 'child_process'; +import { installDeps } from '../install/installDeps'; program .version('Version ' + require('../../package.json').version) @@ -82,18 +83,21 @@ program program .command('install [browserType...]') .description('ensure browsers necessary for this version of Playwright are installed') - .action(function(browserType) { - const allBrowsers = new Set(['chromium', 'firefox', 'webkit']); - for (const type of browserType) { - if (!allBrowsers.has(type)) { - console.log(`Invalid browser name: '${type}'. Expecting 'chromium', 'firefox' or 'webkit'.`); - process.exit(1); + .action(async function(browserType) { + try { + await installDeps(); + const allBrowsers = new Set(['chromium', 'firefox', 'webkit']); + for (const type of browserType) { + if (!allBrowsers.has(type)) { + console.log(`Invalid browser name: '${type}'. Expecting 'chromium', 'firefox' or 'webkit'.`); + process.exit(1); + } } - } - installBrowsers(browserType.length ? browserType : undefined).catch((e: any) => { + await installBrowsers(browserType.length ? browserType : undefined); + } catch (e) { console.log(`Failed to install browsers\n${e}`); process.exit(1); - }); + } }); const browsers = [ diff --git a/src/install/installDeps.ts b/src/install/installDeps.ts new file mode 100644 index 00000000000000..dd35cff95dc6b7 --- /dev/null +++ b/src/install/installDeps.ts @@ -0,0 +1,266 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import childProcess from 'child_process'; +import os from 'os'; +import { getUbuntuVersion } from '../utils/ubuntuVersion'; + +const DEPENDENCIES = { + 'ubuntu18.04': { + chromium: [ + 'fonts-liberation', + 'libasound2', + 'libatk-bridge2.0-0', + 'libatk1.0-0', + 'libatspi2.0-0', + 'libcairo2', + 'libcups2', + 'libdbus-1-3', + 'libdrm2', + 'libgbm1', + 'libgdk-pixbuf2.0-0', + 'libglib2.0-0', + 'libgtk-3-0', + 'libnspr4', + 'libnss3', + 'libpango-1.0-0', + 'libpangocairo-1.0-0', + 'libx11-6', + 'libx11-xcb1', + 'libxcb-dri3-0', + 'libxcb1', + 'libxcomposite1', + 'libxdamage1', + 'libxext6', + 'libxfixes3', + 'libxi6', + 'libxrandr2', + 'libxtst6' + ], + firefox: [ + 'libatk1.0-0', + 'libcairo-gobject2', + 'libcairo2', + 'libdbus-1-3', + 'libdbus-glib-1-2', + 'libfontconfig1', + 'libfreetype6', + 'libgdk-pixbuf2.0-0', + 'libglib2.0-0', + 'libgtk-3-0', + 'libgtk2.0-0', + 'libpango-1.0-0', + 'libpangocairo-1.0-0', + 'libpangoft2-1.0-0', + 'libx11-6', + 'libx11-xcb1', + 'libxcb-shm0', + 'libxcb1', + 'libxcomposite1', + 'libxcursor1', + 'libxdamage1', + 'libxext6', + 'libxfixes3', + 'libxi6', + 'libxrender1', + 'libxt6' + ], + webkit: [ + 'gstreamer1.0-libav', + 'gstreamer1.0-plugins-bad', + 'gstreamer1.0-plugins-base', + 'gstreamer1.0-plugins-good', + 'libatk-bridge2.0-0', + 'libatk1.0-0', + 'libbrotli1', + 'libcairo2', + 'libegl1', + 'libenchant1c2a', + 'libepoxy0', + 'libfontconfig1', + 'libfreetype6', + 'libgdk-pixbuf2.0-0', + 'libgl1', + 'libgles2', + 'libglib2.0-0', + 'libgstreamer-gl1.0-0', + 'libgstreamer1.0-0', + 'libgtk-3-0', + 'libharfbuzz-icu0', + 'libharfbuzz0b', + 'libhyphen0', + 'libicu60', + 'libjpeg-turbo8', + 'libnotify4', + 'libopenjp2-7', + 'libopus0', + 'libpango-1.0-0', + 'libpng16-16', + 'libsecret-1-0', + 'libvpx5', + 'libwayland-client0', + 'libwayland-egl1', + 'libwayland-server0', + 'libwebp6', + 'libwebpdemux2', + 'libwoff1', + 'libx11-6', + 'libxcomposite1', + 'libxdamage1', + 'libxkbcommon0', + 'libxml2', + 'libxslt1.1' + ], + }, + + 'ubuntu20.04': { + chromium: [ + 'fonts-liberation', + 'libasound2', + 'libatk-bridge2.0-0', + 'libatk1.0-0', + 'libatspi2.0-0', + 'libcairo2', + 'libcups2', + 'libdbus-1-3', + 'libdrm2', + 'libgbm1', + 'libgdk-pixbuf2.0-0', + 'libglib2.0-0', + 'libgtk-3-0', + 'libnspr4', + 'libnss3', + 'libpango-1.0-0', + 'libpangocairo-1.0-0', + 'libx11-6', + 'libx11-xcb1', + 'libxcb-dri3-0', + 'libxcb1', + 'libxcomposite1', + 'libxdamage1', + 'libxext6', + 'libxfixes3', + 'libxi6', + 'libxrandr2', + 'libxtst6' + ], + firefox: [ + 'libatk1.0-0', + 'libcairo-gobject2', + 'libcairo2', + 'libdbus-1-3', + 'libdbus-glib-1-2', + 'libfontconfig1', + 'libfreetype6', + 'libgdk-pixbuf2.0-0', + 'libglib2.0-0', + 'libgtk-3-0', + 'libgtk2.0-0', + 'libpango-1.0-0', + 'libpangocairo-1.0-0', + 'libpangoft2-1.0-0', + 'libx11-6', + 'libx11-xcb1', + 'libxcb-shm0', + 'libxcb1', + 'libxcomposite1', + 'libxcursor1', + 'libxdamage1', + 'libxext6', + 'libxfixes3', + 'libxi6', + 'libxrender1', + 'libxt6' + ], + webkit: [ + 'gstreamer1.0-libav', + 'gstreamer1.0-plugins-bad', + 'gstreamer1.0-plugins-base', + 'gstreamer1.0-plugins-good', + 'libatk-bridge2.0-0', + 'libatk1.0-0', + 'libcairo2', + 'libegl1', + 'libenchant1c2a', + 'libepoxy0', + 'libfontconfig1', + 'libfreetype6', + 'libgdk-pixbuf2.0-0', + 'libgl1', + 'libgles2', + 'libglib2.0-0', + 'libgstreamer-gl1.0-0', + 'libgstreamer1.0-0', + 'libgtk-3-0', + 'libharfbuzz-icu0', + 'libharfbuzz0b', + 'libhyphen0', + 'libicu66', + 'libjpeg-turbo8', + 'libnotify4', + 'libopenjp2-7', + 'libopus0', + 'libpango-1.0-0', + 'libpng16-16', + 'libsecret-1-0', + 'libsoup2.4-1', + 'libvpx6', + 'libwayland-client0', + 'libwayland-egl1', + 'libwayland-server0', + 'libwebp6', + 'libwebpdemux2', + 'libwoff1', + 'libx11-6', + 'libxcomposite1', + 'libxdamage1', + 'libxkbcommon0', + 'libxml2', + 'libxslt1.1' + ], + }, +}; + +export async function installDeps() { + if (os.platform() !== 'linux') + return; + + const commands: string[] = []; + commands.push('apt-get update'); + const ubuntuVersion = await getUbuntuVersion(); + let deps: any = []; + if (ubuntuVersion === '18.04') { + deps = DEPENDENCIES['ubuntu18.04']; + } else if (ubuntuVersion === '20.04') { + deps = DEPENDENCIES['ubuntu20.04']; + } else { + console.warn('Cannot install dependencies for this linux distribution!'); // eslint-disable-line no-console + return; + } + console.log('Installing Ubuntu dependencies...'); // eslint-disable-line no-console + commands.push(['apt-get', 'install', '-y', '--no-install-recommends', + ...deps.chromium, + ...deps.firefox, + ...deps.webkit + ].join(' ')); + + // - `ffmpeg`: For video playback in Firefox + commands.push('apt-get install -y ffmpeg'); + // For headful execution + commands.push('apt-get install -y xvfb'); + const child = childProcess.spawn('sudo', ['--', 'sh', '-c', `${commands.join('; ')}`], { stdio: 'inherit' }); + await new Promise(f => child.on('exit', f)); +}