diff --git a/action.yml b/action.yml index ddefdb6..a5883f4 100644 --- a/action.yml +++ b/action.yml @@ -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.' diff --git a/src/dependencies.ts b/src/dependencies.ts index 9f5f71b..9508b4f 100644 --- a/src/dependencies.ts +++ b/src/dependencies.ts @@ -52,7 +52,10 @@ const SUSE_BASED_DEPENDENT_PACKAGES = [ "mozilla-nss", ]; -const installDependencies = async (platform: Platform): Promise => { +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}`, @@ -79,8 +82,9 @@ const installDependencies = async (platform: Platform): Promise => { } throw new Error(`Unsupported OS: ${osReleaseId}`); })(); + const sudo = !noSudo && process.getuid?.() !== 0; - await pkg.install(packages); + await pkg.install(packages, { sudo }); }; export { installDependencies }; diff --git a/src/index.ts b/src/index.ts index d9f86de..c77fe5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,10 +50,11 @@ async function run(): Promise { 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}`);