fix: fix the kcov download link

This commit is contained in:
Amin Yahyaabadi 2022-07-22 13:57:11 -07:00
parent 15070ee637
commit 43d199d290
3 changed files with 53 additions and 34 deletions

View File

@ -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

View File

@ -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,11 +63,14 @@ async function buildKcov(file: string, dest: string) {
}
export async function setupKcov(versionGiven: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
if (process.platform === "win32") {
info("Kcov is not supported on Windows")
return
}
// parse version
const versionSplit = versionGiven.split("-")
let version = versionSplit[0]
let version = addVPrefix(versionSplit[0])
const installMethod = versionSplit[1] as "binary" | undefined
const version_number = removeVPrefix(version)
// fix inconsistency in tagging
@ -90,8 +94,3 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
}
return installationInfo
}
default: {
throw new Error(`Unsupported platform for ${arch}`)
}
}
}

View File

@ -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
}