Skip to content

Commit 8ea041d

Browse files
Use shell command to get the Linux Version
1 parent 32f672c commit 8ea041d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/commands/test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { Binary } = require('binary-install-raw')
22
const os = require('os')
33
const chalk = require('chalk')
44
const fetch = require('node-fetch')
5-
const { filesystem, patching, print } = require('gluegun')
5+
const { filesystem, patching, print, system } = require('gluegun')
66
const { fixParameters } = require('../command-helpers/gluegun')
77
const path = require('path')
88
const semver = require('semver')
@@ -103,7 +103,7 @@ async function runBinary(datasource, opts) {
103103
let latestVersion = opts.get("latestVersion")
104104
let recompileOpt = opts.get("recompile")
105105

106-
const platform = getPlatform(logsOpt)
106+
const platform = await getPlatform(logsOpt)
107107

108108
const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`
109109

@@ -121,16 +121,18 @@ async function runBinary(datasource, opts) {
121121
args.length > 0 ? binary.run(...args) : binary.run()
122122
}
123123

124-
function getPlatform(logsOpt) {
124+
async function getPlatform(logsOpt) {
125125
const type = os.type()
126126
const arch = os.arch()
127127
const release = os.release()
128128
const cpuCore = os.cpus()[0]
129-
const majorVersion = semver.major(release)
130129
const isM1 = cpuCore.model.includes("Apple M1")
130+
const majorVersion = semver.major(release)
131+
let linuxVersion = ""
132+
if (type === 'Linux') linuxVersion = await getLinuxVersion()
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 type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${type === 'Linux' ? linuxVersion : majorVersion}\nCPU model: ${cpuCore.model}`)
134136
}
135137

136138
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
@@ -144,10 +146,13 @@ function getPlatform(logsOpt) {
144146
}
145147
return 'binary-macos-11'
146148
} else if (type === 'Linux') {
147-
if (majorVersion === 18) {
149+
if (linuxVersion === '18.04') {
148150
return 'binary-linux-18'
151+
} else if (linuxVersion == '20.04') {
152+
return 'binary-linux-20'
153+
} else {
154+
throw new Error(`Unsupported Linux Version: ${linuxVersion}`)
149155
}
150-
return 'binary-linux-20'
151156
} else if (type === 'Windows_NT') {
152157
return 'binary-windows'
153158
}
@@ -156,6 +161,11 @@ function getPlatform(logsOpt) {
156161
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
157162
}
158163

164+
async function getLinuxVersion() {
165+
let version = await system.run("grep '^VERSION_ID' /etc/os-release", {trim: true})
166+
return version.replace(/[VERSION_ID=]|['"]+/g, '').trim()
167+
}
168+
159169
async function runDocker(datasource, opts) {
160170
let coverageOpt = opts.get("coverage")
161171
let forceOpt = opts.get("force")

0 commit comments

Comments
 (0)