diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index cea14f4..6a04035 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -3,7 +3,7 @@ import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import fs from 'fs'; import cp from 'child_process'; -import osm from 'os'; +import osm, {type} from 'os'; import path from 'path'; import * as main from '../src/main'; import * as im from '../src/installer'; @@ -11,6 +11,7 @@ import * as im from '../src/installer'; import goJsonData from './data/golang-dl.json'; import matchers from '../matchers.json'; import goTestManifest from './data/versions-manifest.json'; +import {addExecutablesToCache, IGoVersionInfo} from '../src/installer'; const matcherPattern = matchers.problemMatcher[0].pattern[0]; const matcherRegExp = new RegExp(matcherPattern.regexp); const win32Join = path.win32.join; @@ -957,4 +958,39 @@ use . } ); }); + + describe('Windows performance workaround', () => { + it('addExecutablesToCache should depends on env[RUNNER_TOOL_CACHE]', async () => { + const statSpy = jest.spyOn(fs, 'statSync'); + // @ts-ignore + statSpy.mockImplementation(() => ({ + isDirectory: () => true + })); + const readdirSpy = jest.spyOn(fs, 'readdirSync'); + readdirSpy.mockImplementation(() => []); + const writeFileSpy = jest.spyOn(fs, 'writeFileSync'); + writeFileSpy.mockImplementation(() => {}); + const rmRFSpy = jest.spyOn(io, 'rmRF'); + rmRFSpy.mockImplementation(() => Promise.resolve()); + const mkdirPSpy = jest.spyOn(io, 'mkdirP'); + mkdirPSpy.mockImplementation(() => Promise.resolve()); + const cpSpy = jest.spyOn(io, 'cp'); + cpSpy.mockImplementation(() => Promise.resolve()); + + const info: IGoVersionInfo = { + type: 'dist', + downloadUrl: 'http://nowhere.com', + resolvedVersion: '1.2.3', + fileName: 'ignore' + }; + + process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache1'; + const cacheDir1 = await addExecutablesToCache('/qzx', info, 'arch'); + expect(cacheDir1).toBe('/faked-hostedtoolcache1/go/1.2.3/arch'); + + process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache2'; + const cacheDir2 = await addExecutablesToCache('/qzx', info, 'arch'); + expect(cacheDir2).toBe('/faked-hostedtoolcache2/go/1.2.3/arch'); + }); + }); }); diff --git a/src/installer.ts b/src/installer.ts index 16afd24..537d4c2 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -164,7 +164,7 @@ async function resolveVersionFromManifest( } } -async function addExecutablesToCache( +export async function addExecutablesToCache( extPath: string, info: IGoVersionInfo, arch: string