mirror of https://github.com/aminya/setup-cpp
feat: support ubuntu version on Ubuntu-based distros
This commit is contained in:
parent
76c4891c79
commit
cfa0cc5326
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3,18 +3,23 @@ import { getUbuntuVersion } from "ubuntu-version"
|
|||
import which from "which"
|
||||
import { setupAptPack } from "../setup/setupAptPack"
|
||||
import { isUbuntu } from "./isUbuntu"
|
||||
import os from "os"
|
||||
|
||||
export async function ubuntuVersion(): Promise<number[] | null> {
|
||||
try {
|
||||
if (isUbuntu()) {
|
||||
try {
|
||||
if (which.sync("lsb_release", { nothrow: true }) === null) {
|
||||
await setupAptPack([{ name: "lsb-release" }])
|
||||
}
|
||||
} catch {
|
||||
return detectUsingOsVersion()
|
||||
}
|
||||
|
||||
const versionSplitted = await getUbuntuVersion()
|
||||
|
||||
if (versionSplitted.length === 0) {
|
||||
warning("Failed to get the ubuntu major version.")
|
||||
return null
|
||||
return detectUsingOsVersion()
|
||||
}
|
||||
|
||||
return versionSplitted
|
||||
|
@ -26,3 +31,14 @@ export async function ubuntuVersion(): Promise<number[] | null> {
|
|||
return null
|
||||
}
|
||||
}
|
||||
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
|
||||
function detectUsingOsVersion() {
|
||||
// #46~22.04.1-Ubuntu SMP ...
|
||||
const osVersion = os.version()
|
||||
const versionSplitted = osVersion.split(".")
|
||||
const majorVersion = parseInt(versionSplitted[0].replace("#", ""), 10)
|
||||
const minorVersion = parseInt(versionSplitted[1].replace("~", ""), 10)
|
||||
const patchVersion = parseInt(versionSplitted[2].split("-")[0], 10)
|
||||
|
||||
return [majorVersion, minorVersion, patchVersion]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue