Skip to content

Commit 39370e3

Browse files
authored
fix: add arch to cached path (#843)
* fix: add arch to cached path * fix: change from using env to os module * fix: use process.env.RUNNER_OS instead of os.platform() * fix: remove unused var
1 parent abb238b commit 39370e3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

__tests__/cache-restore.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22
import * as cache from '@actions/cache';
33
import * as path from 'path';
44
import * as glob from '@actions/glob';
5+
import osm from 'os';
56

67
import * as utils from '../src/cache-utils';
78
import {restoreCache} from '../src/cache-restore';
@@ -12,6 +13,7 @@ describe('cache-restore', () => {
1213
process.env.RUNNER_OS = 'Linux';
1314
}
1415
const platform = process.env.RUNNER_OS;
16+
const arch = 'arm64';
1517
const commonPath = '/some/random/path';
1618
const npmCachePath = `${commonPath}/npm`;
1719
const pnpmCachePath = `${commonPath}/pnpm`;
@@ -52,6 +54,7 @@ describe('cache-restore', () => {
5254
let getCommandOutputSpy: jest.SpyInstance;
5355
let restoreCacheSpy: jest.SpyInstance;
5456
let hashFilesSpy: jest.SpyInstance;
57+
let archSpy: jest.SpyInstance;
5558

5659
beforeEach(() => {
5760
// core
@@ -102,6 +105,10 @@ describe('cache-restore', () => {
102105

103106
// cache-utils
104107
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
108+
109+
// os
110+
archSpy = jest.spyOn(osm, 'arch');
111+
archSpy.mockImplementation(() => arch);
105112
});
106113

107114
describe('Validate provided package manager', () => {
@@ -135,7 +142,7 @@ describe('cache-restore', () => {
135142
await restoreCache(packageManager, '');
136143
expect(hashFilesSpy).toHaveBeenCalled();
137144
expect(infoSpy).toHaveBeenCalledWith(
138-
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
145+
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
139146
);
140147
expect(infoSpy).not.toHaveBeenCalledWith(
141148
`${packageManager} cache is not found`

dist/setup/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93303,6 +93303,7 @@ const core = __importStar(__nccwpck_require__(2186));
9330393303
const glob = __importStar(__nccwpck_require__(8090));
9330493304
const path_1 = __importDefault(__nccwpck_require__(1017));
9330593305
const fs_1 = __importDefault(__nccwpck_require__(7147));
93306+
const os_1 = __importDefault(__nccwpck_require__(2037));
9330693307
const constants_1 = __nccwpck_require__(9042);
9330793308
const cache_utils_1 = __nccwpck_require__(1678);
9330893309
const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
@@ -93311,6 +93312,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
9331193312
throw new Error(`Caching for '${packageManager}' is not supported`);
9331293313
}
9331393314
const platform = process.env.RUNNER_OS;
93315+
const arch = os_1.default.arch();
9331493316
const cachePaths = yield (0, cache_utils_1.getCacheDirectories)(packageManagerInfo, cacheDependencyPath);
9331593317
core.saveState(constants_1.State.CachePaths, cachePaths);
9331693318
const lockFilePath = cacheDependencyPath
@@ -93320,7 +93322,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
9332093322
if (!fileHash) {
9332193323
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
9332293324
}
93323-
const keyPrefix = `node-cache-${platform}-${packageManager}`;
93325+
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
9332493326
const primaryKey = `${keyPrefix}-${fileHash}`;
9332593327
core.debug(`primary key is ${primaryKey}`);
9332693328
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);

src/cache-restore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as core from '@actions/core';
33
import * as glob from '@actions/glob';
44
import path from 'path';
55
import fs from 'fs';
6+
import os from 'os';
67

78
import {State} from './constants';
89
import {
@@ -21,6 +22,7 @@ export const restoreCache = async (
2122
throw new Error(`Caching for '${packageManager}' is not supported`);
2223
}
2324
const platform = process.env.RUNNER_OS;
25+
const arch = os.arch();
2426

2527
const cachePaths = await getCacheDirectories(
2628
packageManagerInfo,
@@ -38,7 +40,7 @@ export const restoreCache = async (
3840
);
3941
}
4042

41-
const keyPrefix = `node-cache-${platform}-${packageManager}`;
43+
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
4244
const primaryKey = `${keyPrefix}-${fileHash}`;
4345
core.debug(`primary key is ${primaryKey}`);
4446

0 commit comments

Comments
 (0)
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