Skip to content

Commit

Permalink
fix: change from using env to os module
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Dec 26, 2023
1 parent 2c3ea16 commit 8454a14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import * as core from '@actions/core';
import * as cache from '@actions/cache';
import * as path from 'path';
import * as glob from '@actions/glob';
import osm from 'os';

import * as utils from '../src/cache-utils';
import {restoreCache} from '../src/cache-restore';

describe('cache-restore', () => {
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
if (!process.env.RUNNER_OS) {
process.env.RUNNER_OS = 'Linux';
}
if (!process.env.RUNNER_ARCH) {
process.env.RUNNER_ARCH = 'X64';
}
const platform = process.env.RUNNER_OS;
const arch = process.env.RUNNER_ARCH;
const platform = 'Linux';
const arch = 'arm64';
const commonPath = '/some/random/path';
const npmCachePath = `${commonPath}/npm`;
const pnpmCachePath = `${commonPath}/pnpm`;
Expand Down Expand Up @@ -56,6 +51,8 @@ describe('cache-restore', () => {
let getCommandOutputSpy: jest.SpyInstance;
let restoreCacheSpy: jest.SpyInstance;
let hashFilesSpy: jest.SpyInstance;
let archSpy: jest.SpyInstance;
let platformSpy: jest.SpyInstance;

beforeEach(() => {
// core
Expand Down Expand Up @@ -106,6 +103,13 @@ describe('cache-restore', () => {

// cache-utils
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');

// os
archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => arch);

platformSpy = jest.spyOn(osm, 'platform');
platformSpy.mockImplementation(() => platform);
});

describe('Validate provided package manager', () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92567,7 +92567,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
if (!packageManagerInfo) {
throw new Error(`Caching for '${packageManager}' is not supported`);
}
const platform = process.env.RUNNER_OS;
const platform = os_1.default.platform();
const arch = os_1.default.arch();
const cachePaths = yield (0, cache_utils_1.getCacheDirectories)(packageManagerInfo, cacheDependencyPath);
core.saveState(constants_1.State.CachePaths, cachePaths);
Expand Down
2 changes: 1 addition & 1 deletion src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const restoreCache = async (
if (!packageManagerInfo) {
throw new Error(`Caching for '${packageManager}' is not supported`);
}
const platform = process.env.RUNNER_OS;
const platform = os.platform();
const arch = os.arch();

const cachePaths = await getCacheDirectories(
Expand Down

0 comments on commit 8454a14

Please sign in to comment.