Skip to content

Commit 61f88f8

Browse files
authored
Merge pull request #828 from dimitrovmaksim/fix_getting_linux_version
Graph test command: Fix Linux version
2 parents 32f672c + b450629 commit 61f88f8

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/commands/test.js

Lines changed: 27 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()
127-
const release = os.release()
128127
const cpuCore = os.cpus()[0]
129-
const majorVersion = semver.major(release)
130128
const isM1 = cpuCore.model.includes("Apple M1")
129+
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : new Map()
130+
const linuxDistro = linuxInfo.get('name')
131+
const release = linuxInfo.get('version') || os.release()
132+
const majorVersion = parseInt(linuxInfo.get('version'), 10) || 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 type: ${linuxDistro || 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,8 +148,9 @@ function getPlatform(logsOpt) {
146148
} else if (type === 'Linux') {
147149
if (majorVersion === 18) {
148150
return 'binary-linux-18'
151+
} else {
152+
return 'binary-linux-20'
149153
}
150-
return 'binary-linux-20'
151154
} else if (type === 'Windows_NT') {
152155
return 'binary-windows'
153156
}
@@ -156,6 +159,23 @@ function getPlatform(logsOpt) {
156159
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
157160
}
158161

162+
async function getLinuxInfo() {
163+
try {
164+
let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {trim: true})
165+
let infoArray = result.replace(/['"]+/g, '').split('\n').map(p => p.split('='))
166+
let infoMap = new Map();
167+
168+
infoArray.forEach((val) => {
169+
infoMap.set(val[0].toLowerCase(), val[1])
170+
});
171+
172+
return infoMap
173+
} catch (error) {
174+
print.error(`Error fetching the Linux version:\n ${error}`)
175+
process.exit(1)
176+
}
177+
}
178+
159179
async function runDocker(datasource, opts) {
160180
let coverageOpt = opts.get("coverage")
161181
let forceOpt = opts.get("force")

0 commit comments

Comments
 (0)