Skip to content

Commit 8454a14

Browse files
committed
fix: change from using env to os module
1 parent 2c3ea16 commit 8454a14

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

__tests__/cache-restore.test.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ 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';
89

910
describe('cache-restore', () => {
1011
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
11-
if (!process.env.RUNNER_OS) {
12-
process.env.RUNNER_OS = 'Linux';
13-
}
14-
if (!process.env.RUNNER_ARCH) {
15-
process.env.RUNNER_ARCH = 'X64';
16-
}
17-
const platform = process.env.RUNNER_OS;
18-
const arch = process.env.RUNNER_ARCH;
12+
const platform = 'Linux';
13+
const arch = 'arm64';
1914
const commonPath = '/some/random/path';
2015
const npmCachePath = `${commonPath}/npm`;
2116
const pnpmCachePath = `${commonPath}/pnpm`;
@@ -56,6 +51,8 @@ describe('cache-restore', () => {
5651
let getCommandOutputSpy: jest.SpyInstance;
5752
let restoreCacheSpy: jest.SpyInstance;
5853
let hashFilesSpy: jest.SpyInstance;
54+
let archSpy: jest.SpyInstance;
55+
let platformSpy: jest.SpyInstance;
5956

6057
beforeEach(() => {
6158
// core
@@ -106,6 +103,13 @@ describe('cache-restore', () => {
106103

107104
// cache-utils
108105
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
106+
107+
// os
108+
archSpy = jest.spyOn(osm, 'arch');
109+
archSpy.mockImplementation(() => arch);
110+
111+
platformSpy = jest.spyOn(osm, 'platform');
112+
platformSpy.mockImplementation(() => platform);
109113
});
110114

111115
describe('Validate provided package manager', () => {

dist/setup/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92567,7 +92567,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
9256792567
if (!packageManagerInfo) {
9256892568
throw new Error(`Caching for '${packageManager}' is not supported`);
9256992569
}
92570-
const platform = process.env.RUNNER_OS;
92570+
const platform = os_1.default.platform();
9257192571
const arch = os_1.default.arch();
9257292572
const cachePaths = yield (0, cache_utils_1.getCacheDirectories)(packageManagerInfo, cacheDependencyPath);
9257392573
core.saveState(constants_1.State.CachePaths, cachePaths);

src/cache-restore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const restoreCache = async (
2121
if (!packageManagerInfo) {
2222
throw new Error(`Caching for '${packageManager}' is not supported`);
2323
}
24-
const platform = process.env.RUNNER_OS;
24+
const platform = os.platform();
2525
const arch = os.arch();
2626

2727
const cachePaths = await getCacheDirectories(

0 commit comments

Comments
 (0)