Merge pull request #121 from aminya/admina [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-08-26 22:20:26 -07:00 committed by GitHub
commit a349c5cf15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 730 additions and 782 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/actions_python.f90e48a4.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/actions_python.f90e48a4.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
["TS6133", "TS7010"] ["TS6133"]

View File

@ -1 +1 @@
["node_modules/setup-python/src/cache-distributions/poetry-cache.ts", "node_modules/time-delta/types/index.d.ts"] ["node_modules/setup-python/src/cache-distributions/poetry-cache.ts"]

View File

@ -55,6 +55,7 @@
"@actions/io": "^1.1.2", "@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d", "@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d",
"admina": "^0.1.1",
"ci-log": "workspace:1.0.0", "ci-log": "workspace:1.0.0",
"escape-path-with-spaces": "github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3", "escape-path-with-spaces": "github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3",
"exec-powershell": "workspace:1.0.0", "exec-powershell": "workspace:1.0.0",
@ -64,7 +65,6 @@
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1", "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"numerous": "1.0.3", "numerous": "1.0.3",
"patha": "^0.4.0", "patha": "^0.4.0",
"root-tools": "workspace:1.0.0",
"semver": "7.3.7", "semver": "7.3.7",
"setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d", "setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e", "time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
@ -75,9 +75,9 @@
}, },
"devDependencies": { "devDependencies": {
"@types/cross-spawn": "^6.0.2", "@types/cross-spawn": "^6.0.2",
"@types/jest": "^28.1.7", "@types/jest": "^28.1.8",
"@types/mri": "^1.1.1", "@types/mri": "^1.1.1",
"@types/node": "^18.7.9", "@types/node": "^18.7.13",
"@types/semver": "^7.3.12", "@types/semver": "^7.3.12",
"@types/which": "^2.0.1", "@types/which": "^2.0.1",
"caxa": "^2.1.0", "caxa": "^2.1.0",
@ -87,7 +87,7 @@
"eslint": "^8.22.0", "eslint": "^8.22.0",
"eslint-config-atomic": "^1.18.1", "eslint-config-atomic": "^1.18.1",
"gen-readme": "^1.6.0", "gen-readme": "^1.6.0",
"jest": "^28.1.3", "jest": "^29.0.0",
"loose-ts-check": "^1.2.0", "loose-ts-check": "^1.2.0",
"npm-check-updates": "^16.0.5", "npm-check-updates": "^16.0.5",
"npm-run-all2": "^6.0.2", "npm-run-all2": "^6.0.2",
@ -99,7 +99,7 @@
"terser-config-atomic": "^0.1.1", "terser-config-atomic": "^0.1.1",
"ts-jest": "^28.0.8", "ts-jest": "^28.0.8",
"ts-readme": "^1.1.3", "ts-readme": "^1.1.3",
"typescript": "^4.7.4" "typescript": "^4.8.2"
}, },
"engines": { "engines": {
"node": ">=12.x" "node": ">=12.x"

View File

@ -11,7 +11,7 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.9.0", "@actions/core": "^1.9.1",
"@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d" "@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d"
}, },
"keywords": [ "keywords": [

View File

@ -1,76 +0,0 @@
<h1 align="center">root-tools</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
</p>
> Tools for working with root and sudo such as executing command as root, detecting root, etc.
## Install
```sh
npm install --save root-tools
```
## Usage
<!-- INSERT GENERATED DOCS START -->
### `isSudo` (function)
Detect if sudo is available and the user has root privileges
**returns:** boolean
### `isRoot` (function)
Detect if the process has root privileges
**returns:** boolean
### `prependSudo` (function)
Prepend `sudo` to the command if sudo is available
**Parameters:**
- command (`string`)
**returns:** string
### `execRootSync` (function)
Execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
**Parameters:**
- program (`string`) - The program to spawn
- args (`string[]`) - The command arguments
- execOptions (`execa.SyncOptions`) - The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
**returns:** execa.ExecaSyncReturnValue<string>
### `execRoot` (function)
Asynchronously execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
**Parameters:**
- program (`string`) - The program to spawn
- args (`string[]`) - The command arguments
- execOptions (`execa.Options`) - The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
**returns:** execa.ExecaChildProcess<string>
<!-- INSERT GENERATED DOCS END -->
## 🤝 Contributing
You can sponsor my work here:
https://github.com/sponsors/aminya
Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).

View File

@ -1,41 +0,0 @@
{
"name": "root-tools",
"version": "1.0.0",
"description": "Tools for working with root and sudo such as executing command as root, detecting root, etc.",
"homepage": "https://github.com/aminya/setup-cpp",
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"scripts": {
"build": "tsc"
},
"dependencies": {
"execa": "^5.1.1",
"which": "^2.0.2"
},
"devDependencies": {
"@types/which": "^2.0.1"
},
"keywords": [
"sudo",
"root",
"is-root",
"is-sudo",
"exec-sudo",
"exec-root",
"isroot",
"issudo",
"exec",
"execa",
"spawn",
"system",
"unix",
"linux",
"github-actions",
"github",
"actions",
"gitlab",
"ci"
]
}

View File

@ -1,60 +0,0 @@
import which from "which"
import execa from "execa"
/** Detect if sudo is available and the user has root privileges */
export function isSudo(): boolean {
return (Boolean(process.env.CI) || isRoot()) && which.sync("sudo", { nothrow: true }) !== null
}
/** Detect if the process has root privileges */
export function isRoot(): boolean {
return process.getuid?.() === 0
}
/** Prepend `sudo` to the command if sudo is available */
export function prependSudo(command: string) {
if (isSudo()) {
return `sudo ${command}`
}
return command
}
/**
* Execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
*
* @param program The program to spawn
* @param args The command arguments
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
* @returns The execution result
*/
export function execRootSync(
program: string,
args: string[] = [],
execOptions: execa.SyncOptions = { stdio: "inherit", shell: true }
): execa.ExecaSyncReturnValue<string> {
if (isSudo()) {
return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
} else {
return execa.sync(program, args, execOptions)
}
}
/**
* Asynchronously execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
*
* @param program The program to spawn
* @param args The command arguments
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
* @returns A promise to the execution result
*/
export function execRoot(
program: string,
args: string[] = [],
execOptions: execa.Options = { stdio: "inherit", shell: true }
): execa.ExecaChildProcess<string> {
if (isSudo()) {
return execa.command(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
} else {
return execa(program, args, execOptions)
}
}

View File

@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}

View File

@ -11,7 +11,7 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"root-tools": "workspace:*", "admina": "0.1.1",
"untildify": "^4.0.0" "untildify": "^4.0.0"
}, },
"keywords": [ "keywords": [

View File

@ -1,6 +1,6 @@
import { join } from "path" import { join } from "path"
import untildify from "untildify" import untildify from "untildify"
import { isSudo } from "root-tools" import { isSudo } from "admina"
export function untildifyUser(path: string) { export function untildifyUser(path: string) {
if (isSudo() && typeof process.env.SUDO_USER === "string") { if (isSudo() && typeof process.env.SUDO_USER === "string") {

View File

@ -11,7 +11,7 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"root-tools": "workspace:*" "admina": "0.1.1"
}, },
"keywords": [ "keywords": [
"chown", "chown",

View File

@ -1,4 +1,4 @@
import { isSudo, execRootSync } from "root-tools" import { isSudo, execRootSync } from "admina"
/** /**
* Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows * Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf" import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupBazel(version: string, _setupDir: string, _arch: string) { export async function setupBazel(version: string, _setupDir: string, _arch: string) {

View File

@ -1,7 +1,7 @@
import { dirname } from "patha" import { dirname } from "patha"
import which from "which" import which from "which"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack" import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
let binDir: string | undefined let binDir: string | undefined

View File

@ -7,7 +7,7 @@ import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf" import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
import { ubuntuVersion } from "../utils/env/ubuntu_version" import { ubuntuVersion } from "../utils/env/ubuntu_version"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
import { info } from "@actions/core" import { info } from "@actions/core"
import ciDetect from "@npmcli/ci-detect" import ciDetect from "@npmcli/ci-detect"
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv" import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
import { info, warning } from "ci-log" import { info, warning } from "ci-log"
// let didUpdate: boolean = false // let didUpdate: boolean = false

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execRootSync } from "root-tools" import { execRootSync } from "admina"
import { info } from "ci-log" import { info } from "ci-log"
let didUpdate: boolean = false let didUpdate: boolean = false

View File

@ -16,7 +16,7 @@
"inlineSources": true, "inlineSources": true,
"preserveSymlinks": true, "preserveSymlinks": true,
"removeComments": false, "removeComments": false,
"skipLibCheck": false, "skipLibCheck": true,
"lib": ["ES2020", "dom"], "lib": ["ES2020", "dom"],
"target": "ES2020", "target": "ES2020",
"allowJs": true, "allowJs": true,