From 6c87c81bbd983b743d5627c4cdb81f547b2516ef Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Mon, 5 Dec 2022 18:34:56 +0100 Subject: [PATCH 1/9] 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 2ca2fe1b6..3214260a0 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 4e54a94b6..8cb3bdb4a 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 b29c79d69..61594b7c3 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; +} From 7c97a81ef362de63cf3b6d648017c0d1115b505c Mon Sep 17 00:00:00 2001 From: MaksimZhukov <46996400+MaksimZhukov@users.noreply.github.com> Date: Mon, 5 Dec 2022 21:19:40 +0100 Subject: [PATCH 2/9] Improve the error message Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> --- src/find-python.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/find-python.ts b/src/find-python.ts index 8cb3bdb4a..3e033232e 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -88,7 +88,7 @@ export async function useCpythonVersion( const osInfo = await getOSInfo(); throw new Error( [ - `Version ${version} with arch ${architecture} not found for ${osInfo}`, + `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) ); From d9a075e99b5b93247f1b100118a2a6ae15ce216a Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Mon, 5 Dec 2022 21:23:44 +0100 Subject: [PATCH 3/9] Format the code --- src/find-python.ts | 4 +++- src/utils.ts | 22 +++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/find-python.ts b/src/find-python.ts index 3e033232e..5f5069608 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -88,7 +88,9 @@ export async function useCpythonVersion( const osInfo = await getOSInfo(); throw new Error( [ - `The version '${version}' with architecture '${architecture}' was not found for ${osInfo ? osInfo : 'this operating system'}.`, + `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) ); diff --git a/src/utils.ts b/src/utils.ts index 61594b7c3..e500d6316 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -158,13 +158,9 @@ async function getWindowsInfo() { } async function getMacOSInfo() { - const {stdout} = await exec.getExecOutput( - 'sw_vers', - ['-productVersion'], - { - silent: true - } - ); + const {stdout} = await exec.getExecOutput('sw_vers', ['-productVersion'], { + silent: true + }); const macOSVersion = stdout.trim(); @@ -172,13 +168,9 @@ async function getMacOSInfo() { } async function getLinuxInfo() { - const {stdout} = await exec.getExecOutput( - 'lsb_release', - ['-i', '-r', '-s'], - { - silent: true - } - ); + const {stdout} = await exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], { + silent: true + }); const [osName, osVersion] = stdout.trim().split('\n'); @@ -187,7 +179,7 @@ async function getLinuxInfo() { export async function getOSInfo() { let osInfo; - if (IS_WINDOWS){ + if (IS_WINDOWS) { osInfo = await getWindowsInfo(); } else if (IS_LINUX) { osInfo = await getLinuxInfo(); From 1d95b404f29d0d8392fc45892c17fd211482429a Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Tue, 6 Dec 2022 10:23:32 +0100 Subject: [PATCH 4/9] Regenerate the dist folder --- dist/setup/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 3214260a0..a022c17bc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66379,7 +66379,7 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest if (!installDir) { const osInfo = yield utils_1.getOSInfo(); throw new Error([ - `Version ${version} with arch ${architecture} not found for ${osInfo}`, + `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)); } From d4d6125cf2e5750c715c4655dbddf35b2db6fa2b Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Tue, 6 Dec 2022 17:07:51 +0100 Subject: [PATCH 5/9] Add try catch --- dist/setup/index.js | 22 +++++++++++++++------- src/utils.ts | 21 +++++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index a022c17bc..7d58fa846 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -67089,16 +67089,24 @@ function getLinuxInfo() { function getOSInfo() { return __awaiter(this, void 0, void 0, function* () { let osInfo; - if (exports.IS_WINDOWS) { - osInfo = yield getWindowsInfo(); + try { + if (exports.IS_WINDOWS) { + osInfo = yield getWindowsInfo(); + } + else if (exports.IS_LINUX) { + osInfo = yield getLinuxInfo(); + } + else if (exports.IS_MAC) { + osInfo = yield getMacOSInfo(); + } } - else if (exports.IS_LINUX) { - osInfo = yield getLinuxInfo(); + catch (err) { + const error = err; + core.debug(error.message); } - else if (exports.IS_MAC) { - osInfo = yield getMacOSInfo(); + finally { + return osInfo; } - return osInfo; }); } exports.getOSInfo = getOSInfo; diff --git a/src/utils.ts b/src/utils.ts index e500d6316..e52309049 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -179,13 +179,18 @@ async function getLinuxInfo() { 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(); + 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; } - - return osInfo; } From c09af9d29fb89760fb665a3b24f35d5348e23db6 Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Wed, 7 Dec 2022 12:39:31 +0100 Subject: [PATCH 6/9] Get rid of the duplicate --- dist/setup/index.js | 29 ++++++++++------------------ src/cache-distributions/pip-cache.ts | 8 ++++---- src/find-python.ts | 4 +++- src/utils.ts | 26 ++++++------------------- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 7d58fa846..a648f701d 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}`; @@ -66379,7 +66379,7 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest if (!installDir) { const osInfo = yield utils_1.getOSInfo(); throw new Error([ - `The version '${version}' with architecture '${architecture}' was not found for ${osInfo ? osInfo : 'this operating system'}.`, + `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)); } @@ -66952,7 +66952,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -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; +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)); @@ -67043,17 +67043,6 @@ function isCacheFeatureAvailable() { return true; } 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) { const warningPrefix = '[warning]'; core.info(`${warningPrefix}${message}`); @@ -67065,7 +67054,7 @@ function getWindowsInfo() { silent: true }); const windowsVersion = stdout.trim().split(' ')[3]; - return `Windows ${windowsVersion}`; + return { osName: "Windows", osVersion: windowsVersion }; }); } function getMacOSInfo() { @@ -67074,7 +67063,7 @@ function getMacOSInfo() { silent: true }); const macOSVersion = stdout.trim(); - return `macOS ${macOSVersion}`; + return { osName: "macOS", osVersion: macOSVersion }; }); } function getLinuxInfo() { @@ -67083,9 +67072,11 @@ function getLinuxInfo() { silent: true }); const [osName, osVersion] = stdout.trim().split('\n'); - return `${osName} ${osVersion}`; + 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; 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 5f5069608..c156d2abc 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -89,7 +89,9 @@ export async function useCpythonVersion( throw new Error( [ `The version '${version}' with architecture '${architecture}' was not found for ${ - osInfo ? osInfo : 'this operating system' + 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 e52309049..37059cb66 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -122,22 +122,6 @@ export function isCacheFeatureAvailable(): boolean { return true; } -export async function getLinuxOSReleaseInfo() { - const {stdout, stderr, exitCode} = await 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}`; -} - export function logWarning(message: string): void { const warningPrefix = '[warning]'; core.info(`${warningPrefix}${message}`); @@ -154,7 +138,7 @@ async function getWindowsInfo() { const windowsVersion = stdout.trim().split(' ')[3]; - return `Windows ${windowsVersion}`; + return {osName: 'Windows', osVersion: windowsVersion}; } async function getMacOSInfo() { @@ -164,17 +148,19 @@ async function getMacOSInfo() { const macOSVersion = stdout.trim(); - return `macOS ${macOSVersion}`; + return {osName: 'macOS', osVersion: macOSVersion}; } -async function getLinuxInfo() { +export 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}`; + core.debug(`OS Name: ${osName}, Version: ${osVersion}`); + + return {osName: osName, osVersion: osVersion}; } export async function getOSInfo() { From a8c419bcabc0e77f3ea5b83fffdff6166ce03d53 Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Wed, 7 Dec 2022 12:43:13 +0100 Subject: [PATCH 7/9] Regenerate the dist folder --- dist/setup/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index a648f701d..7ad82803f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66379,7 +66379,9 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest if (!installDir) { const osInfo = yield utils_1.getOSInfo(); throw new Error([ - `The version '${version}' with architecture '${architecture}' was not found for ${osInfo ? `${osInfo.osName} ${osInfo.osVersion}` : 'this operating system'}.`, + `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)); } @@ -67054,7 +67056,7 @@ function getWindowsInfo() { silent: true }); const windowsVersion = stdout.trim().split(' ')[3]; - return { osName: "Windows", osVersion: windowsVersion }; + return { osName: 'Windows', osVersion: windowsVersion }; }); } function getMacOSInfo() { @@ -67063,7 +67065,7 @@ function getMacOSInfo() { silent: true }); const macOSVersion = stdout.trim(); - return { osName: "macOS", osVersion: macOSVersion }; + return { osName: 'macOS', osVersion: macOSVersion }; }); } function getLinuxInfo() { From 3d2a56a768c4752ca1c0f953e6622e7604345218 Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Wed, 7 Dec 2022 12:55:04 +0100 Subject: [PATCH 8/9] Update tests --- __tests__/cache-restore.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 8331b8124..7ec2595b9 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -30,7 +30,7 @@ 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; + let getLinuxInfoSpy: jest.SpyInstance; // cache spy let restoreCacheSpy: jest.SpyInstance; @@ -83,7 +83,7 @@ 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'); + getLinuxInfoSpy = jest.spyOn(utils, 'getLinuxInfo'); }); describe('Validate provided package manager', () => { @@ -121,8 +121,8 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py ); if (process.platform === 'linux') { - getLinuxOSReleaseInfoSpy.mockImplementation(() => - Promise.resolve('Ubuntu-20.4') + getLinuxInfoSpy.mockImplementation(() => + Promise.resolve({osName: 'Ubuntu', osVersion: '20.04'}) ); } @@ -130,7 +130,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py 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']}-Ubuntu-20.04-python-${pythonVersion}-${packageManager}-${fileHash}` ); } else { expect(infoSpy).toHaveBeenCalledWith( From d9928f85a748d3f402241f233e442b35b148e953 Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Wed, 7 Dec 2022 17:54:24 +0100 Subject: [PATCH 9/9] Fix tests --- __tests__/cache-restore.test.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 7ec2595b9..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 getLinuxInfoSpy: 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'); - getLinuxInfoSpy = jest.spyOn(utils, 'getLinuxInfo'); }); describe('Validate provided package manager', () => { @@ -120,17 +121,11 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - if (process.platform === 'linux') { - getLinuxInfoSpy.mockImplementation(() => - Promise.resolve({osName: 'Ubuntu', osVersion: '20.04'}) - ); - } - await cacheDistributor.restoreCache(); if (process.platform === 'linux' && packageManager === 'pip') { expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.04-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(