Skip to content

Commit

Permalink
inline installer.parseGoVersionFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Jul 7, 2024
1 parent facc04d commit 9482282
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
14 changes: 0 additions & 14 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9482282

Please sign in to comment.