From 655506db870a14ee64a9207a20f386bd142e5cf1 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 15 Jul 2022 11:27:28 +0200 Subject: [PATCH 01/18] Add Linux version and release to primary key --- dist/setup/index.js | 66 ++++++++++++++++++++++--- src/cache-distributions/pip-cache.ts | 15 ++++-- src/cache-distributions/pipenv-cache.ts | 13 ++++- src/cache-distributions/poetry-cache.ts | 15 +++++- src/utils.ts | 16 ++++++ 5 files changed, 111 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 9ac89a4fd..0c8b1c87e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64430,8 +64430,17 @@ class PipCache extends cache_distributor_1.default { computeKeys() { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(this.cacheDependencyPath); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; + 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}`; + } + 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}`; + } return { primaryKey, restoreKey: [restoreKey] @@ -64486,6 +64495,7 @@ const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); const core = __importStar(__nccwpck_require__(2186)); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); +const utils_1 = __nccwpck_require__(1314); class PipenvCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/Pipfile.lock') { super('pipenv', patterns); @@ -64511,9 +64521,16 @@ class PipenvCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = yield glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const hash = yield glob.hashFiles(this.cacheDependencyPath); + let primaryKey = ''; const restoreKey = undefined; + 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}`; + } + else { + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } return { primaryKey, restoreKey @@ -64567,6 +64584,7 @@ const glob = __importStar(__nccwpck_require__(8090)); const path = __importStar(__nccwpck_require__(1017)); const exec = __importStar(__nccwpck_require__(1514)); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); +const utils_1 = __nccwpck_require__(1314); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { super('poetry', patterns); @@ -64587,8 +64605,15 @@ class PoetryCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = yield glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const hash = yield glob.hashFiles(this.cacheDependencyPath); + let primaryKey = ''; + 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}`; + } + else { + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } const restoreKey = undefined; return { primaryKey, @@ -65354,16 +65379,26 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -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_LINUX = exports.IS_WINDOWS = void 0; +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_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)); const path = __importStar(__nccwpck_require__(1017)); const semver = __importStar(__nccwpck_require__(1383)); +const exec = __importStar(__nccwpck_require__(1514)); exports.IS_WINDOWS = process.platform === 'win32'; exports.IS_LINUX = process.platform === 'linux'; exports.WINDOWS_ARCHS = ['x86', 'x64']; @@ -65447,6 +65482,23 @@ function isCacheFeatureAvailable() { return true; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; +function getLinuxOSReleaseInfo() { + return __awaiter(this, void 0, void 0, function* () { + const versionId = yield exec.getExecOutput('lsb_release', ['-a']); + let osVersion = ''; + let osRelease = ''; + versionId.stdout.split('\n').forEach(elem => { + if (elem.includes('Distributor')) + osVersion = elem.split(':')[1].trim(); + if (elem.includes('Release')) + osRelease = elem.split(':')[1].trim(); + }); + core.info(osRelease); + core.info(osVersion); + return `${osVersion}-${osRelease}`; + }); +} +exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo; /***/ }), diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 17055ea5a..460b097c8 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 {IS_WINDOWS} from '../utils'; +import {getLinuxOSReleaseInfo, IS_LINUX, IS_WINDOWS} from '../utils'; class PipCache extends CacheDistributor { constructor( @@ -57,8 +57,17 @@ class PipCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.cacheDependencyPath); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; + let primaryKey = ''; + 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}`; + } 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}`; + } return { primaryKey, diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index fd1994a68..4602b786f 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -4,6 +4,7 @@ import * as path from 'path'; import * as core from '@actions/core'; import CacheDistributor from './cache-distributor'; +import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; class PipenvCache extends CacheDistributor { constructor( @@ -31,9 +32,17 @@ class PipenvCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const hash = await glob.hashFiles(this.cacheDependencyPath); + let primaryKey = ''; const restoreKey = undefined; + + if (IS_LINUX) { + const osRelease = await getLinuxOSReleaseInfo(); + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } else { + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } + return { primaryKey, restoreKey diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 5e22b5dd7..9113d39fa 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -4,6 +4,7 @@ import * as path from 'path'; import * as exec from '@actions/exec'; import CacheDistributor from './cache-distributor'; +import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; class PoetryCache extends CacheDistributor { constructor( @@ -32,9 +33,19 @@ class PoetryCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const hash = await glob.hashFiles(this.cacheDependencyPath); + + let primaryKey = ''; + + if (IS_LINUX) { + const osRelease = await getLinuxOSReleaseInfo(); + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } else { + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + } + const restoreKey = undefined; + return { primaryKey, restoreKey diff --git a/src/utils.ts b/src/utils.ts index eb3a1ba68..46cf677c8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import * as core from '@actions/core'; import fs from 'fs'; import * as path from 'path'; import * as semver from 'semver'; +import * as exec from '@actions/exec'; export const IS_WINDOWS = process.platform === 'win32'; export const IS_LINUX = process.platform === 'linux'; @@ -119,3 +120,18 @@ export function isCacheFeatureAvailable(): boolean { return true; } + +export async function getLinuxOSReleaseInfo() { + const versionId = await exec.getExecOutput('lsb_release', ['-a']); + let osVersion = ''; + let osRelease = ''; + + versionId.stdout.split('\n').forEach(elem => { + if (elem.includes('Distributor')) osVersion = elem.split(':')[1].trim(); + if (elem.includes('Release')) osRelease = elem.split(':')[1].trim(); + }); + + core.info(osRelease); + core.info(osVersion); + return `${osVersion}-${osRelease}`; +} From 2dd90ca26f801dca56b6df8d5ab369bfc77e0d88 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 12:24:47 +0200 Subject: [PATCH 02/18] Add silent exec output --- dist/setup/index.js | 4 +++- src/utils.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0c8b1c87e..4f8f5cf51 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65484,7 +65484,9 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getLinuxOSReleaseInfo() { return __awaiter(this, void 0, void 0, function* () { - const versionId = yield exec.getExecOutput('lsb_release', ['-a']); + const versionId = yield exec.getExecOutput('lsb_release', ['-a'], { + silent: true + }); let osVersion = ''; let osRelease = ''; versionId.stdout.split('\n').forEach(elem => { diff --git a/src/utils.ts b/src/utils.ts index 46cf677c8..cf77e41ff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -122,7 +122,9 @@ export function isCacheFeatureAvailable(): boolean { } export async function getLinuxOSReleaseInfo() { - const versionId = await exec.getExecOutput('lsb_release', ['-a']); + const versionId = await exec.getExecOutput('lsb_release', ['-a'], { + silent: true + }); let osVersion = ''; let osRelease = ''; From e6b5cf91d50bebdd69659114c8bfa999d31f8e54 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 12:31:20 +0200 Subject: [PATCH 03/18] Amend unit tests --- __tests__/cache-restore.test.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 573f36a93..f27be5fec 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; import * as exec from '@actions/exec'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; +import * as utils from './../src/utils'; describe('restore-cache', () => { const pipFileLockHash = @@ -27,6 +28,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py let debugSpy: jest.SpyInstance; let saveSatetSpy: jest.SpyInstance; let getStateSpy: jest.SpyInstance; + let computeKeysSpy: jest.SpyInstance; let setOutputSpy: jest.SpyInstance; // cache spy @@ -74,6 +76,8 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py return primaryKey; } ); + + computeKeysSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo'); }); describe('Validate provided package manager', () => { @@ -109,11 +113,21 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py pythonVersion, dependencyFile ); + + if (process.env['RUNNER_OS'] === 'linux') { + computeKeysSpy.mockImplementation(() => 'Ubuntu-20.4'); + } await cacheDistributor.restoreCache(); - expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` - ); + if (process.env['RUNNER_OS'] === 'linux') { + expect(infoSpy).toHaveBeenCalledWith( + `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` + ); + } else { + expect(infoSpy).toHaveBeenCalledWith( + `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` + ); + } }, 30000 ); From 9c76d7346319646c95887fcacbcb06567ce4e048 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 12:54:17 +0200 Subject: [PATCH 04/18] Amend unit tests --- __tests__/cache-restore.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index f27be5fec..d1c269671 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -115,8 +115,15 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py ); if (process.env['RUNNER_OS'] === 'linux') { + Object.defineProperty(utils, 'IS_LINUX', { + value: () => { + jest.fn().mockReturnValue(true); + } + }); + computeKeysSpy.mockImplementation(() => 'Ubuntu-20.4'); } + await cacheDistributor.restoreCache(); if (process.env['RUNNER_OS'] === 'linux') { From 6d85af87cc05760d72511ffb5b42f2a5a0dde2ba Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 13:06:54 +0200 Subject: [PATCH 05/18] Mock resolved value test --- __tests__/cache-restore.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index d1c269671..cb37cc934 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -121,7 +121,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py } }); - computeKeysSpy.mockImplementation(() => 'Ubuntu-20.4'); + computeKeysSpy.mockResolvedValue('Ubuntu-20.4'); } await cacheDistributor.restoreCache(); From 3aec06c05e85cb811b9187d0f511f41deb8b2f03 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 13:26:51 +0200 Subject: [PATCH 06/18] Mock resolved value test --- __tests__/cache-restore.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index cb37cc934..7fe60cca2 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -121,7 +121,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py } }); - computeKeysSpy.mockResolvedValue('Ubuntu-20.4'); + computeKeysSpy.mockImplementation(() => + Promise.resolve('Ubuntu-20.4') + ); } await cacheDistributor.restoreCache(); From bdfd06e9517ca7cf665b827e3eb1813f4545c4d7 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 15:13:38 +0200 Subject: [PATCH 07/18] Mock always getLinuxOS --- __tests__/cache-restore.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 7fe60cca2..3df608723 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,16 +114,14 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); + computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4')); + if (process.env['RUNNER_OS'] === 'linux') { Object.defineProperty(utils, 'IS_LINUX', { value: () => { jest.fn().mockReturnValue(true); } }); - - computeKeysSpy.mockImplementation(() => - Promise.resolve('Ubuntu-20.4') - ); } await cacheDistributor.restoreCache(); From 2f31a3b56eeeb3b82ae82fdf7568ea98ce8e35ad Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 15:31:36 +0200 Subject: [PATCH 08/18] Restore mocked value for non linux --- __tests__/cache-restore.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 3df608723..56afa5131 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -122,6 +122,12 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py jest.fn().mockReturnValue(true); } }); + } else { + Object.defineProperty(utils, 'IS_LINUX', { + value: () => { + jest.fn().mockReturnValue(false); + } + }); } await cacheDistributor.restoreCache(); From 116ddb08f568d64e4a6a91b2d5958674df4b7c12 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 15:50:22 +0200 Subject: [PATCH 09/18] Fix string compare --- __tests__/cache-restore.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 56afa5131..b2c5e6b68 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -116,7 +116,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4')); - if (process.env['RUNNER_OS'] === 'linux') { + if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { Object.defineProperty(utils, 'IS_LINUX', { value: () => { jest.fn().mockReturnValue(true); @@ -132,7 +132,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py await cacheDistributor.restoreCache(); - if (process.env['RUNNER_OS'] === 'linux') { + if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { expect(infoSpy).toHaveBeenCalledWith( `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` ); From a743c858bf7a81abafe441a3981da2a80d465896 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:00:00 +0200 Subject: [PATCH 10/18] Hide mock implementation --- __tests__/cache-restore.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index b2c5e6b68..79e04761b 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,18 +114,17 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4')); - if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { + computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4')); Object.defineProperty(utils, 'IS_LINUX', { value: () => { - jest.fn().mockReturnValue(true); + jest.fn().mockImplementation(() => true); } }); } else { Object.defineProperty(utils, 'IS_LINUX', { value: () => { - jest.fn().mockReturnValue(false); + jest.fn().mockReturnValue(() => false); } }); } From f882236246dbb97c35a7da20f8bf60b396585856 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:02:18 +0200 Subject: [PATCH 11/18] Run lint --- __tests__/cache-restore.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 79e04761b..6adf67a6d 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -115,7 +115,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py ); if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { - computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4')); + computeKeysSpy.mockImplementation(() => + Promise.resolve('Ubuntu-20.4') + ); Object.defineProperty(utils, 'IS_LINUX', { value: () => { jest.fn().mockImplementation(() => true); From 919049990a953f726e11d02f9152e18c0e4cbb06 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:43:28 +0200 Subject: [PATCH 12/18] Run lint --- __tests__/cache-restore.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 6adf67a6d..27225e3fb 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,7 +114,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { + if (process.platform.toLowerCase() === 'linux') { computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4') ); @@ -133,7 +133,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py await cacheDistributor.restoreCache(); - if (process.env['RUNNER_OS']?.toLowerCase() === 'linux') { + if (process.platform.toLowerCase() === 'linux') { expect(infoSpy).toHaveBeenCalledWith( `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` ); From aa5ed886ce9fa72e34a6cc08740c8486c405a489 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:49:43 +0200 Subject: [PATCH 13/18] Run lint --- __tests__/cache-restore.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 27225e3fb..b1bc2bda9 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -118,15 +118,15 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4') ); - Object.defineProperty(utils, 'IS_LINUX', { + Object.defineProperty(process, 'platform', { value: () => { - jest.fn().mockImplementation(() => true); + jest.fn().mockImplementation(() => 'linux'); } }); } else { - Object.defineProperty(utils, 'IS_LINUX', { + Object.defineProperty(process, 'platform', { value: () => { - jest.fn().mockReturnValue(() => false); + jest.fn().mockReturnValue(() => 'win32'); } }); } From faa1abdf2c4bf541557e98e3147d594f8b75d65b Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:51:52 +0200 Subject: [PATCH 14/18] Run lint --- __tests__/cache-restore.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index b1bc2bda9..54b1164c7 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,7 +114,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - if (process.platform.toLowerCase() === 'linux') { + if (process.platform === 'linux') { computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4') ); @@ -133,7 +133,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py await cacheDistributor.restoreCache(); - if (process.platform.toLowerCase() === 'linux') { + if (process.platform === 'linux') { expect(infoSpy).toHaveBeenCalledWith( `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` ); From b4c99b3e576c58ef915af4dd054c9cd71d9e71ae Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:54:35 +0200 Subject: [PATCH 15/18] Run lint --- __tests__/cache-restore.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 54b1164c7..1a7a1ef67 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,19 +114,21 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); + console.log(process.platform, "PLATFORM"); + if (process.platform === 'linux') { computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4') ); - Object.defineProperty(process, 'platform', { + Object.defineProperty(utils, 'IS_LINUX', { value: () => { - jest.fn().mockImplementation(() => 'linux'); + jest.fn().mockImplementation(() => true); } }); } else { - Object.defineProperty(process, 'platform', { + Object.defineProperty(utils, 'IS_LINUX', { value: () => { - jest.fn().mockReturnValue(() => 'win32'); + jest.fn().mockReturnValue(() => false); } }); } From 5c8c8fa205dc0b5b3dd90ae26a78070e672e3c3f Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 16:56:06 +0200 Subject: [PATCH 16/18] Run lint --- __tests__/cache-restore.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 1a7a1ef67..07e89c8f7 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,7 +114,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py dependencyFile ); - console.log(process.platform, "PLATFORM"); + console.log(process.platform, 'PLATFORM'); if (process.platform === 'linux') { computeKeysSpy.mockImplementation(() => From a7a979162e10369e0f01aa3949080b71d36b6950 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 17:03:21 +0200 Subject: [PATCH 17/18] Run lint --- dist/setup/index.js | 3 +++ src/cache-distributions/pip-cache.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4f8f5cf51..9deac897f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64432,12 +64432,15 @@ class PipCache extends cache_distributor_1.default { const hash = yield glob.hashFiles(this.cacheDependencyPath); let primaryKey = ''; let restoreKey = ''; + console.log(process.platform, 'This is current platform'); if (utils_1.IS_LINUX) { + console.log('here'); 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}`; } else { + console.log('here2'); 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/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 460b097c8..26113fc81 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -60,11 +60,14 @@ class PipCache extends CacheDistributor { let primaryKey = ''; let restoreKey = ''; + console.log(process.platform, 'This is current platform'); if (IS_LINUX) { + console.log('here'); 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}`; } else { + console.log('here2'); 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}`; } From d262e92ea1168a53ac4beb24b3729101a13952f7 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 17:06:38 +0200 Subject: [PATCH 18/18] Run lint --- __tests__/cache-restore.test.ts | 11 ----------- dist/setup/index.js | 2 ++ src/cache-distributions/pip-cache.ts | 2 ++ 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 07e89c8f7..62f773d8b 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -120,17 +120,6 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py computeKeysSpy.mockImplementation(() => Promise.resolve('Ubuntu-20.4') ); - Object.defineProperty(utils, 'IS_LINUX', { - value: () => { - jest.fn().mockImplementation(() => true); - } - }); - } else { - Object.defineProperty(utils, 'IS_LINUX', { - value: () => { - jest.fn().mockReturnValue(() => false); - } - }); } await cacheDistributor.restoreCache(); diff --git a/dist/setup/index.js b/dist/setup/index.js index 9deac897f..8d20a8122 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64433,6 +64433,8 @@ class PipCache extends cache_distributor_1.default { let primaryKey = ''; let restoreKey = ''; console.log(process.platform, 'This is current platform'); + console.log(utils_1.IS_LINUX, 'IS LINUX'); + console.log(utils_1.IS_WINDOWS, 'IS WINDOWS'); if (utils_1.IS_LINUX) { console.log('here'); const osRelease = yield utils_1.getLinuxOSReleaseInfo(); diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 26113fc81..41db936f3 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -61,6 +61,8 @@ class PipCache extends CacheDistributor { let restoreKey = ''; console.log(process.platform, 'This is current platform'); + console.log(IS_LINUX, 'IS LINUX'); + console.log(IS_WINDOWS, 'IS WINDOWS'); if (IS_LINUX) { console.log('here'); const osRelease = await getLinuxOSReleaseInfo();