Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect if sudo should be used #138

Merged
merged 5 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/manual-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ jobs:
- uses: ./
with:
limit-access-to-actor: ${{ matrix.limit-access-to-actor }}
sudo: false
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: 'auto'
install-dependencies:
description: 'Whether or not to install dependencies for tmate on linux (openssh-client, xz-utils)'
required: false
Expand Down
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12470,6 +12470,15 @@ var external_child_process_ = __nccwpck_require__(2081);




/**
* @returns {boolean}
*/
const useSudoPrefix = () => {
const input = core.getInput("sudo");
return input === "auto" ? external_os_default().userInfo().uid !== 0 : input === "true";
}

/**
* @param {string} cmd
* @returns {Promise<string>}
Expand Down Expand Up @@ -12570,7 +12579,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 = useSudoPrefix() ? "sudo " : "";
const distro = await getLinuxDistro();
core.debug("linux distro: [" + distro + "]");
if (distro === "alpine") {
Expand Down
9 changes: 9 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import { spawn } from 'child_process'
import * as core from "@actions/core"
import fs from 'fs'
import os from 'os'

/**
* @returns {boolean}
*/
export const useSudoPrefix = () => {
const input = core.getInput("sudo");
return input === "auto" ? os.userInfo().uid !== 0 : input === "true";
}

/**
* @param {string} cmd
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as github from "@actions/github"
import * as tc from "@actions/tool-cache"
import { Octokit } from "@octokit/rest"

import { execShellCommand, getValidatedInput, getLinuxDistro } from "./helpers"
import { execShellCommand, getValidatedInput, getLinuxDistro, useSudoPrefix } from "./helpers"

const TMATE_LINUX_VERSION = "2.4.0"

Expand All @@ -34,7 +34,7 @@ export async function run() {
} else if (process.platform === "win32") {
await execShellCommand('pacman -Sy --noconfirm tmate');
} else {
const optionalSudoPrefix = core.getInput("sudo") === "true" ? "sudo " : "";
const optionalSudoPrefix = useSudoPrefix() ? "sudo " : "";
const distro = await getLinuxDistro();
core.debug("linux distro: [" + distro + "]");
if (distro === "alpine") {
Expand Down