1
0
Fork 0
mirror of https://github.com/actions/setup-python.git synced 2024-09-19 16:46:43 +00:00

Add OS info to the error message (#559)

This commit is contained in:
MaksimZhukov 2022-12-07 18:12:42 +01:00 committed by GitHub
parent 76bbdfadd7
commit 2c3dd9e7e2
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 42 deletions

View file

@ -30,7 +30,6 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
let saveSatetSpy: jest.SpyInstance; let saveSatetSpy: jest.SpyInstance;
let getStateSpy: jest.SpyInstance; let getStateSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance; let setOutputSpy: jest.SpyInstance;
let getLinuxOSReleaseInfoSpy: jest.SpyInstance;
// cache spy // cache spy
let restoreCacheSpy: jest.SpyInstance; let restoreCacheSpy: jest.SpyInstance;
@ -67,6 +66,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
if (input.includes('poetry')) { if (input.includes('poetry')) {
return {stdout: poetryConfigOutput, stderr: '', exitCode: 0}; return {stdout: poetryConfigOutput, stderr: '', exitCode: 0};
} }
if (input.includes('lsb_release')) {
return {stdout: 'Ubuntu\n20.04', stderr: '', exitCode: 0};
}
return {stdout: '', stderr: 'Error occured', exitCode: 2}; return {stdout: '', stderr: 'Error occured', exitCode: 2};
}); });
@ -83,7 +85,6 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
whichSpy = jest.spyOn(io, 'which'); whichSpy = jest.spyOn(io, 'which');
whichSpy.mockImplementation(() => '/path/to/python'); whichSpy.mockImplementation(() => '/path/to/python');
getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo');
}); });
describe('Validate provided package manager', () => { describe('Validate provided package manager', () => {
@ -120,17 +121,11 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
dependencyFile dependencyFile
); );
if (process.platform === 'linux') {
getLinuxOSReleaseInfoSpy.mockImplementation(() =>
Promise.resolve('Ubuntu-20.4')
);
}
await cacheDistributor.restoreCache(); await cacheDistributor.restoreCache();
if (process.platform === 'linux' && packageManager === 'pip') { if (process.platform === 'linux' && packageManager === 'pip') {
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-20.04-Ubuntu-python-${pythonVersion}-${packageManager}-${fileHash}`
); );
} else { } else {
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(

77
dist/setup/index.js vendored
View file

@ -65943,9 +65943,9 @@ class PipCache extends cache_distributor_1.default {
let primaryKey = ''; let primaryKey = '';
let restoreKey = ''; let restoreKey = '';
if (utils_1.IS_LINUX) { if (utils_1.IS_LINUX) {
const osRelease = yield utils_1.getLinuxOSReleaseInfo(); const osInfo = yield utils_1.getLinuxInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`; restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`;
} }
else { else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
@ -66401,8 +66401,11 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
} }
} }
if (!installDir) { if (!installDir) {
const osInfo = yield utils_1.getOSInfo();
throw new Error([ throw new Error([
`Version ${version} with arch ${architecture} not found`, `The version '${version}' with architecture '${architecture}' was not found for ${osInfo
? `${osInfo.osName} ${osInfo.osVersion}`
: 'this operating system'}.`,
`The list of all available versions can be found here: ${installer.MANIFEST_URL}` `The list of all available versions can be found here: ${installer.MANIFEST_URL}`
].join(os.EOL)); ].join(os.EOL));
} }
@ -66975,7 +66978,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); 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.getLinuxInfo = exports.logWarning = 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 cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147)); const fs_1 = __importDefault(__nccwpck_require__(7147));
@ -67066,22 +67069,64 @@ function isCacheFeatureAvailable() {
return true; return true;
} }
exports.isCacheFeatureAvailable = isCacheFeatureAvailable; exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getLinuxOSReleaseInfo() {
return __awaiter(this, void 0, void 0, function* () {
const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], {
silent: true
});
const [osRelease, osVersion] = stdout.trim().split('\n');
core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`);
return `${osVersion}-${osRelease}`;
});
}
exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo;
function logWarning(message) { function logWarning(message) {
const warningPrefix = '[warning]'; const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`); core.info(`${warningPrefix}${message}`);
} }
exports.logWarning = logWarning; 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 { osName: 'Windows', osVersion: 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 { osName: 'macOS', osVersion: 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');
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
return { osName: osName, osVersion: osVersion };
});
}
exports.getLinuxInfo = getLinuxInfo;
function getOSInfo() {
return __awaiter(this, void 0, void 0, function* () {
let osInfo;
try {
if (exports.IS_WINDOWS) {
osInfo = yield getWindowsInfo();
}
else if (exports.IS_LINUX) {
osInfo = yield getLinuxInfo();
}
else if (exports.IS_MAC) {
osInfo = yield getMacOSInfo();
}
}
catch (err) {
const error = err;
core.debug(error.message);
}
finally {
return osInfo;
}
});
}
exports.getOSInfo = getOSInfo;
/***/ }), /***/ }),

View file

@ -7,7 +7,7 @@ import * as path from 'path';
import os from 'os'; import os from 'os';
import CacheDistributor from './cache-distributor'; import CacheDistributor from './cache-distributor';
import {getLinuxOSReleaseInfo, IS_LINUX, IS_WINDOWS} from '../utils'; import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils';
class PipCache extends CacheDistributor { class PipCache extends CacheDistributor {
constructor( constructor(
@ -61,9 +61,9 @@ class PipCache extends CacheDistributor {
let restoreKey = ''; let restoreKey = '';
if (IS_LINUX) { if (IS_LINUX) {
const osRelease = await getLinuxOSReleaseInfo(); const osInfo = await getLinuxInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`; restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`;
} else { } else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;

View file

@ -1,6 +1,6 @@
import * as os from 'os'; import * as os from 'os';
import * as path from 'path'; 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'; import * as semver from 'semver';
@ -85,9 +85,14 @@ export async function useCpythonVersion(
} }
if (!installDir) { if (!installDir) {
const osInfo = await getOSInfo();
throw new Error( throw new Error(
[ [
`Version ${version} with arch ${architecture} not found`, `The version '${version}' with architecture '${architecture}' was not found for ${
osInfo
? `${osInfo.osName} ${osInfo.osVersion}`
: 'this operating system'
}.`,
`The list of all available versions can be found here: ${installer.MANIFEST_URL}` `The list of all available versions can be found here: ${installer.MANIFEST_URL}`
].join(os.EOL) ].join(os.EOL)
); );

View file

@ -122,23 +122,61 @@ export function isCacheFeatureAvailable(): boolean {
return true; return true;
} }
export async function getLinuxOSReleaseInfo() { export function logWarning(message: string): void {
const {stdout, stderr, exitCode} = await exec.getExecOutput( const warningPrefix = '[warning]';
'lsb_release', core.info(`${warningPrefix}${message}`);
['-i', '-r', '-s'], }
async function getWindowsInfo() {
const {stdout} = await exec.getExecOutput(
'powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"',
undefined,
{ {
silent: true silent: true
} }
); );
const [osRelease, osVersion] = stdout.trim().split('\n'); const windowsVersion = stdout.trim().split(' ')[3];
core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); return {osName: 'Windows', osVersion: windowsVersion};
return `${osVersion}-${osRelease}`;
} }
export function logWarning(message: string): void { async function getMacOSInfo() {
const warningPrefix = '[warning]'; const {stdout} = await exec.getExecOutput('sw_vers', ['-productVersion'], {
core.info(`${warningPrefix}${message}`); silent: true
});
const macOSVersion = stdout.trim();
return {osName: 'macOS', osVersion: macOSVersion};
}
export async function getLinuxInfo() {
const {stdout} = await exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], {
silent: true
});
const [osName, osVersion] = stdout.trim().split('\n');
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
return {osName: osName, osVersion: osVersion};
}
export async function getOSInfo() {
let osInfo;
try {
if (IS_WINDOWS) {
osInfo = await getWindowsInfo();
} else if (IS_LINUX) {
osInfo = await getLinuxInfo();
} else if (IS_MAC) {
osInfo = await getMacOSInfo();
}
} catch (err) {
const error = err as Error;
core.debug(error.message);
} finally {
return osInfo;
}
} }