Skip to content

Commit b49afc1

Browse files
Fetch Linux destro name and full version
1 parent 727b2f8 commit b49afc1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/commands/test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ async function runBinary(datasource, opts) {
124124
async function getPlatform(logsOpt) {
125125
const type = os.type()
126126
const arch = os.arch()
127-
const release = os.release()
128127
const cpuCore = os.cpus()[0]
129128
const isM1 = cpuCore.model.includes("Apple M1")
130-
const majorVersion = (type === 'Linux') ? await getLinuxVersion() : semver.major(release)
129+
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : []
130+
const linuxDestro = linuxInfo[0] || type
131+
const release = linuxInfo[1] || os.release()
132+
const majorVersion = parseInt(linuxInfo[1]) || semver.major(release)
131133

132134
if (logsOpt) {
133-
print.info(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
135+
print.info(`OS: ${linuxDestro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
134136
}
135137

136138
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
@@ -146,10 +148,8 @@ async function getPlatform(logsOpt) {
146148
} else if (type === 'Linux') {
147149
if (majorVersion === 18) {
148150
return 'binary-linux-18'
149-
} else if (majorVersion == 20) {
150-
return 'binary-linux-20'
151151
} else {
152-
throw new Error(`Unsupported Linux Version: ${majorVersion}`)
152+
return 'binary-linux-20'
153153
}
154154
} else if (type === 'Windows_NT') {
155155
return 'binary-windows'
@@ -159,10 +159,14 @@ async function getPlatform(logsOpt) {
159159
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
160160
}
161161

162-
async function getLinuxVersion() {
163-
let version = await system.run("grep '^VERSION_ID' /etc/os-release", {trim: true})
164-
version = version.replace(/[VERSION_ID=]|['"]+/g, '')
165-
return parseInt(version)
162+
async function getLinuxInfo() {
163+
try {
164+
let info = await system.run("cat /etc/*-release | egrep -e '(^VERSION|^NAME)='", {trim: true})
165+
return info.replace(/[VERSION=]|[NAME=]|['"]+/g, '').split('\n')
166+
} catch (error) {
167+
print.error(`Error fetching the Linux version:\n ${error}`)
168+
process.exit(1)
169+
}
166170
}
167171

168172
async function runDocker(datasource, opts) {

0 commit comments

Comments
 (0)