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",
|
"nothrow",
|
||||||
"Opencppcoverage",
|
"Opencppcoverage",
|
||||||
"OSSDK",
|
"OSSDK",
|
||||||
|
"setx",
|
||||||
"untildify",
|
"untildify",
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
"visualc",
|
"visualc",
|
||||||
|
|
|
@ -209,7 +209,6 @@ jobs:
|
||||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Articles
|
# Articles
|
||||||
|
|
||||||
[Setup-Cpp on Dev.to](https://dev.to/aminya/setup-cpp-3ia4)
|
[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 { setupPython } from "./python/python"
|
||||||
import mri from "mri"
|
import mri from "mri"
|
||||||
import untildify from "untildify"
|
import untildify from "untildify"
|
||||||
import { isCI } from "./utils/env/isci"
|
import { isGitHubCI } from "./utils/env/isci"
|
||||||
|
|
||||||
import semverValid from "semver/functions/valid"
|
import semverValid from "semver/functions/valid"
|
||||||
import { getVersion } from "./default_versions"
|
import { getVersion } from "./default_versions"
|
||||||
|
@ -79,7 +79,7 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
|
||||||
|
|
||||||
/** The main entry function */
|
/** The main entry function */
|
||||||
export async function main(args: string[]): Promise<number> {
|
export async function main(args: string[]): Promise<number> {
|
||||||
if (!isCI()) {
|
if (!isGitHubCI()) {
|
||||||
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
|
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ export async function main(args: string[]): Promise<number> {
|
||||||
|
|
||||||
core.info("setup_cpp finished")
|
core.info("setup_cpp finished")
|
||||||
|
|
||||||
if (!isCI()) {
|
if (!isGitHubCI()) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "win32": {
|
case "win32": {
|
||||||
core.info("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
|
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 { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||||
import hasha from "hasha"
|
import hasha from "hasha"
|
||||||
import { join } from "path"
|
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) {
|
export function setupPython(version: string, setupDir: string, arch: string) {
|
||||||
if (!isCI()) {
|
if (!isGitHubCI()) {
|
||||||
// TODO parse versoin
|
// TODO parse versoin
|
||||||
return setupPythonViaSystem("", setupDir, arch)
|
return setupPythonViaSystem("", setupDir, arch)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
export function isCI() {
|
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 * as core from "@actions/core"
|
||||||
import { isCI } from "../env/isci"
|
import { isGitHubCI } from "../env/isci"
|
||||||
|
|
||||||
export function error(err: string | Error) {
|
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) {
|
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,14 +2,31 @@ import { addPath as ghAddPath } from "@actions/core"
|
||||||
import { delimiter } from "path"
|
import { delimiter } from "path"
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import execa from "execa"
|
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 */
|
/** An add path function that works locally or inside GitHub Actions */
|
||||||
export function addPath(path: string) {
|
export function addPath(path: string) {
|
||||||
try {
|
try {
|
||||||
|
if (isGitHubCI()) {
|
||||||
ghAddPath(path)
|
ghAddPath(path)
|
||||||
|
} else {
|
||||||
|
addPathSystem(path)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
try {
|
try {
|
||||||
core.error(err as Error)
|
core.error(err as Error)
|
||||||
|
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.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPathSystem(path: string) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "win32": {
|
case "win32": {
|
||||||
execa.sync(`setx PATH=${path};%PATH%`)
|
execa.sync(`setx PATH=${path};%PATH%`)
|
||||||
|
@ -17,19 +34,15 @@ export function addPath(path: string) {
|
||||||
}
|
}
|
||||||
case "linux":
|
case "linux":
|
||||||
case "darwin": {
|
case "darwin": {
|
||||||
execa.commandSync(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
|
const profile_path = untildify("~/.profile")
|
||||||
execa.commandSync(`source ~/.profile`)
|
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
|
||||||
core.info(`${path} was added to ~/.profile`)
|
// spawnSync(`source "${profile_path}"`, { shell: true })
|
||||||
|
core.info(`${path} was added to "${profile_path}"`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
// fall through shell path modification
|
// fall through shell path modification
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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}`
|
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { addPath } from "../path/addPath"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
import { isCI } from "../env/isci"
|
import { isGitHubCI } from "../env/isci"
|
||||||
|
|
||||||
/** A type that describes a package */
|
/** A type that describes a package */
|
||||||
export type PackageInfo = {
|
export type PackageInfo = {
|
||||||
|
@ -52,7 +52,7 @@ export async function setupBin(
|
||||||
)
|
)
|
||||||
|
|
||||||
// Restore from cache (if found).
|
// Restore from cache (if found).
|
||||||
if (isCI()) {
|
if (isGitHubCI()) {
|
||||||
try {
|
try {
|
||||||
const dir = find(name, version)
|
const dir = find(name, version)
|
||||||
if (dir) {
|
if (dir) {
|
||||||
|
@ -86,7 +86,7 @@ export async function setupBin(
|
||||||
addPath(binDir)
|
addPath(binDir)
|
||||||
|
|
||||||
// check if inside Github Actions. If so, cache the installation
|
// 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)
|
await cacheDir(setupDir, name, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue