Skip to content

Commit

Permalink
fix: remove the OS name from cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
KengoTODA committed Sep 6, 2021
1 parent 3a3331b commit fe37d8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
10 changes: 6 additions & 4 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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"
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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"
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`;
}

/**
Expand All @@ -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);
Expand Down

0 comments on commit fe37d8c

Please sign in to comment.