diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 92e7ef50..52184f44 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -92709,36 +92709,9 @@ function getNodeVersionFromFile(versionFilePath) { catch { core.info('Node version file is not JSON file'); } - const nodePrefix = 'node'; - let inRunsSection = false; - for (const line of contents.split(/\r?\n/)) { - const trimmedLine = line.trim(); - if (!inRunsSection) { - inRunsSection = - trimmedLine === 'runs:' || trimmedLine.startsWith('runs: #'); - continue; - } - if (!trimmedLine || trimmedLine.startsWith('#')) { - continue; - } - if (!line.match(/^\s/)) { - break; - } - const separatorIndex = trimmedLine.indexOf(':'); - if (separatorIndex <= 0 || - trimmedLine.slice(0, separatorIndex) !== 'using') { - continue; - } - let runtime = trimmedLine.slice(separatorIndex + 1).trim(); - runtime = runtime.split('#', 1)[0].trim(); - if ((runtime.startsWith("'") && runtime.endsWith("'")) || - (runtime.startsWith('"') && runtime.endsWith('"'))) { - runtime = runtime.slice(1, -1); - } - if (runtime.startsWith(nodePrefix) && - /^\d+$/.test(runtime.slice(nodePrefix.length))) { - return runtime.slice(nodePrefix.length); - } + const actionYmlNodeVersion = contents.match(/^\s+using:\s*['"]?node(?\d+)['"]?\s*(?:#.*)?$/m); + if (actionYmlNodeVersion) { + return actionYmlNodeVersion.groups?.version ?? null; } const found = contents.match(/^(?:node(js)?\s+)?v?(?[^\s]+)$/m); return found?.groups?.version ?? contents.trim(); diff --git a/dist/setup/index.js b/dist/setup/index.js index dcc17212..9834f15d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -98103,36 +98103,9 @@ function getNodeVersionFromFile(versionFilePath) { catch { core_info('Node version file is not JSON file'); } - const nodePrefix = 'node'; - let inRunsSection = false; - for (const line of contents.split(/\r?\n/)) { - const trimmedLine = line.trim(); - if (!inRunsSection) { - inRunsSection = - trimmedLine === 'runs:' || trimmedLine.startsWith('runs: #'); - continue; - } - if (!trimmedLine || trimmedLine.startsWith('#')) { - continue; - } - if (!line.match(/^\s/)) { - break; - } - const separatorIndex = trimmedLine.indexOf(':'); - if (separatorIndex <= 0 || - trimmedLine.slice(0, separatorIndex) !== 'using') { - continue; - } - let runtime = trimmedLine.slice(separatorIndex + 1).trim(); - runtime = runtime.split('#', 1)[0].trim(); - if ((runtime.startsWith("'") && runtime.endsWith("'")) || - (runtime.startsWith('"') && runtime.endsWith('"'))) { - runtime = runtime.slice(1, -1); - } - if (runtime.startsWith(nodePrefix) && - /^\d+$/.test(runtime.slice(nodePrefix.length))) { - return runtime.slice(nodePrefix.length); - } + const actionYmlNodeVersion = contents.match(/^\s+using:\s*['"]?node(?\d+)['"]?\s*(?:#.*)?$/m); + if (actionYmlNodeVersion) { + return actionYmlNodeVersion.groups?.version ?? null; } const found = contents.match(/^(?:node(js)?\s+)?v?(?[^\s]+)$/m); return found?.groups?.version ?? contents.trim(); diff --git a/src/util.ts b/src/util.ts index 085f929f..dd7ae1e6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -68,45 +68,11 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null { core.info('Node version file is not JSON file'); } - const nodePrefix = 'node'; - let inRunsSection = false; - for (const line of contents.split(/\r?\n/)) { - const trimmedLine = line.trim(); - if (!inRunsSection) { - inRunsSection = - trimmedLine === 'runs:' || trimmedLine.startsWith('runs: #'); - continue; - } - - if (!trimmedLine || trimmedLine.startsWith('#')) { - continue; - } - if (!line.match(/^\s/)) { - break; - } - - const separatorIndex = trimmedLine.indexOf(':'); - if ( - separatorIndex <= 0 || - trimmedLine.slice(0, separatorIndex) !== 'using' - ) { - continue; - } - - let runtime = trimmedLine.slice(separatorIndex + 1).trim(); - runtime = runtime.split('#', 1)[0].trim(); - if ( - (runtime.startsWith("'") && runtime.endsWith("'")) || - (runtime.startsWith('"') && runtime.endsWith('"')) - ) { - runtime = runtime.slice(1, -1); - } - if ( - runtime.startsWith(nodePrefix) && - /^\d+$/.test(runtime.slice(nodePrefix.length)) - ) { - return runtime.slice(nodePrefix.length); - } + const actionYmlNodeVersion = contents.match( + /^\s+using:\s*['"]?node(?\d+)['"]?\s*(?:#.*)?$/m + ); + if (actionYmlNodeVersion) { + return actionYmlNodeVersion.groups?.version ?? null; } const found = contents.match(/^(?:node(js)?\s+)?v?(?[^\s]+)$/m);