From 6c87c81bbd983b743d5627c4cdb81f547b2516ef Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Mon, 5 Dec 2022 18:34:56 +0100 Subject: [PATCH] Add OS info to the error message --- dist/setup/index.js | 48 +++++++++++++++++++++++++++++++++++++-- src/find-python.ts | 5 +++-- src/utils.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2ca2fe1b..3214260a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66377,8 +66377,9 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest } } if (!installDir) { + const osInfo = yield utils_1.getOSInfo(); throw new Error([ - `Version ${version} with arch ${architecture} not found`, + `Version ${version} with arch ${architecture} not found for ${osInfo}`, `The list of all available versions can be found here: ${installer.MANIFEST_URL}` ].join(os.EOL)); } @@ -66951,7 +66952,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.logWarning = exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.getOSInfo = exports.logWarning = exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const fs_1 = __importDefault(__nccwpck_require__(7147)); @@ -67058,6 +67059,49 @@ function logWarning(message) { core.info(`${warningPrefix}${message}`); } exports.logWarning = logWarning; +function getWindowsInfo() { + return __awaiter(this, void 0, void 0, function* () { + const { stdout } = yield exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', undefined, { + silent: true + }); + const windowsVersion = stdout.trim().split(' ')[3]; + return `Windows ${windowsVersion}`; + }); +} +function getMacOSInfo() { + return __awaiter(this, void 0, void 0, function* () { + const { stdout } = yield exec.getExecOutput('sw_vers', ['-productVersion'], { + silent: true + }); + const macOSVersion = stdout.trim(); + return `macOS ${macOSVersion}`; + }); +} +function getLinuxInfo() { + return __awaiter(this, void 0, void 0, function* () { + const { stdout } = yield exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], { + silent: true + }); + const [osName, osVersion] = stdout.trim().split('\n'); + return `${osName} ${osVersion}`; + }); +} +function getOSInfo() { + return __awaiter(this, void 0, void 0, function* () { + let osInfo; + if (exports.IS_WINDOWS) { + osInfo = yield getWindowsInfo(); + } + else if (exports.IS_LINUX) { + osInfo = yield getLinuxInfo(); + } + else if (exports.IS_MAC) { + osInfo = yield getMacOSInfo(); + } + return osInfo; + }); +} +exports.getOSInfo = getOSInfo; /***/ }), diff --git a/src/find-python.ts b/src/find-python.ts index 4e54a94b..8cb3bdb4 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -1,6 +1,6 @@ import * as os from 'os'; import * as path from 'path'; -import {IS_WINDOWS, IS_LINUX} from './utils'; +import {IS_WINDOWS, IS_LINUX, getOSInfo} from './utils'; import * as semver from 'semver'; @@ -85,9 +85,10 @@ export async function useCpythonVersion( } if (!installDir) { + const osInfo = await getOSInfo(); throw new Error( [ - `Version ${version} with arch ${architecture} not found`, + `Version ${version} with arch ${architecture} not found for ${osInfo}`, `The list of all available versions can be found here: ${installer.MANIFEST_URL}` ].join(os.EOL) ); diff --git a/src/utils.ts b/src/utils.ts index b29c79d6..61594b7c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -142,3 +142,58 @@ export function logWarning(message: string): void { const warningPrefix = '[warning]'; core.info(`${warningPrefix}${message}`); } + +async function getWindowsInfo() { + const {stdout} = await exec.getExecOutput( + 'powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', + undefined, + { + silent: true + } + ); + + const windowsVersion = stdout.trim().split(' ')[3]; + + return `Windows ${windowsVersion}`; +} + +async function getMacOSInfo() { + const {stdout} = await exec.getExecOutput( + 'sw_vers', + ['-productVersion'], + { + silent: true + } + ); + + const macOSVersion = stdout.trim(); + + return `macOS ${macOSVersion}`; +} + +async function getLinuxInfo() { + const {stdout} = await exec.getExecOutput( + 'lsb_release', + ['-i', '-r', '-s'], + { + silent: true + } + ); + + const [osName, osVersion] = stdout.trim().split('\n'); + + return `${osName} ${osVersion}`; +} + +export async function getOSInfo() { + let osInfo; + if (IS_WINDOWS){ + osInfo = await getWindowsInfo(); + } else if (IS_LINUX) { + osInfo = await getLinuxInfo(); + } else if (IS_MAC) { + osInfo = await getMacOSInfo(); + } + + return osInfo; +}