From 43d199d290c83bc4956acb97e35c0138b782d2aa Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 22 Jul 2022 13:57:11 -0700 Subject: [PATCH] fix: fix the kcov download link --- src/kcov/__tests__/kcov.test.ts | 17 +++++++-- src/kcov/kcov.ts | 63 ++++++++++++++++----------------- src/utils/setup/version.ts | 7 ++++ 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/kcov/__tests__/kcov.test.ts b/src/kcov/__tests__/kcov.test.ts index b8314c38..cd660ec7 100644 --- a/src/kcov/__tests__/kcov.test.ts +++ b/src/kcov/__tests__/kcov.test.ts @@ -2,14 +2,27 @@ import { setupKcov } from "../kcov" import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" import { InstallationInfo } from "../../utils/setup/setupBin" import which from "which" +import { info } from "@actions/core" jest.setTimeout(300000) describe("setup-Kcov", () => { - if (process.platform !== "linux") { - it.todo("should setup kcov on non-linux") + if (process.platform === "win32") { + it.todo("should setup kcov on windows") return } + it("should setup Kcov v40", async () => { + const directory = await setupTmpDir("kcov-v40") + const { binDir } = (await setupKcov("40-binary", directory, "")) as InstallationInfo + // the prebuild binary only works on ubuntu 20.04 + try { + await testBin("kcov", ["--version"], binDir) + } catch (err) { + info((err as Error).message) + } + await cleanupTmpDir("kcov-v40") + }) + it("should setup Kcov v40", async () => { const directory = await setupTmpDir("kcov-v40") const { binDir } = (await setupKcov("40", directory, "")) as InstallationInfo diff --git a/src/kcov/kcov.ts b/src/kcov/kcov.ts index 849a5baf..7a3988db 100644 --- a/src/kcov/kcov.ts +++ b/src/kcov/kcov.ts @@ -14,7 +14,8 @@ import { isArch } from "../utils/env/isArch" import { hasDnf } from "../utils/env/hasDnf" import { setupDnfPack } from "../utils/setup/setupDnfPack" import { isUbuntu } from "../utils/env/isUbuntu" -import { removeVPrefix } from "../utils/setup/version" +import { addVPrefix, removeVPrefix } from "../utils/setup/version" +import { info } from "../utils/io/io" function getDownloadKcovPackageInfo(version_number: string): PackageInfo { return { @@ -62,36 +63,34 @@ async function buildKcov(file: string, dest: string) { } export async function setupKcov(versionGiven: string, setupDir: string, arch: string) { - switch (process.platform) { - case "linux": { - // parse version - const versionSplit = versionGiven.split("-") - let version = versionSplit[0] - const installMethod = versionSplit[1] as "binary" | undefined - const version_number = removeVPrefix(version) - // fix inconsistency in tagging - if (version_number === 38) { - version = "v38" - } - - let installationInfo: InstallationInfo - if (installMethod === "binary" && version_number >= 39) { - installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch) - if (isArch()) { - setupPacmanPack("binutils") - } else if (hasDnf()) { - setupDnfPack("binutils") - } else if (isUbuntu()) { - setupAptPack("libbinutils") - } - return installationInfo - } else { - installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch) - } - return installationInfo - } - default: { - throw new Error(`Unsupported platform for ${arch}`) - } + if (process.platform === "win32") { + info("Kcov is not supported on Windows") + return } + + // parse version + const versionSplit = versionGiven.split("-") + let version = addVPrefix(versionSplit[0]) + const installMethod = versionSplit[1] as "binary" | undefined + const version_number = removeVPrefix(version) + // fix inconsistency in tagging + if (version_number === 38) { + version = "v38" + } + + let installationInfo: InstallationInfo + if (installMethod === "binary" && version_number >= 39) { + installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch) + if (isArch()) { + setupPacmanPack("binutils") + } else if (hasDnf()) { + setupDnfPack("binutils") + } else if (isUbuntu()) { + setupAptPack("libbinutils") + } + return installationInfo + } else { + installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch) + } + return installationInfo } diff --git a/src/utils/setup/version.ts b/src/utils/setup/version.ts index ae56403a..df2e3692 100644 --- a/src/utils/setup/version.ts +++ b/src/utils/setup/version.ts @@ -119,3 +119,10 @@ export function semverCoerceIfInvalid(version: string) { export function removeVPrefix(version: string) { return parseInt(version.replace(/^v/, ""), 10) } + +export function addVPrefix(version: string) { + if (!version.match(/^v/)) { + return `v${version}` + } + return version +}