Skip to content

Commit

Permalink
detect if sudo should be used
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Oct 9, 2022
1 parent 57508dd commit 080fbff
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 37 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
sudo:
description: 'If apt should be executed with sudo or without'
required: false
default: 'true'
default: 'detect'
install-dependencies:
description: 'Whether or not to install dependencies for tmate on linux (openssh-client, xz-utils)'
required: false
Expand Down
23 changes: 22 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12470,6 +12470,27 @@ var external_child_process_ = __nccwpck_require__(2081);




/**
* @returns {string}
*/
const getOptionalSudoPrefix = () => {
switch(core.getInput("sudo")){
case "true":{
return "sudo ";
}
case "detect":{
return external_os_default().userInfo().uid == 0 ? "" : "sudo ";
}
case "false":{
return "";
}
default:{
throw new Error(`Unsupported 'sudo' value: ${core.getInput("sudo")}`);
}
}
}

/**
* @param {string} cmd
* @returns {Promise<string>}
Expand Down Expand Up @@ -12570,7 +12591,7 @@ async function run() {
} else if (process.platform === "win32") {
await execShellCommand('pacman -Sy --noconfirm tmate');
} else {
const optionalSudoPrefix = core.getInput("sudo") === "true" ? "sudo " : "";
const optionalSudoPrefix = getOptionalSudoPrefix();
const distro = await getLinuxDistro();
core.debug("linux distro: [" + distro + "]");
if (distro === "alpine") {
Expand Down
Loading

0 comments on commit 080fbff

Please sign in to comment.