diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 8331b8124..81caabad0 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -30,7 +30,6 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py let saveSatetSpy: jest.SpyInstance; let getStateSpy: jest.SpyInstance; let setOutputSpy: jest.SpyInstance; - let getLinuxOSReleaseInfoSpy: jest.SpyInstance; // cache spy let restoreCacheSpy: jest.SpyInstance; @@ -67,6 +66,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py if (input.includes('poetry')) { 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}; }); @@ -83,7 +85,6 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py whichSpy = jest.spyOn(io, 'which'); whichSpy.mockImplementation(() => '/path/to/python'); - getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo'); }); describe('Validate provided package manager', () => { @@ -120,17 +121,11 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - if (process.platform === 'linux') { - getLinuxOSReleaseInfoSpy.mockImplementation(() => - Promise.resolve('Ubuntu-20.4') - ); - } - await cacheDistributor.restoreCache(); if (process.platform === 'linux' && packageManager === 'pip') { 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 { expect(infoSpy).toHaveBeenCalledWith( diff --git a/dist/setup/index.js b/dist/setup/index.js index 2ca2fe1b6..7ad82803f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65919,9 +65919,9 @@ class PipCache extends cache_distributor_1.default { let primaryKey = ''; let restoreKey = ''; if (utils_1.IS_LINUX) { - const osRelease = yield utils_1.getLinuxOSReleaseInfo(); - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`; + const osInfo = yield utils_1.getLinuxInfo(); + 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']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; } else { primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; @@ -66377,8 +66377,11 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest } } if (!installDir) { + const osInfo = yield utils_1.getOSInfo(); 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}` ].join(os.EOL)); } @@ -66951,7 +66954,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.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 core = __importStar(__nccwpck_require__(2186)); const fs_1 = __importDefault(__nccwpck_require__(7147)); @@ -67042,22 +67045,64 @@ function isCacheFeatureAvailable() { return true; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; -function getLinuxOSReleaseInfo() { +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +function getWindowsInfo() { return __awaiter(this, void 0, void 0, function* () { - const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], { + const { stdout } = yield exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', undefined, { silent: true }); - const [osRelease, osVersion] = stdout.trim().split('\n'); - core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); - return `${osVersion}-${osRelease}`; + const windowsVersion = stdout.trim().split(' ')[3]; + return { osName: 'Windows', osVersion: windowsVersion }; }); } -exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo; -function logWarning(message) { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${message}`); +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 }; + }); } -exports.logWarning = logWarning; +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; /***/ }), diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 460b097c8..25b29c662 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import os from 'os'; 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 { constructor( @@ -61,9 +61,9 @@ class PipCache extends CacheDistributor { let restoreKey = ''; if (IS_LINUX) { - const osRelease = await getLinuxOSReleaseInfo(); - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`; + const osInfo = await getLinuxInfo(); + 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']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; } else { 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}`; diff --git a/src/find-python.ts b/src/find-python.ts index 4e54a94b6..c156d2abc 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,14 @@ 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.osName} ${osInfo.osVersion}` + : 'this operating system' + }.`, `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 b29c79d69..37059cb66 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -122,23 +122,61 @@ export function isCacheFeatureAvailable(): boolean { return true; } -export async function getLinuxOSReleaseInfo() { - const {stdout, stderr, exitCode} = await exec.getExecOutput( - 'lsb_release', - ['-i', '-r', '-s'], +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 [osRelease, osVersion] = stdout.trim().split('\n'); + const windowsVersion = stdout.trim().split(' ')[3]; - core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); + return {osName: 'Windows', osVersion: windowsVersion}; +} + +async function getMacOSInfo() { + const {stdout} = await exec.getExecOutput('sw_vers', ['-productVersion'], { + silent: true + }); - return `${osVersion}-${osRelease}`; + const macOSVersion = stdout.trim(); + + return {osName: 'macOS', osVersion: macOSVersion}; } -export function logWarning(message: string): void { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${message}`); +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; + } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: