Skip to content

Commit 808262a

Browse files
authored
feat: Add install-dependencies parameter (#521)
A new parameter `install-dependencies` is added to the action. The action will install the dependencies if the parameter is set to `true` on the Linux. It would be useful when you use the action on the self-hosted runner and want to install the dependencies automatically. This feature works only on the Linux runner, otherwise, it will be ignored.
1 parent 67cafd0 commit 808262a

8 files changed

Lines changed: 170 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,40 @@ jobs:
4949
- if: runner.os == 'Windows'
5050
run: |
5151
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
52+
53+
test-container:
54+
needs: [build]
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
container:
59+
- fedora
60+
- debian
61+
- opensuse/leap
62+
runs-on: ubuntu-latest
63+
container: ${{ matrix.container }}
64+
steps:
65+
- uses: actions/download-artifact@v3
66+
with:
67+
name: dist
68+
- name: Install action dependencies
69+
run: apt-get update && apt-get install -y unzip
70+
if: ${{ matrix.container == 'debian' || matrix.container == 'ubuntu' || matrix.container == 'linuxmintd/mint21-amd64' }}
71+
72+
- name: Install action dependencies
73+
run: yum install --assumeyes unzip
74+
if: ${{ matrix.container == 'redhat/ubi9' || matrix.container == 'oraclelinux:9' || matrix.container == 'fedora' }}
75+
- name: Install action dependencies
76+
run: zypper install --no-confirm unzip
77+
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}
78+
# Override GITHUB_PATH by the current PATH to prevent the issue discussed in https://github.com/actions/runner/issues/3210
79+
- run: echo "$PATH" >>"$GITHUB_PATH"
80+
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}
81+
- name: Install Google Chrome
82+
uses: ./
83+
with:
84+
chrome-version: 120
85+
install-dependencies: true
86+
id: setup-chrome
87+
- run: |
88+
"${{ steps.setup-chrome.outputs.chrome-path }}" --version

