feat: use a similar interface for installing all the packages

This commit is contained in:
Amin Yahyaabadi 2021-09-16 06:57:37 -05:00
parent a970eb0e44
commit 511a2fbbce
16 changed files with 92 additions and 112 deletions

View File

@ -1,7 +1,8 @@
import { execFileSync } from "child_process" import { execFileSync } from "child_process"
import which from "which" import which from "which"
export function setupBrew() { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupBrew(_version: string, _setupCppDir: string, _arch: string) {
if (!["darwin", "linux"].includes(process.platform)) { if (!["darwin", "linux"].includes(process.platform)) {
return return
} }

View File

@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
export function setupCcache(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCcache(version: string, _setupCppDir: string, _arch: string) {
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
return setupChocoPack("ccache", version) return setupChocoPack("ccache", version)

View File

@ -1,7 +1,8 @@
import { exec } from "@actions/exec" import { exec } from "@actions/exec"
import which from "which" import which from "which"
export async function setupChocolatey() { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }

View File

@ -59,6 +59,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
} }
/** Setup cmake */ /** Setup cmake */
export function setupCmake(version: string, setupCppDir: string): Promise<InstallationInfo> { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCmake(version: string, setupCppDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("cmake", version, getCmakePackageInfo, setupCppDir) return setupBin("cmake", version, getCmakePackageInfo, setupCppDir)
} }

View File

@ -1,5 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack" import { setupPipPack } from "../utils/setup/setupPipPack"
export async function setupConan(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupConan(version: string | undefined, _setupCppDir: string, _arch: string) {
await setupPipPack("conan", version) await setupPipPack("conan", version)
} }

View File

@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
export function setupCppcheck(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCppcheck(version: string | undefined, _setupCppDir: string, _arch: string) {
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
return setupChocoPack("cppcheck", version) return setupChocoPack("cppcheck", version)

View File

@ -7,7 +7,7 @@ const DefaultVersions: Record<string, string> = {
/** Get the default version if passed true or undefined, otherwise return the version itself */ /** Get the default version if passed true or undefined, otherwise return the version itself */
export function getVersion(name: string, version: string | undefined) { export function getVersion(name: string, version: string | undefined) {
if (version === "true" || version === undefined) { if (version === "true" || (version === undefined && name in DefaultVersions)) {
return DefaultVersions[name] return DefaultVersions[name]
} else { } else {
return version return version

View File

@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
export async function setupDoxygen(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupDoxygen(version: string | undefined, _setupCppDir: string, _arch: string) {
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
await setupChocoPack("graphviz", version) await setupChocoPack("graphviz", version)

View File

@ -1,5 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack" import { setupPipPack } from "../utils/setup/setupPipPack"
export async function setupGcovr(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupGcovr(version: string | undefined, _setupCppDir: string, _arch: string) {
await setupPipPack("gcovr", version) await setupPipPack("gcovr", version)
} }

View File

@ -233,8 +233,13 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
} }
} }
export async function setupLLVM(version: string, directoryGiven?: string): Promise<InstallationInfo> { // eslint-disable-next-line @typescript-eslint/no-unused-vars
let directory = directoryGiven export async function setupLLVM(
version: string,
_setupCppDir: string | undefined,
_arch: string
): Promise<InstallationInfo> {
let directory = _setupCppDir
if (directory === "" || directory === undefined) { if (directory === "" || directory === undefined) {
directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY
} }

View File

@ -13,8 +13,34 @@ import { setupMSVC } from "./msvc/msvc"
import { setupNinja } from "./ninja/ninja" import { setupNinja } from "./ninja/ninja"
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage" import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPython } from "./python/python" import { setupPython } from "./python/python"
import semverValid from "semver/functions/valid" import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions" import { getVersion } from "./default_versions"
import { InstallationInfo } from "./utils/setup/setupBin"
const setups = {
cmake: setupCmake,
ninja: setupNinja,
python: setupPython,
conan: setupConan,
meson: setupMeson,
gcovr: setupGcovr,
opencppcoverage: setupOpencppcoverage,
llvm: setupLLVM,
choco: setupChocolatey,
brew: setupBrew,
ccache: setupCcache,
doxygen: setupDoxygen,
cppcheck: setupCppcheck,
msvc: setupMSVC,
} as Record<
string,
(
version: string | undefined,
setupCppDir: string,
...args: unknown[]
) => Promise<InstallationInfo> | Promise<void> | void
>
function maybeGetInput(key: string) { function maybeGetInput(key: string) {
const value = core.getInput(key.toLowerCase()) const value = core.getInput(key.toLowerCase())
@ -46,7 +72,7 @@ export async function main(): Promise<number> {
case "llvm": case "llvm":
case "clang": case "clang":
case "clang++": { case "clang++": {
await setupLLVM(getVersion("llvm", version), setupCppDir) await setupLLVM(getVersion("llvm", version) as string, setupCppDir, arch)
break break
} }
case "cl": case "cl":
@ -56,7 +82,7 @@ export async function main(): Promise<number> {
case "visualstudio": case "visualstudio":
case "visualcpp": case "visualcpp":
case "visualc++": { case "visualc++": {
await setupMSVC(getVersion("msvc", version), setupCppDir) await setupMSVC(getVersion("msvc", version) as string, setupCppDir, arch)
break break
} }
default: { default: {
@ -65,88 +91,28 @@ export async function main(): Promise<number> {
} }
} }
// setup cmake for (const tool of [
const cmakeVersion = maybeGetInput("cmake") "cmake",
if (cmakeVersion !== undefined) { "ninja",
await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir) "python",
} "conan",
"meson",
// setup ninja "gcovr",
const ninjaVersion = maybeGetInput("ninja") "opencppcoverage",
if (ninjaVersion !== undefined) { "llvm",
await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir) "choco",
} "brew",
"ccache",
// setup python (required for conan, meson, gcovr, etc.) "doxygen",
const pythonVersion = maybeGetInput("python") "cppcheck",
if (pythonVersion !== undefined) { "msvc",
await setupPython(getVersion("python", pythonVersion), arch) ]) {
} const version = maybeGetInput(tool)
if (version !== undefined) {
// setup conan const setupFunction = setups[tool]
const conanVersion = maybeGetInput("conan") // eslint-disable-next-line no-await-in-loop
if (conanVersion !== undefined) { await setupFunction(getVersion(tool, version), setupCppDir, arch)
await setupConan(getVersion("conan", conanVersion)) }
}
// setup meson
const mesonVersion = maybeGetInput("meson")
if (mesonVersion !== undefined) {
await setupMeson(getVersion("meson", mesonVersion))
}
// setup gcovr
const gcovrVersion = maybeGetInput("gcovr")
if (gcovrVersion !== undefined) {
await setupGcovr(getVersion("gcovr", gcovrVersion))
}
// setup opencppCoverage
const opencppCoverageVersion = maybeGetInput("opencppcoverage")
if (opencppCoverageVersion !== undefined) {
await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion))
}
// setup llvm
const llvmVersion = maybeGetInput("llvm")
if (llvmVersion !== undefined) {
await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir)
}
// setup chocolatey (required for installing msvc)
const chocoVersion = maybeGetInput("choco")
if (chocoVersion !== undefined) {
await setupChocolatey()
}
// setup brew
const brewVersion = maybeGetInput("brew")
if (brewVersion !== undefined) {
setupBrew()
}
// setup ccache
const ccacheVersion = maybeGetInput("ccache")
if (ccacheVersion !== undefined) {
await setupCcache(getVersion("ccache", ccacheVersion))
}
// setup doxygen
const doxygenVersion = maybeGetInput("doxygen")
if (doxygenVersion !== undefined) {
await setupDoxygen(getVersion("doxygen", doxygenVersion))
}
// setup cppCheck
const cppCheckVersion = maybeGetInput("cppcheck")
if (cppCheckVersion !== undefined) {
await setupCppcheck(getVersion("cppcheck", cppCheckVersion))
}
// setup msvc
const msvcVersion = maybeGetInput("msvc")
if (msvcVersion !== undefined) {
await setupMSVC(getVersion("msvc", msvcVersion))
} }
} catch (err) { } catch (err) {
core.error(err as string | Error) core.error(err as string | Error)

View File

@ -1,5 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack" import { setupPipPack } from "../utils/setup/setupPipPack"
export async function setupMeson(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupMeson(version: string | undefined, _setupCppDir: string, _arch: string) {
await setupPipPack("meson", version) await setupPipPack("meson", version)
} }

View File

@ -24,10 +24,11 @@ function getArch(arch: string): string {
export async function setupMSVC( export async function setupMSVC(
version: MSVCVersion, version: MSVCVersion,
_setupCppDir: string,
arch: string,
sdk?: string, sdk?: string,
uwp?: boolean, uwp?: boolean,
spectre?: boolean, spectre?: boolean
arch = osArch()
): Promise<void> { ): Promise<void> {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return

View File

@ -26,6 +26,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
} }
} }
export function setupNinja(version: string, setupCppDir: string): Promise<InstallationInfo> { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupNinja(version: string, setupCppDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir) return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir)
} }

View File

@ -1,7 +1,8 @@
import { addPath } from "@actions/core" import { addPath } from "@actions/core"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
export async function setupOpencppcoverage(version?: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupOpencppcoverage(version: string | undefined, _setupCppDir: string, _arch: string) {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }

View File

@ -2,24 +2,21 @@ import * as core from "@actions/core"
import * as finder from "./setup-python/src/find-python" import * as finder from "./setup-python/src/find-python"
import * as finderPyPy from "./setup-python/src/find-pypy" import * as finderPyPy from "./setup-python/src/find-pypy"
import * as path from "path" import * as path from "path"
import * as os from "os"
function isPyPyVersion(versionSpec: string) { function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy-") return versionSpec.startsWith("pypy-")
} }
export async function setupPython(version?: string, arch: string = os.arch()) { export async function setupPython(version: string, _setupCppDir: string, arch: string) {
try { try {
if (version !== undefined && version !== "") { if (isPyPyVersion(version)) {
if (isPyPyVersion(version)) { const installed = await finderPyPy.findPyPyVersion(version, arch)
const installed = await finderPyPy.findPyPyVersion(version, arch) core.info(
core.info( `Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` )
) } else {
} else { const installed = await finder.findPythonVersion(version, arch)
const installed = await finder.findPythonVersion(version, arch) core.info(`Successfully setup ${installed.impl} (${installed.version})`)
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
}
} }
const matchersPath = path.join(__dirname, "..", ".github") const matchersPath = path.join(__dirname, "..", ".github")
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`) core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)