From f22ce506754ffc7c33c3cf8a96a5d74202c9154c Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 17:16:35 +0200 Subject: [PATCH 1/7] Add linux os release info to primary key --- __tests__/cache-restore.test.ts | 23 ++++++-- dist/setup/index.js | 70 ++++++++++++++++++++++--- src/cache-distributions/pip-cache.ts | 17 ++++-- src/cache-distributions/pipenv-cache.ts | 13 ++++- src/cache-distributions/poetry-cache.ts | 14 +++-- src/utils.ts | 18 +++++++ 6 files changed, 137 insertions(+), 18 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 573f36a93..e591ef1f3 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 = @@ -28,6 +29,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; // cache spy let restoreCacheSpy: jest.SpyInstance; @@ -74,6 +76,8 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py return primaryKey; } ); + + getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo'); }); describe('Validate provided package manager', () => { @@ -109,11 +113,24 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py pythonVersion, dependencyFile ); + + if (process.platform === 'linux') { + getLinuxOSReleaseInfoSpy.mockImplementation(() => + Promise.resolve('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.platform === '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 ); diff --git a/dist/setup/index.js b/dist/setup/index.js index 9ac89a4fd..444c3ad43 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64430,8 +64430,19 @@ 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) { + 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}`; + } return { primaryKey, restoreKey: [restoreKey] @@ -64485,6 +64496,7 @@ const glob = __importStar(__nccwpck_require__(8090)); const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); const core = __importStar(__nccwpck_require__(2186)); +const utils_1 = __nccwpck_require__(1314); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); class PipenvCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/Pipfile.lock') { @@ -64511,9 +64523,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 @@ -64566,6 +64585,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const glob = __importStar(__nccwpck_require__(8090)); const path = __importStar(__nccwpck_require__(1017)); const exec = __importStar(__nccwpck_require__(1514)); +const utils_1 = __nccwpck_require__(1314); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { @@ -64587,9 +64607,16 @@ 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 = ''; 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 @@ -65354,16 +65381,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 +65484,25 @@ 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'], { + silent: true + }); + 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..11ff3e496 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,19 @@ 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) { + 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}`; + } return { primaryKey, diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index fd1994a68..f8549fecf 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -2,6 +2,7 @@ import * as glob from '@actions/glob'; import * as os from 'os'; import * as path from 'path'; import * as core from '@actions/core'; +import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; import CacheDistributor from './cache-distributor'; @@ -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..d2453a9f2 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -1,7 +1,7 @@ import * as glob from '@actions/glob'; -import * as os from 'os'; import * as path from 'path'; import * as exec from '@actions/exec'; +import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; import CacheDistributor from './cache-distributor'; @@ -32,9 +32,17 @@ 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 = ''; 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/utils.ts b/src/utils.ts index eb3a1ba68..cf77e41ff 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,20 @@ export function isCacheFeatureAvailable(): boolean { return true; } + +export async function getLinuxOSReleaseInfo() { + const versionId = await exec.getExecOutput('lsb_release', ['-a'], { + silent: true + }); + 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 6e46140c9c36e79b1d020f4d50a3b42dd17cfcf6 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 18:16:11 +0200 Subject: [PATCH 2/7] Remove console logs and debug version --- dist/setup/index.js | 9 +++------ src/cache-distributions/pip-cache.ts | 2 -- src/utils.ts | 17 +++++++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 444c3ad43..e5fe26e0b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64433,13 +64433,11 @@ class PipCache extends cache_distributor_1.default { let primaryKey = ''; let restoreKey = ''; 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}`; } @@ -65486,19 +65484,18 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getLinuxOSReleaseInfo() { return __awaiter(this, void 0, void 0, function* () { - const versionId = yield exec.getExecOutput('lsb_release', ['-a'], { + const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-a'], { silent: true }); let osVersion = ''; let osRelease = ''; - versionId.stdout.split('\n').forEach(elem => { + 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); + core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); return `${osVersion}-${osRelease}`; }); } diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 11ff3e496..460b097c8 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -61,12 +61,10 @@ class PipCache extends CacheDistributor { let restoreKey = ''; 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}`; } diff --git a/src/utils.ts b/src/utils.ts index cf77e41ff..085774e6b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -122,18 +122,23 @@ export function isCacheFeatureAvailable(): boolean { } export async function getLinuxOSReleaseInfo() { - const versionId = await exec.getExecOutput('lsb_release', ['-a'], { - silent: true - }); + const {stdout, stderr, exitCode} = await exec.getExecOutput( + 'lsb_release', + ['-a'], + { + silent: true + } + ); + let osVersion = ''; let osRelease = ''; - versionId.stdout.split('\n').forEach(elem => { + 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); + core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); + return `${osVersion}-${osRelease}`; } From 96d176662db3dffd1dc67432f83a6e7253c5f6b1 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 18:24:59 +0200 Subject: [PATCH 3/7] Update exec command, remove mock from unit tests --- __tests__/cache-restore.test.ts | 6 ------ dist/setup/index.js | 11 ++--------- src/utils.ts | 10 ++-------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index e591ef1f3..149726ae5 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,12 +114,6 @@ 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') { diff --git a/dist/setup/index.js b/dist/setup/index.js index e5fe26e0b..5c3ab6df5 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65484,17 +65484,10 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getLinuxOSReleaseInfo() { return __awaiter(this, void 0, void 0, function* () { - const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-a'], { + const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-i -r -s'], { silent: true }); - let osVersion = ''; - let osRelease = ''; - stdout.split('\n').forEach(elem => { - if (elem.includes('Distributor')) - osVersion = elem.split(':')[1].trim(); - if (elem.includes('Release')) - osRelease = elem.split(':')[1].trim(); - }); + const [osRelease, osVersion] = stdout.trim().split('\n'); core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); return `${osVersion}-${osRelease}`; }); diff --git a/src/utils.ts b/src/utils.ts index 085774e6b..e5374e903 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -124,19 +124,13 @@ export function isCacheFeatureAvailable(): boolean { export async function getLinuxOSReleaseInfo() { const {stdout, stderr, exitCode} = await exec.getExecOutput( 'lsb_release', - ['-a'], + ['-i -r -s'], { silent: true } ); - let osVersion = ''; - let osRelease = ''; - - stdout.split('\n').forEach(elem => { - if (elem.includes('Distributor')) osVersion = elem.split(':')[1].trim(); - if (elem.includes('Release')) osRelease = elem.split(':')[1].trim(); - }); + const [osRelease, osVersion] = stdout.trim().split('\n'); core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`); From e53798f2d2d99c9f602bc5fea2edf5e7dfcf308b Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 18:29:43 +0200 Subject: [PATCH 4/7] Send args as array --- dist/setup/index.js | 2 +- src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 5c3ab6df5..315259e31 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65484,7 +65484,7 @@ function 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'], { + const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], { silent: true }); const [osRelease, osVersion] = stdout.trim().split('\n'); diff --git a/src/utils.ts b/src/utils.ts index e5374e903..6eb1388fe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -124,7 +124,7 @@ export function isCacheFeatureAvailable(): boolean { export async function getLinuxOSReleaseInfo() { const {stdout, stderr, exitCode} = await exec.getExecOutput( 'lsb_release', - ['-i -r -s'], + ['-i', '-r', '-s'], { silent: true } From f8a2339550051524b28dbff56911557de59441b1 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 18 Jul 2022 18:33:30 +0200 Subject: [PATCH 5/7] Revert restore deps test --- __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 149726ae5..e591ef1f3 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -114,6 +114,12 @@ 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') { From a0c296a502581a456e5cc0075e810e72034ef50d Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 19 Jul 2022 13:05:37 +0200 Subject: [PATCH 6/7] Revert poetry and pipenv changes --- dist/setup/index.js | 24 ++++-------------------- src/cache-distributions/pipenv-cache.ts | 13 ++----------- src/cache-distributions/poetry-cache.ts | 14 +++----------- 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 315259e31..e98596d10 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64494,7 +64494,6 @@ const glob = __importStar(__nccwpck_require__(8090)); const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); const core = __importStar(__nccwpck_require__(2186)); -const utils_1 = __nccwpck_require__(1314); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); class PipenvCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/Pipfile.lock') { @@ -64521,16 +64520,9 @@ class PipenvCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = yield glob.hashFiles(this.cacheDependencyPath); - let primaryKey = ''; + const hash = yield glob.hashFiles(this.patterns); + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; 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 @@ -64583,7 +64575,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const glob = __importStar(__nccwpck_require__(8090)); const path = __importStar(__nccwpck_require__(1017)); const exec = __importStar(__nccwpck_require__(1514)); -const utils_1 = __nccwpck_require__(1314); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { @@ -64605,16 +64596,9 @@ class PoetryCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = yield glob.hashFiles(this.cacheDependencyPath); - let primaryKey = ''; + const hash = yield glob.hashFiles(this.patterns); + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; 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 diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index f8549fecf..fd1994a68 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -2,7 +2,6 @@ import * as glob from '@actions/glob'; import * as os from 'os'; import * as path from 'path'; import * as core from '@actions/core'; -import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; import CacheDistributor from './cache-distributor'; @@ -32,17 +31,9 @@ class PipenvCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.cacheDependencyPath); - let primaryKey = ''; + const hash = await glob.hashFiles(this.patterns); + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; 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 d2453a9f2..5e22b5dd7 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -1,7 +1,7 @@ import * as glob from '@actions/glob'; +import * as os from 'os'; import * as path from 'path'; import * as exec from '@actions/exec'; -import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils'; import CacheDistributor from './cache-distributor'; @@ -32,17 +32,9 @@ class PoetryCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.cacheDependencyPath); - let primaryKey = ''; + const hash = await glob.hashFiles(this.patterns); + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; 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 From bce0bb9af2689a0b614ba8adf4442b101aafad8c Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 19 Jul 2022 13:12:19 +0200 Subject: [PATCH 7/7] Update restore dependency 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 e591ef1f3..b0d44b8f8 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -122,7 +122,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py await cacheDistributor.restoreCache(); - if (process.platform === 'linux') { + 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}` );