Skip to content

Commit 51475bb

Browse files
authored
Merge pull request #11 from aminya/gitlab [skip ci]
2 parents 54c51d7 + fe9414c commit 51475bb

10 files changed

Lines changed: 50 additions & 33 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"nothrow",
2121
"Opencppcoverage",
2222
"OSSDK",
23+
"setx",
2324
"untildify",
2425
"vcpkg",
2526
"visualc",

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ jobs:
209209
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
210210
```
211211
212-
213212
# Articles
214213
215214
[Setup-Cpp on Dev.to](https://dev.to/aminya/setup-cpp-3ia4)

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
1515
import { setupPython } from "./python/python"
1616
import mri from "mri"
1717
import untildify from "untildify"
18-
import { isCI } from "./utils/env/isci"
18+
import { isGitHubCI } from "./utils/env/isci"
1919

2020
import semverValid from "semver/functions/valid"
2121
import { getVersion } from "./default_versions"
@@ -79,7 +79,7 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
7979

8080
/** The main entry function */
8181
export async function main(args: string[]): Promise<number> {
82-
if (!isCI()) {
82+
if (!isGitHubCI()) {
8383
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
8484
}
8585

@@ -196,7 +196,7 @@ export async function main(args: string[]): Promise<number> {
196196

197197
core.info("setup_cpp finished")
198198

199-
if (!isCI()) {
199+
if (!isGitHubCI()) {
200200
switch (process.platform) {
201201
case "win32": {
202202
core.info("Run `RefreshEnv.cmd` or restart your shell to update the environment.")

src/python/python.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
55
import { setupChocoPack } from "../utils/setup/setupChocoPack"
66
import hasha from "hasha"
77
import { join } from "path"
8-
import { isCI } from "../utils/env/isci"
8+
import { isGitHubCI } from "../utils/env/isci"
99

1010
export function setupPython(version: string, setupDir: string, arch: string) {
11-
if (!isCI()) {
11+
if (!isGitHubCI()) {
1212
// TODO parse versoin
1313
return setupPythonViaSystem("", setupDir, arch)
1414
}

src/utils/env/isci.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export function isCI() {
2-
return !(process.env.CI === undefined || process.env.CI === "" || process.env.CI === "false")
2+
return process.env.CI === "true"
3+
}
4+
5+
export function isGitHubCI() {
6+
return isCI() && process.env.GITHUB_ACTIONS == "true"
37
}

src/utils/io/io.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as core from "@actions/core"
2-
import { isCI } from "../env/isci"
2+
import { isGitHubCI } from "../env/isci"
33

44
export function error(err: string | Error) {
5-
return isCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`)
5+
return isGitHubCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`)
66
}
77

88
export function success(msg: string) {
9-
return isCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
9+
return isGitHubCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
1010
}

src/utils/path/addPath.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,47 @@ import { addPath as ghAddPath } from "@actions/core"
22
import { delimiter } from "path"
33
import * as core from "@actions/core"
44
import execa from "execa"
5+
import { isGitHubCI } from "../env/isci"
6+
import untildify from "untildify"
7+
import { appendFileSync } from "fs"
8+
// import { spawnSync } from "child_process"
59

610
/** An add path function that works locally or inside GitHub Actions */
711
export function addPath(path: string) {
812
try {
9-
ghAddPath(path)
13+
if (isGitHubCI()) {
14+
ghAddPath(path)
15+
} else {
16+
addPathSystem(path)
17+
}
1018
} catch (err) {
1119
try {
1220
core.error(err as Error)
13-
switch (process.platform) {
14-
case "win32": {
15-
execa.sync(`setx PATH=${path};%PATH%`)
16-
return
17-
}
18-
case "linux":
19-
case "darwin": {
20-
execa.commandSync(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
21-
execa.commandSync(`source ~/.profile`)
22-
core.info(`${path} was added to ~/.profile`)
23-
return
24-
}
25-
default: {
26-
// fall through shell path modification
27-
}
28-
}
21+
return addPathSystem(path)
2922
} catch (err2) {
3023
core.error(err2 as Error)
3124
}
3225
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`)
33-
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
3426
}
3527
}
28+
29+
function addPathSystem(path: string) {
30+
switch (process.platform) {
31+
case "win32": {
32+
execa.sync(`setx PATH=${path};%PATH%`)
33+
return
34+
}
35+
case "linux":
36+
case "darwin": {
37+
const profile_path = untildify("~/.profile")
38+
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
39+
// spawnSync(`source "${profile_path}"`, { shell: true })
40+
core.info(`${path} was added to "${profile_path}"`)
41+
return
42+
}
43+
default: {
44+
// fall through shell path modification
45+
}
46+
}
47+
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
48+
}

src/utils/setup/setupBin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { addPath } from "../path/addPath"
44
import { join } from "path"
55
import { existsSync } from "fs"
66
import { tmpdir } from "os"
7-
import { isCI } from "../env/isci"
7+
import { isGitHubCI } from "../env/isci"
88

99
/** A type that describes a package */
1010
export type PackageInfo = {
@@ -52,7 +52,7 @@ export async function setupBin(
5252
)
5353

5454
// Restore from cache (if found).
55-
if (isCI()) {
55+
if (isGitHubCI()) {
5656
try {
5757
const dir = find(name, version)
5858
if (dir) {
@@ -86,7 +86,7 @@ export async function setupBin(
8686
addPath(binDir)
8787

8888
// check if inside Github Actions. If so, cache the installation
89-
if (isCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
89+
if (isGitHubCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
9090
await cacheDir(setupDir, name, version)
9191
}
9292

0 commit comments

Comments
 (0)