From a04a8ba00a55145fd73eec30d4c0145bb44282b5 Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 01:41:25 +0100 Subject: [PATCH 1/9] build debug log --- dist/setup/index.js | 1 + src/cache-distributions/pip-cache.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4cf276797..0eda83340 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65944,6 +65944,7 @@ class PipCache extends cache_distributor_1.default { computeKeys() { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(this.cacheDependencyPath); + core.info(`Cache key hash: ${hash}, path: ${this.cacheDependencyPath}`); let primaryKey = ''; let restoreKey = ''; if (utils_1.IS_LINUX) { diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 25b29c662..aedd3e0da 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -57,6 +57,7 @@ class PipCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.cacheDependencyPath); + core.info(`Cache key hash: ${hash}, path: ${this.cacheDependencyPath}`); let primaryKey = ''; let restoreKey = ''; From 8644d4cc22edbf6028802115c985185261728d50 Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 01:50:06 +0100 Subject: [PATCH 2/9] add backup --- dist/setup/index.js | 6 ++++-- src/cache-distributions/pip-cache.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0eda83340..4a3c0dd47 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65908,6 +65908,7 @@ class PipCache extends cache_distributor_1.default { constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') { super('pip', cacheDependencyPath); this.pythonVersion = pythonVersion; + this.cacheDependencyBackupPath = '**/pyproject.toml'; } getCacheGlobalDirectories() { return __awaiter(this, void 0, void 0, function* () { @@ -65943,8 +65944,9 @@ class PipCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = yield glob.hashFiles(this.cacheDependencyPath); - core.info(`Cache key hash: ${hash}, path: ${this.cacheDependencyPath}`); + const hash = (yield glob.hashFiles(this.cacheDependencyPath)) + || (yield glob.hashFiles(this.cacheDependencyBackupPath)); + core.info(`Cache key hash: ${hash}`); let primaryKey = ''; let restoreKey = ''; if (utils_1.IS_LINUX) { diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index aedd3e0da..e8666033a 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -10,6 +10,9 @@ import CacheDistributor from './cache-distributor'; import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils'; class PipCache extends CacheDistributor { + + private readonly cacheDependencyBackupPath: string = '**/pyproject.toml'; + constructor( private pythonVersion: string, cacheDependencyPath: string = '**/requirements.txt' @@ -56,8 +59,9 @@ class PipCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.cacheDependencyPath); - core.info(`Cache key hash: ${hash}, path: ${this.cacheDependencyPath}`); + const hash = await glob.hashFiles(this.cacheDependencyPath) + || await glob.hashFiles(this.cacheDependencyBackupPath); + core.info(`Cache key hash: ${hash}`); let primaryKey = ''; let restoreKey = ''; From c72f56dac905a4ff49b68cac18e83fcffdbb877d Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 01:52:16 +0100 Subject: [PATCH 3/9] add cache backup file --- src/cache-distributions/pip-cache.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index e8666033a..b48c10758 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -61,7 +61,6 @@ class PipCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.cacheDependencyPath) || await glob.hashFiles(this.cacheDependencyBackupPath); - core.info(`Cache key hash: ${hash}`); let primaryKey = ''; let restoreKey = ''; From 4fe0c4a7d366a6fbc8d110e26e8623973eff8d2e Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 01:54:08 +0100 Subject: [PATCH 4/9] update docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08619c6a3..cb098d980 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Using `architecture` input it is possible to specify the required Python or PyPy The action has built-in functionality for caching and restoring dependencies. It uses [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. -The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash that want to be used. +The action defaults to searching for a dependency file (`requirements.txt` or `pyproject.toml` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash that want to be used. - For `pip`, the action will cache the global cache directory - For `pipenv`, the action will cache virtualenv directory From 78738c7252f7ed82a522a4b30c5868122bb57686 Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 01:54:31 +0100 Subject: [PATCH 5/9] build --- dist/setup/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4a3c0dd47..61712724f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65946,7 +65946,6 @@ class PipCache extends cache_distributor_1.default { return __awaiter(this, void 0, void 0, function* () { const hash = (yield glob.hashFiles(this.cacheDependencyPath)) || (yield glob.hashFiles(this.cacheDependencyBackupPath)); - core.info(`Cache key hash: ${hash}`); let primaryKey = ''; let restoreKey = ''; if (utils_1.IS_LINUX) { From 292b71d345691eca3f447ec586f1dfd981a67a59 Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 20 Jan 2023 09:33:53 +0100 Subject: [PATCH 6/9] format & build --- dist/setup/index.js | 4 ++-- src/cache-distributions/pip-cache.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 61712724f..c788fd645 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65944,8 +65944,8 @@ class PipCache extends cache_distributor_1.default { } computeKeys() { return __awaiter(this, void 0, void 0, function* () { - const hash = (yield glob.hashFiles(this.cacheDependencyPath)) - || (yield glob.hashFiles(this.cacheDependencyBackupPath)); + const hash = (yield glob.hashFiles(this.cacheDependencyPath)) || + (yield glob.hashFiles(this.cacheDependencyBackupPath)); let primaryKey = ''; let restoreKey = ''; if (utils_1.IS_LINUX) { diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index b48c10758..554d18d7b 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -10,7 +10,6 @@ import CacheDistributor from './cache-distributor'; import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils'; class PipCache extends CacheDistributor { - private readonly cacheDependencyBackupPath: string = '**/pyproject.toml'; constructor( @@ -59,8 +58,9 @@ class PipCache extends CacheDistributor { } protected async computeKeys() { - const hash = await glob.hashFiles(this.cacheDependencyPath) - || await glob.hashFiles(this.cacheDependencyBackupPath); + const hash = + (await glob.hashFiles(this.cacheDependencyPath)) || + (await glob.hashFiles(this.cacheDependencyBackupPath)); let primaryKey = ''; let restoreKey = ''; From 29e63a4476ee6b82ede9eebedc4b07939f5c9ba5 Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Thu, 9 Feb 2023 09:09:51 +0100 Subject: [PATCH 7/9] test implemented --- __tests__/cache-restore.test.ts | 43 +++++++++++++++++--- dist/cache-save/index.js | 23 +++++++++-- dist/setup/index.js | 26 ++++++++++-- src/cache-distributions/cache-distributor.ts | 11 +++-- src/cache-distributions/constants.ts | 2 + src/cache-distributions/pip-cache.ts | 3 +- 6 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 src/cache-distributions/constants.ts diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index d6ed8320b..250342768 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -5,7 +5,7 @@ import * as exec from '@actions/exec'; import * as io from '@actions/io'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; import {State} from '../src/cache-distributions/cache-distributor'; -import * as utils from './../src/utils'; +import * as constants from '../src/cache-distributions/constants'; describe('restore-cache', () => { const pipFileLockHash = @@ -196,11 +196,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py 30000 ); - it.each([ - ['pip', '3.8.12', 'requirements-linux.txt', 'requirements-linux.txt'], - ['pip', '3.8.12', 'requirements.txt', 'requirements.txt'], - ['pipenv', '3.9.12', 'requirements.txt', 'requirements.txt'] - ])( + it.each([['pipenv', '3.9.12', 'requirements.txt', 'requirements.txt']])( 'Should throw an error because dependency file is not found', async ( packageManager, @@ -213,6 +209,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py pythonVersion, dependencyFile ); + await expect(cacheDistributor.restoreCache()).rejects.toThrowError( `No file in ${process.cwd()} matched to [${cacheDependencyPath .split('\n') @@ -220,6 +217,40 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py ); } ); + + it.each([ + ['pip', '3.8.12', 'requirements-linux.txt'], + ['pip', '3.8.12', 'requirements.txt'] + ])( + 'Shouldn`t throw an error as there is a default file `pyproject.toml` to use when requirements.txt is not specified', + async (packageManager, pythonVersion, dependencyFile) => { + const cacheDistributor = getCacheDistributor( + packageManager, + pythonVersion, + dependencyFile + ); + await expect(cacheDistributor.restoreCache()).resolves; + } + ); + + it.each([ + ['pip', '3.8.12', 'requirements-linux.txt'], + ['pip', '3.8.12', 'requirements.txt'] + ])( + 'Should throw an error as there is no default file `pyproject.toml` to use when requirements.txt is not specified', + async (packageManager, pythonVersion, dependencyFile) => { + jest.mock('../src/cache-distributions/constants', () => ({ + CACHE_DEPENDENCY_BACKUP_PATH: '**/pyprojecttest.toml' + })); + + const cacheDistributor = getCacheDistributor( + packageManager, + pythonVersion, + dependencyFile + ); + await expect(cacheDistributor.restoreCache()).resolves; + } + ); }); describe('Dependencies changed', () => { diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 09a9fc6ec..c9c91ec7b 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -59699,6 +59699,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.State = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); +const constants_1 = __nccwpck_require__(8248); var State; (function (State) { State["STATE_CACHE_PRIMARY_KEY"] = "cache-primary-key"; @@ -59718,9 +59719,12 @@ class CacheDistributor { return __awaiter(this, void 0, void 0, function* () { const { primaryKey, restoreKey } = yield this.computeKeys(); if (primaryKey.endsWith('-')) { - throw new Error(`No file in ${process.cwd()} matched to [${this.cacheDependencyPath - .split('\n') - .join(',')}], make sure you have checked out the target repository`); + const file = this.packageManager === 'pip' + ? `${this.cacheDependencyPath + .split('\n') + .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}}` + : this.cacheDependencyPath.split('\n').join(','); + throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`); } const cachePath = yield this.getCacheGlobalDirectories(); core.saveState(State.CACHE_PATHS, cachePath); @@ -59744,6 +59748,19 @@ class CacheDistributor { exports["default"] = CacheDistributor; +/***/ }), + +/***/ 8248: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.CACHE_DEPENDENCY_BACKUP_PATH = void 0; +const CACHE_DEPENDENCY_BACKUP_PATH = '**/pyproject.toml'; +exports.CACHE_DEPENDENCY_BACKUP_PATH = CACHE_DEPENDENCY_BACKUP_PATH; + + /***/ }), /***/ 4553: diff --git a/dist/setup/index.js b/dist/setup/index.js index c788fd645..6d4e35570 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65775,6 +65775,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.State = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); +const constants_1 = __nccwpck_require__(8248); var State; (function (State) { State["STATE_CACHE_PRIMARY_KEY"] = "cache-primary-key"; @@ -65794,9 +65795,12 @@ class CacheDistributor { return __awaiter(this, void 0, void 0, function* () { const { primaryKey, restoreKey } = yield this.computeKeys(); if (primaryKey.endsWith('-')) { - throw new Error(`No file in ${process.cwd()} matched to [${this.cacheDependencyPath - .split('\n') - .join(',')}], make sure you have checked out the target repository`); + const file = this.packageManager === 'pip' + ? `${this.cacheDependencyPath + .split('\n') + .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}}` + : this.cacheDependencyPath.split('\n').join(','); + throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`); } const cachePath = yield this.getCacheGlobalDirectories(); core.saveState(State.CACHE_PATHS, cachePath); @@ -65856,6 +65860,19 @@ function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) exports.getCacheDistributor = getCacheDistributor; +/***/ }), + +/***/ 8248: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.CACHE_DEPENDENCY_BACKUP_PATH = void 0; +const CACHE_DEPENDENCY_BACKUP_PATH = '**/pyproject.toml'; +exports.CACHE_DEPENDENCY_BACKUP_PATH = CACHE_DEPENDENCY_BACKUP_PATH; + + /***/ }), /***/ 5546: @@ -65904,11 +65921,12 @@ const path = __importStar(__nccwpck_require__(1017)); const os_1 = __importDefault(__nccwpck_require__(2037)); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); const utils_1 = __nccwpck_require__(1314); +const constants_1 = __nccwpck_require__(8248); class PipCache extends cache_distributor_1.default { constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') { super('pip', cacheDependencyPath); this.pythonVersion = pythonVersion; - this.cacheDependencyBackupPath = '**/pyproject.toml'; + this.cacheDependencyBackupPath = constants_1.CACHE_DEPENDENCY_BACKUP_PATH; } getCacheGlobalDirectories() { return __awaiter(this, void 0, void 0, function* () { diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index 2e46c961d..e2e5475b9 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -1,5 +1,6 @@ import * as cache from '@actions/cache'; import * as core from '@actions/core'; +import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants'; export enum State { STATE_CACHE_PRIMARY_KEY = 'cache-primary-key', @@ -24,10 +25,14 @@ abstract class CacheDistributor { public async restoreCache() { const {primaryKey, restoreKey} = await this.computeKeys(); if (primaryKey.endsWith('-')) { + const file = + this.packageManager === 'pip' + ? `${this.cacheDependencyPath + .split('\n') + .join(',')} or ${CACHE_DEPENDENCY_BACKUP_PATH}}` + : this.cacheDependencyPath.split('\n').join(','); throw new Error( - `No file in ${process.cwd()} matched to [${this.cacheDependencyPath - .split('\n') - .join(',')}], make sure you have checked out the target repository` + `No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository` ); } diff --git a/src/cache-distributions/constants.ts b/src/cache-distributions/constants.ts new file mode 100644 index 000000000..74edfd927 --- /dev/null +++ b/src/cache-distributions/constants.ts @@ -0,0 +1,2 @@ +const CACHE_DEPENDENCY_BACKUP_PATH: string = '**/pyproject.toml'; +export {CACHE_DEPENDENCY_BACKUP_PATH}; diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 554d18d7b..c29d4cd19 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -8,9 +8,10 @@ import os from 'os'; import CacheDistributor from './cache-distributor'; import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils'; +import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants'; class PipCache extends CacheDistributor { - private readonly cacheDependencyBackupPath: string = '**/pyproject.toml'; + private cacheDependencyBackupPath: string = CACHE_DEPENDENCY_BACKUP_PATH; constructor( private pythonVersion: string, From e8c120888a4dafee0a5ae188b1c9e2b9fae4947e Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii <102794661+e-korolevskii@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:05:21 +0100 Subject: [PATCH 8/9] Update src/cache-distributions/cache-distributor.ts Co-authored-by: Ivan <98037481+IvanZosimov@users.noreply.github.com> --- src/cache-distributions/cache-distributor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index e2e5475b9..29fba0cf4 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -29,7 +29,7 @@ abstract class CacheDistributor { this.packageManager === 'pip' ? `${this.cacheDependencyPath .split('\n') - .join(',')} or ${CACHE_DEPENDENCY_BACKUP_PATH}}` + .join(',')} or ${CACHE_DEPENDENCY_BACKUP_PATH}` : this.cacheDependencyPath.split('\n').join(','); throw new Error( `No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository` From a5572734efc4c5cc32e71436e56f42d2122ccdbe Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Fri, 17 Feb 2023 12:49:07 +0100 Subject: [PATCH 9/9] build --- dist/cache-save/index.js | 2 +- dist/setup/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index c9c91ec7b..bef6790aa 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -59722,7 +59722,7 @@ class CacheDistributor { const file = this.packageManager === 'pip' ? `${this.cacheDependencyPath .split('\n') - .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}}` + .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}` : this.cacheDependencyPath.split('\n').join(','); throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`); } diff --git a/dist/setup/index.js b/dist/setup/index.js index 6d4e35570..c309b19dd 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65798,7 +65798,7 @@ class CacheDistributor { const file = this.packageManager === 'pip' ? `${this.cacheDependencyPath .split('\n') - .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}}` + .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}` : this.cacheDependencyPath.split('\n').join(','); throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy