2023-05-24 11:43:45 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright 2023 Google LLC.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview Installs a browser defined in `.browser` for Chromium-BiDi using
|
|
|
|
* `@puppeteer/browsers` to the directory provided as the first argument
|
|
|
|
* (default: cwd). The executable path is written to the `executablePath` output
|
|
|
|
* param for GitHub actions.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* - `node install-browser.mjs`
|
|
|
|
* - `node install-browser.mjs /tmp/cache`
|
|
|
|
*/
|
2023-09-20 14:13:32 +00:00
|
|
|
import {readFile} from 'node:fs/promises';
|
|
|
|
import {createRequire} from 'node:module';
|
2023-05-24 11:43:45 +00:00
|
|
|
|
|
|
|
import actions from '@actions/core';
|
2023-10-12 13:04:29 +00:00
|
|
|
|
2023-09-20 14:13:32 +00:00
|
|
|
import {computeExecutablePath, install} from '@puppeteer/browsers';
|
|
|
|
|
|
|
|
const require = createRequire(import.meta.url);
|
2023-05-24 11:43:45 +00:00
|
|
|
|
|
|
|
try {
|
2023-09-20 14:13:32 +00:00
|
|
|
const browserSpec = await readFile(
|
|
|
|
require.resolve('chromium-bidi/.browser', {
|
|
|
|
paths: [require.resolve('puppeteer-core')],
|
|
|
|
}),
|
|
|
|
'utf-8'
|
|
|
|
);
|
2023-05-24 11:43:45 +00:00
|
|
|
const cacheDir = process.argv[2] || process.cwd();
|
|
|
|
// See .browser for the format.
|
|
|
|
const browser = browserSpec.split('@')[0];
|
|
|
|
const buildId = browserSpec.split('@')[1];
|
|
|
|
await install({
|
|
|
|
browser,
|
|
|
|
buildId,
|
|
|
|
cacheDir,
|
|
|
|
});
|
|
|
|
const executablePath = computeExecutablePath({
|
|
|
|
cacheDir,
|
|
|
|
browser,
|
|
|
|
buildId,
|
|
|
|
});
|
2023-05-31 11:13:34 +00:00
|
|
|
if (process.argv.indexOf('--shell') === -1) {
|
|
|
|
actions.setOutput('executablePath', executablePath);
|
|
|
|
}
|
2023-05-24 11:43:45 +00:00
|
|
|
console.log(executablePath);
|
|
|
|
} catch (err) {
|
|
|
|
actions.setFailed(`Failed to download the browser: ${err.message}`);
|
|
|
|
}
|