From fe37d8c2997358fd460bdf767cb1d7550f85b37d Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Mon, 6 Sep 2021 02:01:55 +0000 Subject: [PATCH] fix: remove the OS name from cache key --- dist/cleanup/index.js | 10 ++++++---- dist/setup/index.js | 10 ++++++---- src/cache.ts | 10 +++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index bbc65296e..a8f2f1db1 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -64536,7 +64536,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.save = exports.restore = void 0; +exports.save = exports.restore = exports.computeCacheKey = exports.findPackageManager = void 0; const path_1 = __webpack_require__(622); const os_1 = __importDefault(__webpack_require__(87)); const cache = __importStar(__webpack_require__(692)); @@ -64566,18 +64566,20 @@ function findPackageManager(id) { } return packageManager; } +exports.findPackageManager = findPackageManager; /** * A function that generates a cache key to use. - * Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"". + * Format of the generated key will be "setup-java-${{ id }}-${{ fileHash }}"". * If there is no file matched to {@link PackageManager.path}, the generated key ends with a dash (-). * @see {@link https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key|spec of cache key} */ function computeCacheKey(packageManager) { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(packageManager.pattern.join('\n')); - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`; + return `${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`; }); } +exports.computeCacheKey = computeCacheKey; /** * Restore the dependency cache * @param id ID of the package manager, should be "maven" or "gradle" @@ -64592,7 +64594,7 @@ function restore(id) { throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); } const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [ - `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}` + `${CACHE_KEY_PREFIX}-${id}` ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); diff --git a/dist/setup/index.js b/dist/setup/index.js index d8f0e773e..591b7b01f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -18923,7 +18923,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.save = exports.restore = void 0; +exports.save = exports.restore = exports.computeCacheKey = exports.findPackageManager = void 0; const path_1 = __webpack_require__(622); const os_1 = __importDefault(__webpack_require__(87)); const cache = __importStar(__webpack_require__(692)); @@ -18953,18 +18953,20 @@ function findPackageManager(id) { } return packageManager; } +exports.findPackageManager = findPackageManager; /** * A function that generates a cache key to use. - * Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"". + * Format of the generated key will be "setup-java-${{ id }}-${{ fileHash }}"". * If there is no file matched to {@link PackageManager.path}, the generated key ends with a dash (-). * @see {@link https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key|spec of cache key} */ function computeCacheKey(packageManager) { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(packageManager.pattern.join('\n')); - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`; + return `${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`; }); } +exports.computeCacheKey = computeCacheKey; /** * Restore the dependency cache * @param id ID of the package manager, should be "maven" or "gradle" @@ -18979,7 +18981,7 @@ function restore(id) { throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); } const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [ - `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}` + `${CACHE_KEY_PREFIX}-${id}` ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); diff --git a/src/cache.ts b/src/cache.ts index fb97fb0b1..b277cd605 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -35,7 +35,7 @@ const supportedPackageManager: PackageManager[] = [ } ]; -function findPackageManager(id: string): PackageManager { +export function findPackageManager(id: string): PackageManager { const packageManager = supportedPackageManager.find(packageManager => packageManager.id === id); if (packageManager === undefined) { throw new Error(`unknown package manager specified: ${id}`); @@ -45,13 +45,13 @@ function findPackageManager(id: string): PackageManager { /** * A function that generates a cache key to use. - * Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"". + * Format of the generated key will be "setup-java-${{ id }}-${{ fileHash }}"". * If there is no file matched to {@link PackageManager.path}, the generated key ends with a dash (-). * @see {@link https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key|spec of cache key} */ -async function computeCacheKey(packageManager: PackageManager) { +export async function computeCacheKey(packageManager: PackageManager) { const hash = await glob.hashFiles(packageManager.pattern.join('\n')); - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`; + return `${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`; } /** @@ -73,7 +73,7 @@ export async function restore(id: string) { } const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, [ - `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}` + `${CACHE_KEY_PREFIX}-${id}` ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey);