fix: make install directory configurable

This commit is contained in:
Amin Yahyaabadi 2021-09-14 07:02:34 -05:00
parent 40336c3c67
commit a5ae2b4863
7 changed files with 17 additions and 13 deletions

View File

@ -9,7 +9,7 @@ Settting up a **cross-platform** enviroment for building and testing C++/C proje
This package is designed to be fully **modular** and as **minimal** as possible. This will allow you to only install the tools you want. This package is designed to be fully **modular** and as **minimal** as possible. This will allow you to only install the tools you want.
The package will be usable locally or inside GitHub Actions. Stay tuned for the stable release. The package will be usable from any environment (locally, GitHub Actions, etc). Stay tuned for the stable release.
# Features (WIP) # Features (WIP)

View File

@ -5,8 +5,9 @@ import { setupTmpDir, cleanupTmpDir } from "../../utils/tests/test-helpers"
jest.setTimeout(100000) jest.setTimeout(100000)
describe("setup-cmake", () => { describe("setup-cmake", () => {
let directory: string
beforeEach(async () => { beforeEach(async () => {
await setupTmpDir("setup-cmake") directory = await setupTmpDir("setup-cmake")
}) })
afterAll(async () => { afterAll(async () => {
@ -14,7 +15,7 @@ describe("setup-cmake", () => {
}, 100000) }, 100000)
it("should setup CMake", async () => { it("should setup CMake", async () => {
const cmakePath = await setupCmake("3.20.2") const cmakePath = await setupCmake("3.20.2", directory)
expect(cmakePath).toBeDefined() expect(cmakePath).toBeDefined()
expect(cmakePath).not.toHaveLength(0) expect(cmakePath).not.toHaveLength(0)

View File

@ -59,6 +59,6 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
} }
/** Setup cmake */ /** Setup cmake */
export function setupCmake(version: string): Promise<string> { export function setupCmake(version: string, setupCppDir: string): Promise<string> {
return setupBin("cmake", version, getCmakePackageInfo) return setupBin("cmake", version, getCmakePackageInfo, setupCppDir)
} }

View File

@ -1,5 +1,6 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import { setupCmake } from "./cmake/cmake" import { setupCmake } from "./cmake/cmake"
import { setupLLVM } from "./llvm/llvm"
import { setupNinja } from "./ninja/ninja" import { setupNinja } from "./ninja/ninja"
function maybeGetInput(key: string) { function maybeGetInput(key: string) {
@ -11,17 +12,18 @@ function maybeGetInput(key: string) {
} }
export async function main(): Promise<number> { export async function main(): Promise<number> {
const setupCppDir = process.env.SETUP_CPP_DIR ?? "~/setup_cpp"
try { try {
// setup cmake // setup cmake
const cmakeVersion = maybeGetInput("cmake") const cmakeVersion = maybeGetInput("cmake")
if (cmakeVersion !== undefined) { if (cmakeVersion !== undefined) {
await setupCmake(cmakeVersion) await setupCmake(cmakeVersion, setupCppDir)
} }
// setup ninja // setup ninja
const ninjaVersion = maybeGetInput("ninja") const ninjaVersion = maybeGetInput("ninja")
if (ninjaVersion !== undefined) { if (ninjaVersion !== undefined) {
await setupNinja(ninjaVersion) await setupNinja(ninjaVersion, setupCppDir)
} }
} catch (err) { } catch (err) {
core.error(err as string | Error) core.error(err as string | Error)

View File

@ -5,8 +5,9 @@ import { setupTmpDir, cleanupTmpDir } from "../../utils/tests/test-helpers"
jest.setTimeout(100000) jest.setTimeout(100000)
describe("setup-ninja", () => { describe("setup-ninja", () => {
let directory: string
beforeEach(async () => { beforeEach(async () => {
await setupTmpDir("setup-ninja") directory = await setupTmpDir("setup-ninja")
}) })
afterAll(async () => { afterAll(async () => {
@ -14,7 +15,7 @@ describe("setup-ninja", () => {
}, 100000) }, 100000)
it("should setup Ninja", async () => { it("should setup Ninja", async () => {
const ninjaPath = await setupNinja("1.10.2") const ninjaPath = await setupNinja("1.10.2", directory)
expect(ninjaPath).toBeDefined() expect(ninjaPath).toBeDefined()
expect(ninjaPath).not.toHaveLength(0) expect(ninjaPath).not.toHaveLength(0)

View File

@ -26,6 +26,6 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
} }
} }
export function setupNinja(version: string): Promise<string> { export function setupNinja(version: string, setupCppDir: string): Promise<string> {
return setupBin("ninja", version, getNinjaPackageInfo) return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir)
} }

View File

@ -23,9 +23,9 @@ export type PackageInfo = {
export async function setupBin( export async function setupBin(
name: string, name: string,
version: string, version: string,
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo,
setupCppDir: string
): Promise<string> { ): Promise<string> {
const setupCppDir = process.env.SETUP_CPP_DIR ?? "~/setup_cpp"
process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir() process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(setupCppDir, "ToolCache") process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(setupCppDir, "ToolCache")