From 60732b496693486fa36434b6259b4040052e6e7d Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Wed, 19 Oct 2022 15:26:27 +0200 Subject: [PATCH] fix toolcache --- dist/setup/index.js | 13 ++++++++++++- src/installer.ts | 22 ++++++++++++++++++++-- src/main.ts | 3 ++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e7090563..43838707 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73226,7 +73226,13 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // check cache core.debug('check toolcache'); let toolPath; - toolPath = tc.find('node', versionSpec, osArch); + if (isNightly) { + const nightlyVersion = findNightlyVersionInHostedToolcache(versionSpec, osArch); + toolPath = tc.find('node', nightlyVersion, osArch); + } + else { + toolPath = tc.find('node', versionSpec, osArch); + } // If not found in cache, download if (toolPath) { core.info(`Found in cache @ ${toolPath}`); @@ -73322,6 +73328,11 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { }); } exports.getNode = getNode; +function findNightlyVersionInHostedToolcache(versionsSpec, osArch) { + const foundAllVersions = tc.findAllVersions('node', osArch); + const version = evaluateVersions(foundAllVersions, versionsSpec); + return version; +} function isLtsAlias(versionSpec) { return versionSpec.startsWith('lts/'); } diff --git a/src/installer.ts b/src/installer.ts index c727a6dc..efa081a7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -83,7 +83,15 @@ export async function getNode( // check cache core.debug('check toolcache'); let toolPath: string; - toolPath = tc.find('node', versionSpec, osArch); + if (isNightly) { + const nightlyVersion = findNightlyVersionInHostedToolcache( + versionSpec, + osArch + ); + toolPath = tc.find('node', nightlyVersion, osArch); + } else { + toolPath = tc.find('node', versionSpec, osArch); + } // If not found in cache, download if (toolPath) { @@ -207,6 +215,16 @@ export async function getNode( core.addPath(toolPath); } +function findNightlyVersionInHostedToolcache( + versionsSpec: string, + osArch: string +) { + const foundAllVersions = tc.findAllVersions('node', osArch); + const version = evaluateVersions(foundAllVersions, versionsSpec); + + return version; +} + function isLtsAlias(versionSpec: string): boolean { return versionSpec.startsWith('lts/'); } @@ -398,7 +416,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string { let version = ''; core.debug(`evaluating ${versions.length} versions`); - if(versionSpec.includes('nightly')) { + if (versionSpec.includes('nightly')) { return evaluateNightlyVersions(versions, versionSpec); } diff --git a/src/main.ts b/src/main.ts index bec19354..45ef02e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,7 +34,8 @@ export async function run() { if (version) { const token = core.getInput('token'); const auth = !token || isGhes() ? undefined : `token ${token}`; - const stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; + const stable = + (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; await installer.getNode(version, stable, checkLatest, auth, arch);