Skip to content

Commit c4578f1

Browse files
authored
chore: organize per-browser dependencies (#5787)
1 parent a185da9 commit c4578f1

13 files changed

+602
-134
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
- uses: actions/setup-node@v1
3030
with:
3131
node-version: 10
32-
- uses: microsoft/playwright-github-action@v1
3332
- run: npm ci
3433
- run: npm run build
34+
- run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
3535
- run: mkdir -p coredumps
3636
# Set core dump file name pattern
3737
- run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
@@ -64,9 +64,9 @@ jobs:
6464
- uses: actions/setup-node@v1
6565
with:
6666
node-version: 10
67-
- uses: microsoft/playwright-github-action@v1
6867
- run: npm ci
6968
- run: npm run build
69+
- run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
7070
- run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json --shard=${{ matrix.shard }}/2
7171
env:
7272
BROWSER: ${{ matrix.browser }}
@@ -94,9 +94,9 @@ jobs:
9494
- uses: actions/setup-node@v1
9595
with:
9696
node-version: 10
97-
- uses: microsoft/playwright-github-action@v1
9897
- run: npm ci
9998
- run: npm run build
99+
- run: node lib/cli/cli install-deps
100100
- run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
101101
shell: bash
102102
env:
@@ -125,9 +125,9 @@ jobs:
125125
- uses: actions/setup-node@v1
126126
with:
127127
node-version: ${{ matrix.node_version }}
128-
- uses: microsoft/playwright-github-action@v1
129128
- run: npm ci
130129
- run: npm run build
130+
- run: node lib/cli/cli install-deps
131131
- run: bash packages/installation-tests/installation-tests.sh
132132

133133
headful_linux:
@@ -142,9 +142,9 @@ jobs:
142142
- uses: actions/setup-node@v1
143143
with:
144144
node-version: 10
145-
- uses: microsoft/playwright-github-action@v1
146145
- run: npm ci
147146
- run: npm run build
147+
- run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
148148
- run: mkdir -p coredumps
149149
# Set core dump file name pattern
150150
- run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
@@ -177,9 +177,9 @@ jobs:
177177
- uses: actions/setup-node@v1
178178
with:
179179
node-version: 10
180-
- uses: microsoft/playwright-github-action@v1
181180
- run: npm ci
182181
- run: npm run build
182+
- run: node lib/cli/cli install-deps chromium
183183
- run: mkdir -p coredumps
184184
# Set core dump file name pattern
185185
- run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
@@ -211,9 +211,9 @@ jobs:
211211
- uses: actions/setup-node@v1
212212
with:
213213
node-version: 10
214-
- uses: microsoft/playwright-github-action@v1
215214
- run: npm ci
216215
- run: npm run build
216+
- run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
217217
- run: mkdir -p coredumps
218218
# Set core dump file name pattern
219219
- run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
@@ -240,9 +240,9 @@ jobs:
240240
- uses: actions/setup-node@v1
241241
with:
242242
node-version: 14
243-
- uses: microsoft/playwright-github-action@v1
244243
- run: npm ci
245244
- run: npm run build
245+
- run: node lib/cli/cli install-deps
246246
- name: Create Android Emulator
247247
run: utils/avd_recreate.sh
248248
- name: Start Android Emulator
@@ -269,11 +269,11 @@ jobs:
269269
- uses: actions/setup-node@v1
270270
with:
271271
node-version: 10
272-
- uses: microsoft/playwright-github-action@v1
273272
- name: Install Chrome Stable
274273
run: sudo apt install google-chrome-stable
275274
- run: npm ci
276275
- run: npm run build
276+
- run: node lib/cli/cli install-deps chromium
277277
- run: mkdir -p coredumps
278278
# Set core dump file name pattern
279279
- run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'

src/cli/cli.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { Page } from '../client/page';
3131
import { BrowserType } from '../client/browserType';
3232
import { BrowserContextOptions, LaunchOptions } from '../client/types';
3333
import { spawn } from 'child_process';
34+
import { installDeps } from '../install/installDeps';
3435

3536
program
3637
.version('Version ' + require('../../package.json').version)
@@ -82,20 +83,34 @@ program
8283
program
8384
.command('install [browserType...]')
8485
.description('ensure browsers necessary for this version of Playwright are installed')
85-
.action(function(browserType) {
86-
const allBrowsers = new Set(['chromium', 'firefox', 'webkit']);
87-
for (const type of browserType) {
88-
if (!allBrowsers.has(type)) {
89-
console.log(`Invalid browser name: '${type}'. Expecting 'chromium', 'firefox' or 'webkit'.`);
90-
process.exit(1);
86+
.action(async function(browserType) {
87+
try {
88+
const allBrowsers = new Set(['chromium', 'firefox', 'webkit']);
89+
for (const type of browserType) {
90+
if (!allBrowsers.has(type)) {
91+
console.log(`Invalid browser name: '${type}'. Expecting 'chromium', 'firefox' or 'webkit'.`);
92+
process.exit(1);
93+
}
9194
}
95+
if (browserType.length && browserType.includes('chromium'))
96+
browserType = browserType.concat('ffmpeg');
97+
await installBrowsers(browserType.length ? browserType : undefined);
98+
} catch (e) {
99+
console.log(`Failed to install browsers\n${e}`);
100+
process.exit(1);
92101
}
93-
if (browserType.length && browserType.includes('chromium'))
94-
browserType = browserType.concat('ffmpeg');
95-
installBrowsers(browserType.length ? browserType : undefined).catch((e: any) => {
102+
});
103+
104+
program
105+
.command('install-deps [browserType...]')
106+
.description('install dependencies necessary to run browser')
107+
.action(async function(browserType) {
108+
try {
109+
await installDeps(browserType);
110+
} catch (e) {
96111
console.log(`Failed to install browsers\n${e}`);
97112
process.exit(1);
98-
});
113+
}
99114
});
100115

101116
const browsers = [

src/install/installDeps.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import childProcess from 'child_process';
18+
import os from 'os';
19+
import { getUbuntuVersion } from '../utils/ubuntuVersion';
20+
21+
const { deps } = require('../nativeDeps');
22+
23+
export async function installDeps(browserTypes: string[]) {
24+
if (os.platform() !== 'linux')
25+
return;
26+
if (!browserTypes.length)
27+
browserTypes = ['chromium', 'firefox', 'webkit'];
28+
browserTypes.push('tools');
29+
30+
const ubuntuVersion = await getUbuntuVersion();
31+
if (ubuntuVersion !== '18.04' && ubuntuVersion !== '20.04') {
32+
console.warn('Cannot install dependencies for this linux distribution!'); // eslint-disable-line no-console
33+
return;
34+
}
35+
36+
const libraries: string[] = [];
37+
for (const browserType of browserTypes) {
38+
if (ubuntuVersion === '18.04')
39+
libraries.push(...deps['bionic'][browserType]);
40+
else if (ubuntuVersion === '20.04')
41+
libraries.push(...deps['focal'][browserType]);
42+
}
43+
const uniqueLibraries = Array.from(new Set(libraries));
44+
console.log('Installing Ubuntu dependencies...'); // eslint-disable-line no-console
45+
const commands: string[] = [];
46+
commands.push('apt-get update');
47+
commands.push(['apt-get', 'install', '-y', '--no-install-recommends',
48+
...uniqueLibraries,
49+
].join(' '));
50+
const child = childProcess.spawn('sudo', ['--', 'sh', '-c', `${commands.join('; ')}`], { stdio: 'inherit' });
51+
await new Promise(f => child.on('exit', f));
52+
}

0 commit comments

Comments
 (0)