From 94822821b9a10f5a44580c648e95fe390ade40a1 Mon Sep 17 00:00:00 2001 From: myaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:03:52 -0400 Subject: [PATCH] inline installer.parseGoVersionFile() --- src/installer.ts | 14 -------------- src/main.ts | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 817c334f6..28554d32d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -417,20 +417,6 @@ export function makeSemver(version: string): string { return fullVersion; } -export function parseGoVersionFile(versionFilePath: string): string { - const contents = fs.readFileSync(versionFilePath).toString(); - - if ( - path.basename(versionFilePath) === 'go.mod' || - path.basename(versionFilePath) === 'go.work' - ) { - const match = contents.match(/^go (\d+(\.\d+)*)/m); - return match ? match[1] : ''; - } - - return contents.trim(); -} - async function resolveStableVersionDist(versionSpec: string, arch: string) { const archFilter = sys.getArch(arch); const platFilter = sys.getPlatform(); diff --git a/src/main.ts b/src/main.ts index 2fdeb8ae0..080add48d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -143,22 +143,24 @@ function resolveVersionInput(): string { core.warning( 'Both go-version and go-version-file inputs are specified, only go-version will be used' ); + versionFilePath = ''; } - - if (version) { - if (!version.endsWith('go.mod')) { - return version; - } - versionFilePath = version; + if (versionFilePath) { + version = versionFilePath; } - if (versionFilePath) { - if (!fs.existsSync(versionFilePath)) { + if ( + path.basename(version) === 'go.mod' || + path.basename(version) === 'go.work' + ) { + if (!fs.existsSync(version)) { throw new Error( - `The specified go version file at: ${versionFilePath} does not exist` + `The specified go version file at: ${version} does not exist` ); } - version = installer.parseGoVersionFile(versionFilePath); + const contents = fs.readFileSync(version).toString(); + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; } return version;