Skip to content

Commit

Permalink
fix: install package with sudo for non-root users by default (#546)
Browse files Browse the repository at this point in the history
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 #544
  • Loading branch information
ueokande committed May 15, 2024
1 parent 18cfc76 commit 5325b7d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: 'build-test'
on:
pull_request:
push:
branches-ignore:
- master
Expand Down Expand Up @@ -50,14 +49,14 @@ jobs:
run: |
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
test-container:
test-install-dependencies:
needs: [build]
strategy:
fail-fast: false
matrix:
container:
- ""
- fedora
- debian
- opensuse/leap
runs-on: ubuntu-latest
container: ${{ matrix.container }}
Expand All @@ -68,16 +67,17 @@ jobs:
- name: Install action dependencies
run: apt-get update && apt-get install -y unzip
if: ${{ matrix.container == 'debian' || matrix.container == 'ubuntu' || matrix.container == 'linuxmintd/mint21-amd64' }}

- name: Install action dependencies
run: yum install --assumeyes unzip
if: ${{ matrix.container == 'redhat/ubi9' || matrix.container == 'oraclelinux:9' || matrix.container == 'fedora' }}
- name: Install action dependencies
run: zypper install --no-confirm unzip
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}

# Override GITHUB_PATH by the current PATH to prevent the issue discussed in https://github.com/actions/runner/issues/3210
- run: echo "$PATH" >>"$GITHUB_PATH"
if: ${{ matrix.container == 'opensuse/leap' || matrix.container == 'registry.suse.com/bci/bci-base:15.5' }}

- name: Install Google Chrome
uses: ./
with:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
description: |-
Install dependent packages for Google Chrome/Chromium (Linux only).
default: false
no-sudo:
description: |-
Do not use sudo to install Google Chrome/Chromium (Linux only).
default: false
outputs:
chrome-version:
description: 'The installed Google Chrome/Chromium version. Useful when given a latest version.'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@actions/http-client": "^2.2.1",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"actions-swing": "^0.0.5"
"actions-swing": "^0.0.6"
},
"devDependencies": {
"@biomejs/biome": "^1.7.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const SUSE_BASED_DEPENDENT_PACKAGES = [
"mozilla-nss",
];

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

await pkg.install(packages);
await pkg.install(packages, { sudo });
};

export { installDependencies };
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ async function run(): Promise<void> {
const platform = getPlatform();
const flagInstallDependencies =
core.getInput("install-dependencies") === "true";
const noSudo = core.getInput("no-sudo") === "true";

if (flagInstallDependencies) {
core.info("Installing dependencies");
await installDependencies(platform);
await installDependencies(platform, { noSudo });
}

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

0 comments on commit 5325b7d

Please sign in to comment.