Skip to content

Commit cfa0cc5

Browse files
committed
feat: support ubuntu version on Ubuntu-based distros
1 parent 76c4891 commit cfa0cc5

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

dist/node12/setup-cpp.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/env/ubuntu_version.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ import { getUbuntuVersion } from "ubuntu-version"
33
import which from "which"
44
import { setupAptPack } from "../setup/setupAptPack"
55
import { isUbuntu } from "./isUbuntu"
6+
import os from "os"
67

78
export async function ubuntuVersion(): Promise<number[] | null> {
89
try {
910
if (isUbuntu()) {
10-
if (which.sync("lsb_release", { nothrow: true }) === null) {
11-
await setupAptPack([{ name: "lsb-release" }])
11+
try {
12+
if (which.sync("lsb_release", { nothrow: true }) === null) {
13+
await setupAptPack([{ name: "lsb-release" }])
14+
}
15+
} catch {
16+
return detectUsingOsVersion()
1217
}
18+
1319
const versionSplitted = await getUbuntuVersion()
1420

1521
if (versionSplitted.length === 0) {
16-
warning("Failed to get the ubuntu major version.")
17-
return null
22+
return detectUsingOsVersion()
1823
}
1924

2025
return versionSplitted
@@ -26,3 +31,14 @@ export async function ubuntuVersion(): Promise<number[] | null> {
2631
return null
2732
}
2833
}
34+
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
35+
function detectUsingOsVersion() {
36+
// #46~22.04.1-Ubuntu SMP ...
37+
const osVersion = os.version()
38+
const versionSplitted = osVersion.split(".")
39+
const majorVersion = parseInt(versionSplitted[0].replace("#", ""), 10)
40+
const minorVersion = parseInt(versionSplitted[1].replace("~", ""), 10)
41+
const patchVersion = parseInt(versionSplitted[2].split("-")[0], 10)
42+
43+
return [majorVersion, minorVersion, patchVersion]
44+
}

0 commit comments

Comments
 (0)