Skip to content

Commit 43d199d

Browse files
committed
fix: fix the kcov download link
1 parent 15070ee commit 43d199d

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

src/kcov/__tests__/kcov.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import { setupKcov } from "../kcov"
22
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
33
import { InstallationInfo } from "../../utils/setup/setupBin"
44
import which from "which"
5+
import { info } from "@actions/core"
56

67
jest.setTimeout(300000)
78
describe("setup-Kcov", () => {
8-
if (process.platform !== "linux") {
9-
it.todo("should setup kcov on non-linux")
9+
if (process.platform === "win32") {
10+
it.todo("should setup kcov on windows")
1011
return
1112
}
1213

14+
it("should setup Kcov v40", async () => {
15+
const directory = await setupTmpDir("kcov-v40")
16+
const { binDir } = (await setupKcov("40-binary", directory, "")) as InstallationInfo
17+
// the prebuild binary only works on ubuntu 20.04
18+
try {
19+
await testBin("kcov", ["--version"], binDir)
20+
} catch (err) {
21+
info((err as Error).message)
22+
}
23+
await cleanupTmpDir("kcov-v40")
24+
})
25+
1326
it("should setup Kcov v40", async () => {
1427
const directory = await setupTmpDir("kcov-v40")
1528
const { binDir } = (await setupKcov("40", directory, "")) as InstallationInfo

src/kcov/kcov.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { isArch } from "../utils/env/isArch"
1414
import { hasDnf } from "../utils/env/hasDnf"
1515
import { setupDnfPack } from "../utils/setup/setupDnfPack"
1616
import { isUbuntu } from "../utils/env/isUbuntu"
17-
import { removeVPrefix } from "../utils/setup/version"
17+
import { addVPrefix, removeVPrefix } from "../utils/setup/version"
18+
import { info } from "../utils/io/io"
1819

1920
function getDownloadKcovPackageInfo(version_number: string): PackageInfo {
2021
return {
@@ -62,36 +63,34 @@ async function buildKcov(file: string, dest: string) {
6263
}
6364

6465
export async function setupKcov(versionGiven: string, setupDir: string, arch: string) {
65-
switch (process.platform) {
66-
case "linux": {
67-
// parse version
68-
const versionSplit = versionGiven.split("-")
69-
let version = versionSplit[0]
70-
const installMethod = versionSplit[1] as "binary" | undefined
71-
const version_number = removeVPrefix(version)
72-
// fix inconsistency in tagging
73-
if (version_number === 38) {
74-
version = "v38"
75-
}
66+
if (process.platform === "win32") {
67+
info("Kcov is not supported on Windows")
68+
return
69+
}
7670

77-
let installationInfo: InstallationInfo
78-
if (installMethod === "binary" && version_number >= 39) {
79-
installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch)
80-
if (isArch()) {
81-
setupPacmanPack("binutils")
82-
} else if (hasDnf()) {
83-
setupDnfPack("binutils")
84-
} else if (isUbuntu()) {
85-
setupAptPack("libbinutils")
86-
}
87-
return installationInfo
88-
} else {
89-
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
90-
}
91-
return installationInfo
92-
}
93-
default: {
94-
throw new Error(`Unsupported platform for ${arch}`)
71+
// parse version
72+
const versionSplit = versionGiven.split("-")
73+
let version = addVPrefix(versionSplit[0])
74+
const installMethod = versionSplit[1] as "binary" | undefined
75+
const version_number = removeVPrefix(version)
76+
// fix inconsistency in tagging
77+
if (version_number === 38) {
78+
version = "v38"
79+
}
80+
81+
let installationInfo: InstallationInfo
82+
if (installMethod === "binary" && version_number >= 39) {
83+
installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch)
84+
if (isArch()) {
85+
setupPacmanPack("binutils")
86+
} else if (hasDnf()) {
87+
setupDnfPack("binutils")
88+
} else if (isUbuntu()) {
89+
setupAptPack("libbinutils")
9590
}
91+
return installationInfo
92+
} else {
93+
installationInfo = await setupBin("kcov", version, getBuildKcovPackageInfo, setupDir, arch)
9694
}
95+
return installationInfo
9796
}

src/utils/setup/version.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,10 @@ export function semverCoerceIfInvalid(version: string) {
119119
export function removeVPrefix(version: string) {
120120
return parseInt(version.replace(/^v/, ""), 10)
121121
}
122+
123+
export function addVPrefix(version: string) {
124+
if (!version.match(/^v/)) {
125+
return `v${version}`
126+
}
127+
return version
128+
}

0 commit comments

Comments
 (0)