fix: add arch to cached path

This commit is contained in:
Peng Xiao 2023-08-30 00:36:04 +08:00 committed by GitHub
parent 5e21ff4d9b
commit 343cc68d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2288 additions and 2282 deletions

View File

@ -11,7 +11,11 @@ describe('cache-restore', () => {
if (!process.env.RUNNER_OS) { if (!process.env.RUNNER_OS) {
process.env.RUNNER_OS = 'Linux'; process.env.RUNNER_OS = 'Linux';
} }
if (!process.env.RUNNER_ARCH) {
process.env.RUNNER_ARCH = 'X64';
}
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const arch = process.env.RUNNER_ARCH;
const commonPath = '/some/random/path'; const commonPath = '/some/random/path';
const npmCachePath = `${commonPath}/npm`; const npmCachePath = `${commonPath}/npm`;
const pnpmCachePath = `${commonPath}/pnpm`; const pnpmCachePath = `${commonPath}/pnpm`;
@ -135,7 +139,7 @@ describe('cache-restore', () => {
await restoreCache(packageManager, ''); await restoreCache(packageManager, '');
expect(hashFilesSpy).toHaveBeenCalled(); expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}` `Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
); );
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`${packageManager} cache is not found` `${packageManager} cache is not found`

3
dist/setup/index.js vendored
View File

@ -71163,6 +71163,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
throw new Error(`Caching for '${packageManager}' is not supported`); throw new Error(`Caching for '${packageManager}' is not supported`);
} }
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const arch = process.env.RUNNER_ARCH;
const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath); const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath);
core.saveState(constants_1.State.CachePaths, cachePaths); core.saveState(constants_1.State.CachePaths, cachePaths);
const lockFilePath = cacheDependencyPath const lockFilePath = cacheDependencyPath
@ -71172,7 +71173,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
if (!fileHash) { if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
} }
const keyPrefix = `node-cache-${platform}-${packageManager}`; const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`; const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`); core.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey); core.saveState(constants_1.State.CachePrimaryKey, primaryKey);

View File

@ -21,6 +21,7 @@ export const restoreCache = async (
throw new Error(`Caching for '${packageManager}' is not supported`); throw new Error(`Caching for '${packageManager}' is not supported`);
} }
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const arch = process.env.RUNNER_ARCH;
const cachePaths = await getCacheDirectories( const cachePaths = await getCacheDirectories(
packageManagerInfo, packageManagerInfo,
@ -38,7 +39,7 @@ export const restoreCache = async (
); );
} }
const keyPrefix = `node-cache-${platform}-${packageManager}`; const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`; const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`); core.debug(`primary key is ${primaryKey}`);