chore: make ubuntuVersion exception safe

This commit is contained in:
Amin Yahyaabadi 2022-11-02 20:06:36 -07:00
parent b9c2f3b391
commit 23a09cba35
10 changed files with 30 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/node12/setup_cpp.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/node12/setup_cpp.js.map vendored Normal file

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

2
dist/node16/setup_cpp.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/node16/setup_cpp.js.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -148,13 +148,7 @@ export async function main(args: string[]): Promise<number> {
// installing the specified tools // installing the specified tools
let osVersion: number[] | null = null const osVersion = await ubuntuVersion()
try {
// get the version if not already done
osVersion = await ubuntuVersion()
} catch (err) {
warning((err as Error).toString())
}
// sync the version for the llvm tools // sync the version for the llvm tools
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) { if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {

View File

@ -1,21 +1,28 @@
import { warning } from "ci-log"
import { getUbuntuVersion } from "ubuntu-version" import { getUbuntuVersion } from "ubuntu-version"
import which from "which" import which from "which"
import { setupAptPack } from "../setup/setupAptPack" import { setupAptPack } from "../setup/setupAptPack"
import { isUbuntu } from "./isUbuntu" import { isUbuntu } from "./isUbuntu"
export async function ubuntuVersion(): Promise<number[] | null> { export async function ubuntuVersion(): Promise<number[] | null> {
if (isUbuntu()) { try {
if (which.sync("lsb_release", { nothrow: true }) === null) { if (isUbuntu()) {
await setupAptPack("lsb-release") if (which.sync("lsb_release", { nothrow: true }) === null) {
} await setupAptPack("lsb-release")
const versionSplitted = await getUbuntuVersion() }
const versionSplitted = await getUbuntuVersion()
if (versionSplitted.length === 0) { if (versionSplitted.length === 0) {
throw new Error("Failed to get the ubuntu major version.") warning("Failed to get the ubuntu major version.")
} return null
}
return versionSplitted return versionSplitted
} else { } else {
return null
}
} catch (err) {
warning((err as Error).toString())
return null return null
} }
} }