Skip to content

Commit

Permalink
Install package with sudo for non-root users by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ueokande committed May 15, 2024
1 parent 18cfc76 commit 2d88a76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
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
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 2d88a76

Please sign in to comment.