.github/workflows/manual-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
- ubuntu
1111
- windows
1212
- macos
13+
container:
14+
description: 'Container image to run test on'
15+
required: false
16+
type: string
1317
chrome-version:
1418
description: 'Chrome version to install'
1519
required: false
@@ -38,6 +42,7 @@ jobs:
3842
test:
3943
needs: [build]
4044
runs-on: ${{ inputs.os }}-latest
45+
container: ${{ inputs.container }}
4146
steps:
4247
- uses: actions/download-artifact@v3
4348
with:

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ steps:
3131
chrome-version: 120
3232
```
3333

34+
If you use the self-hosted runner, your runner may not have the required dependencies on the system.
35+
You can install the dependencies by using the `install-dependencies` parameter.
36+
It installs the required dependencies for the Google Chrome/Chromium to run automatically.
37+
38+
```yaml
39+
steps:
40+
- uses: browser-actions/setup-chrome@v1
41+
with:
42+
chrome-version: 120
43+
install-dependencies: true
44+
```
45+
3446
### Supported version formats
3547

3648
The action supports the following version formats:
@@ -63,6 +75,8 @@ steps:
6375

6476
- `chrome-version`: *(Optional)* The Google Chrome/Chromium version to be installed.
6577
Default: `latest`
78+
- `install-dependencies`: *(Optional)* Install the required dependencies for the Google Chrome/Chromium to run.
79+
Default: `false`
6680

6781
### Outputs
6882

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
The Google Chrome/Chromium version to install and use.
88
default: latest
99
required: false
10+
install-dependencies:
11+
description: |-
12+
Install dependent packages for Google Chrome/Chromium (Linux only).
13+
default: false
1014
outputs:
1115
chrome-version:
1216
description: 'The installed Google Chrome/Chromium version. Useful when given a latest version.'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"@actions/exec": "^1.1.1",
1313
"@actions/http-client": "^2.2.0",
1414
"@actions/io": "^1.1.3",
15-
"@actions/tool-cache": "^2.0.1"
15+
"@actions/tool-cache": "^2.0.1",
16+
"actions-swing": "^0.0.5"
1617
},
1718
"devDependencies": {
1819
"@types/jest": "^29.5.10",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dependencies.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { pkg, runtime } from "actions-swing";
2+
import type { Platform } from "./platform";
3+
import * as core from "@actions/core";
4+
5+
const DEBIAN_BASED_DEPENDENT_PACKAGES = [
6+
"libglib2.0-0",
7+
"libgconf-2-4",
8+
"libatk1.0-0",
9+
"libatk-bridge2.0-0",
10+
"libgdk-pixbuf2.0-0",
11+
"libgtk-3-0",
12+
"libgbm-dev",
13+
"libnss3-dev",
14+
"libxss-dev",
15+
"libasound2",
16+
"xvfb",
17+
"fonts-liberation",
18+
"libu2f-udev",
19+
"xdg-utils",
20+
];
21+
22+
const FEDORA_BASED_DEPENDENT_PACKAGES = [
23+
"alsa-lib",
24+
"atk",
25+
"at-spi2-atk",
26+
"cups-libs",
27+
"libdrm",
28+
"libXcomposite",
29+
"libXdamage",
30+
"libxkbcommon",
31+
"libXrandr",
32+
"mesa-libgbm",
33+
"nss",
34+
"pango",
35+
];
36+
37+
const SUSE_BASED_DEPENDENT_PACKAGES = [
38+
"libasound2",
39+
"libatk-1_0-0",
40+
"libatk-bridge-2_0-0",
41+
"libcups2",
42+
"libdbus-1-3",
43+
"libdrm2",
44+
"libgbm1",
45+
"libgobject-2_0-0",
46+
"libpango-1_0-0",
47+
"libXcomposite1",
48+
"libXdamage1",
49+
"libXfixes3",
50+
"libxkbcommon0",
51+
"libXrandr2",
52+
"mozilla-nss",
53+
];
54+
55+
const installDependencies = async (platform: Platform): Promise<void> => {
56+
if (platform.os !== "linux") {
57+
core.warning(
58+
`install-dependencies is only supported on Linux, but current platform is ${platform.os}`,
59+
);
60+
return;
61+
}
62+
63+
const packages = await (async () => {
64+
const osReleaseId = await runtime.getOsReleaseId();
65+
switch (osReleaseId) {
66+
case "rhel":
67+
case "centos":
68+
case "ol":
69+
case "fedora":
70+
return FEDORA_BASED_DEPENDENT_PACKAGES;
71+
case "debian":
72+
case "ubuntu":
73+
case "linuxmint":
74+
return DEBIAN_BASED_DEPENDENT_PACKAGES;
75+
case "opensuse":
76+
case "opensuse-leap":
77+
case "sles":
78+
return SUSE_BASED_DEPENDENT_PACKAGES;
79+
}
80+
throw new Error(`Unsupported OS: ${osReleaseId}`);
81+
})();
82+
83+
await pkg.install(packages);
84+
};
85+
86+
export { installDependencies };

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as exec from "@actions/exec";
33
import * as installer from "./installer";
44
import { getPlatform, Platform, OS } from "./platform";
55
import path from "path";
6+
import { installDependencies } from "./dependencies";
67

78
const hasErrorMessage = (e: unknown): e is { message: string | Error } => {
89
return typeof e === "object" && e !== null && "message" in e;
@@ -47,6 +48,13 @@ async function run(): Promise<void> {
4748
try {
4849
const version = core.getInput("chrome-version") || "latest";
4950
const platform = getPlatform();
51+
const flagInstallDependencies =
52+
core.getInput("install-dependencies") === "true";
53+
54+
if (flagInstallDependencies) {
55+
core.info(`Installing dependencies`);
56+
await installDependencies(platform);
57+
}
5058

5159
core.info(`Setup chromium ${version}`);
5260

0 commit comments

Comments
 (0)