From 8454a14c98aea86afafe1a0a5cbcffd3e5244805 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Tue, 26 Dec 2023 17:11:46 +0800 Subject: [PATCH] fix: change from using env to os module --- __tests__/cache-restore.test.ts | 20 ++++++++++++-------- dist/setup/index.js | 2 +- src/cache-restore.ts | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 770497a70..8ff99b07d 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -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`; @@ -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 @@ -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', () => { diff --git a/dist/setup/index.js b/dist/setup/index.js index 4fc551a6b..4fb187cff 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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); diff --git a/src/cache-restore.ts b/src/cache-restore.ts index af12ad83c..f5ad58ffa 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -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(