Skip to content

Commit 9482282

Browse files
committed
inline installer.parseGoVersionFile()
1 parent facc04d commit 9482282

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

src/installer.ts

-14
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,6 @@ export function makeSemver(version: string): string {
417417
return fullVersion;
418418
}
419419

420-
export function parseGoVersionFile(versionFilePath: string): string {
421-
const contents = fs.readFileSync(versionFilePath).toString();
422-
423-
if (
424-
path.basename(versionFilePath) === 'go.mod' ||
425-
path.basename(versionFilePath) === 'go.work'
426-
) {
427-
const match = contents.match(/^go (\d+(\.\d+)*)/m);
428-
return match ? match[1] : '';
429-
}
430-
431-
return contents.trim();
432-
}
433-
434420
async function resolveStableVersionDist(versionSpec: string, arch: string) {
435421
const archFilter = sys.getArch(arch);
436422
const platFilter = sys.getPlatform();

src/main.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,24 @@ function resolveVersionInput(): string {
143143
core.warning(
144144
'Both go-version and go-version-file inputs are specified, only go-version will be used'
145145
);
146+
versionFilePath = '';
146147
}
147-
148-
if (version) {
149-
if (!version.endsWith('go.mod')) {
150-
return version;
151-
}
152-
versionFilePath = version;
148+
if (versionFilePath) {
149+
version = versionFilePath;
153150
}
154151

155-
if (versionFilePath) {
156-
if (!fs.existsSync(versionFilePath)) {
152+
if (
153+
path.basename(version) === 'go.mod' ||
154+
path.basename(version) === 'go.work'
155+
) {
156+
if (!fs.existsSync(version)) {
157157
throw new Error(
158-
`The specified go version file at: ${versionFilePath} does not exist`
158+
`The specified go version file at: ${version} does not exist`
159159
);
160160
}
161-
version = installer.parseGoVersionFile(versionFilePath);
161+
const contents = fs.readFileSync(version).toString();
162+
const match = contents.match(/^go (\d+(\.\d+)*)/m);
163+
return match ? match[1] : '';
162164
}
163165

164166
return version;

0 commit comments

Comments
 (0)