mirror of https://github.com/aminya/setup-cpp
Merge pull request #11 from aminya/gitlab [skip ci]
This commit is contained in:
commit
51475bb65b
|
@ -20,6 +20,7 @@
|
|||
"nothrow",
|
||||
"Opencppcoverage",
|
||||
"OSSDK",
|
||||
"setx",
|
||||
"untildify",
|
||||
"vcpkg",
|
||||
"visualc",
|
||||
|
|
|
@ -209,7 +209,6 @@ jobs:
|
|||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
```
|
||||
|
||||
|
||||
# Articles
|
||||
|
||||
[Setup-Cpp on Dev.to](https://dev.to/aminya/setup-cpp-3ia4)
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,7 @@ import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
|
|||
import { setupPython } from "./python/python"
|
||||
import mri from "mri"
|
||||
import untildify from "untildify"
|
||||
import { isCI } from "./utils/env/isci"
|
||||
import { isGitHubCI } from "./utils/env/isci"
|
||||
|
||||
import semverValid from "semver/functions/valid"
|
||||
import { getVersion } from "./default_versions"
|
||||
|
@ -79,7 +79,7 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
|
|||
|
||||
/** The main entry function */
|
||||
export async function main(args: string[]): Promise<number> {
|
||||
if (!isCI()) {
|
||||
if (!isGitHubCI()) {
|
||||
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
|
||||
core.info("setup_cpp finished")
|
||||
|
||||
if (!isCI()) {
|
||||
if (!isGitHubCI()) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
core.info("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
|
||||
|
|
|
@ -5,10 +5,10 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import hasha from "hasha"
|
||||
import { join } from "path"
|
||||
import { isCI } from "../utils/env/isci"
|
||||
import { isGitHubCI } from "../utils/env/isci"
|
||||
|
||||
export function setupPython(version: string, setupDir: string, arch: string) {
|
||||
if (!isCI()) {
|
||||
if (!isGitHubCI()) {
|
||||
// TODO parse versoin
|
||||
return setupPythonViaSystem("", setupDir, arch)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
export function isCI() {
|
||||
return !(process.env.CI === undefined || process.env.CI === "" || process.env.CI === "false")
|
||||
return process.env.CI === "true"
|
||||
}
|
||||
|
||||
export function isGitHubCI() {
|
||||
return isCI() && process.env.GITHUB_ACTIONS == "true"
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import * as core from "@actions/core"
|
||||
import { isCI } from "../env/isci"
|
||||
import { isGitHubCI } from "../env/isci"
|
||||
|
||||
export function error(err: string | Error) {
|
||||
return isCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`)
|
||||
return isGitHubCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`)
|
||||
}
|
||||
|
||||
export function success(msg: string) {
|
||||
return isCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
|
||||
return isGitHubCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
|
||||
}
|
||||
|
|
|
@ -2,34 +2,47 @@ import { addPath as ghAddPath } from "@actions/core"
|
|||
import { delimiter } from "path"
|
||||
import * as core from "@actions/core"
|
||||
import execa from "execa"
|
||||
import { isGitHubCI } from "../env/isci"
|
||||
import untildify from "untildify"
|
||||
import { appendFileSync } from "fs"
|
||||
// import { spawnSync } from "child_process"
|
||||
|
||||
/** An add path function that works locally or inside GitHub Actions */
|
||||
export function addPath(path: string) {
|
||||
try {
|
||||
ghAddPath(path)
|
||||
if (isGitHubCI()) {
|
||||
ghAddPath(path)
|
||||
} else {
|
||||
addPathSystem(path)
|
||||
}
|
||||
} catch (err) {
|
||||
try {
|
||||
core.error(err as Error)
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
execa.sync(`setx PATH=${path};%PATH%`)
|
||||
return
|
||||
}
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
execa.commandSync(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
|
||||
execa.commandSync(`source ~/.profile`)
|
||||
core.info(`${path} was added to ~/.profile`)
|
||||
return
|
||||
}
|
||||
default: {
|
||||
// fall through shell path modification
|
||||
}
|
||||
}
|
||||
return addPathSystem(path)
|
||||
} catch (err2) {
|
||||
core.error(err2 as Error)
|
||||
}
|
||||
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`)
|
||||
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
|
||||
}
|
||||
}
|
||||
|
||||
function addPathSystem(path: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
execa.sync(`setx PATH=${path};%PATH%`)
|
||||
return
|
||||
}
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
const profile_path = untildify("~/.profile")
|
||||
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
|
||||
// spawnSync(`source "${profile_path}"`, { shell: true })
|
||||
core.info(`${path} was added to "${profile_path}"`)
|
||||
return
|
||||
}
|
||||
default: {
|
||||
// fall through shell path modification
|
||||
}
|
||||
}
|
||||
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { addPath } from "../path/addPath"
|
|||
import { join } from "path"
|
||||
import { existsSync } from "fs"
|
||||
import { tmpdir } from "os"
|
||||
import { isCI } from "../env/isci"
|
||||
import { isGitHubCI } from "../env/isci"
|
||||
|
||||
/** A type that describes a package */
|
||||
export type PackageInfo = {
|
||||
|
@ -52,7 +52,7 @@ export async function setupBin(
|
|||
)
|
||||
|
||||
// Restore from cache (if found).
|
||||
if (isCI()) {
|
||||
if (isGitHubCI()) {
|
||||
try {
|
||||
const dir = find(name, version)
|
||||
if (dir) {
|
||||
|
@ -86,7 +86,7 @@ export async function setupBin(
|
|||
addPath(binDir)
|
||||
|
||||
// check if inside Github Actions. If so, cache the installation
|
||||
if (isCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
|
||||
if (isGitHubCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
|
||||
await cacheDir(setupDir, name, version)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue