Skip to content

Commit 5325b7d

Browse files
committed
fix: install package with sudo for non-root users by default (browser-actions#546)
This change is to install dependencies with `sudo` for non-root users by default. The action identify the current UID and enable `sudo` if the UID is not 0. Users can disable using `sudo` by setting the `no-sudo: true` in the action input. ```yaml steps: - uses: browser-actions/setup-chrome@v1 with: chrome-version: 120 install-dependencies: true no-sudo: true ``` Close browser-actions#544
1 parent 18cfc76 commit 5325b7d

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: 'build-test'
22
on:
3-
pull_request:
43
push:
54
branches-ignore:
65
- master
@@ -50,14 +49,14 @@ jobs:
5049
run: |
5150
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
5251
53-
test-container:
52+
test-install-dependencies:
5453
needs: [build]
5554
strategy:
5655
fail-fast: false
5756
matrix:
5857
container:
58+
- ""
5959
- fedora
60-
- debian
6160
- opensuse/leap
6261
runs-on: ubuntu-latest
6362
container: ${{ matrix.container }}
@@ -68,16 +67,17 @@ jobs:
6867
- name: Install action dependencies
6968
run: apt-get update && apt-get install -y unzip
7069
if: ${{ matrix.container == 'debian' || matrix.container == 'ubuntu' || matrix.container == 'linuxmintd/mint21-amd64' }}
71-
7270
- name: Install action dependencies
7371
run: yum install --assumeyes unzip
7472
if: ${{ matrix.container == 'redhat/ubi9' || matrix.container == 'oraclelinux:9' || matrix.container == 'fedora' }}
7573
- name: Install action dependencies
7674
run: zypper install --no-confirm unzip
7775
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}
76+
7877
# Override GITHUB_PATH by the current PATH to prevent the issue discussed in https://github.com/actions/runner/issues/3210
7978
- run: echo "$PATH" >>"$GITHUB_PATH"
8079
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}
80+
8181
- name: Install Google Chrome
8282
uses: ./
8383
with:

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: |-
1212
Install dependent packages for Google Chrome/Chromium (Linux only).
1313
default: false
14+
no-sudo:
15+
description: |-
16+
Do not use sudo to install Google Chrome/Chromium (Linux only).
17+
default: false
1418
outputs:
1519
chrome-version:
1620
description: 'The installed Google Chrome/Chromium version. Useful when given a latest version.'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@actions/http-client": "^2.2.1",
1414
"@actions/io": "^1.1.3",
1515
"@actions/tool-cache": "^2.0.1",
16-
"actions-swing": "^0.0.5"
16+
"actions-swing": "^0.0.6"
1717
},
1818
"devDependencies": {
1919
"@biomejs/biome": "^1.7.2",

pnpm-lock.yaml

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

src/dependencies.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ const SUSE_BASED_DEPENDENT_PACKAGES = [
5252
"mozilla-nss",
5353
];
5454

55-
const installDependencies = async (platform: Platform): Promise<void> => {
55+
const installDependencies = async (
56+
platform: Platform,
57+
{ noSudo }: { noSudo: boolean },
58+
) => {
5659
if (platform.os !== "linux") {
5760
core.warning(
5861
`install-dependencies is only supported on Linux, but current platform is ${platform.os}`,
@@ -79,8 +82,9 @@ const installDependencies = async (platform: Platform): Promise<void> => {
7982
}
8083
throw new Error(`Unsupported OS: ${osReleaseId}`);
8184
})();
85+
const sudo = !noSudo && process.getuid?.() !== 0;
8286

83-
await pkg.install(packages);
87+
await pkg.install(packages, { sudo });
8488
};
8589

8690
export { installDependencies };

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ async function run(): Promise<void> {
5050
const platform = getPlatform();
5151
const flagInstallDependencies =
5252
core.getInput("install-dependencies") === "true";
53+
const noSudo = core.getInput("no-sudo") === "true";
5354

5455
if (flagInstallDependencies) {
5556
core.info("Installing dependencies");
56-
await installDependencies(platform);
57+
await installDependencies(platform, { noSudo });
5758
}
5859

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

0 commit comments

Comments
 (0)