Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OS info to the error message #559

Merged
merged 9 commits into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 46 additions & 2 deletions dist/setup/index.js
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;


/***/ }),
Expand Down
7 changes: 5 additions & 2 deletions 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';

Expand Down Expand Up @@ -85,9 +85,12 @@ export async function useCpythonVersion(
}

if (!installDir) {
const osInfo = await getOSInfo();
throw new Error(
[
`Version ${version} with arch ${architecture} not found`,
`The version '${version}' with architecture '${architecture}' was not found for ${
osInfo ? osInfo : 'this operating system'
}.`,
`The list of all available versions can be found here: ${installer.MANIFEST_URL}`
].join(os.EOL)
);
Expand Down
47 changes: 47 additions & 0 deletions src/utils.ts
Expand Up @@ -142,3 +142,50 @@ 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;
}