This commit is contained in:
myaaaaaaaaa 2025-06-13 09:44:09 -06:00 committed by GitHub
commit 502b99df16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 53 deletions

View file

@ -488,20 +488,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();

View file

@ -137,25 +137,31 @@ export function parseGoVersion(versionString: string): string {
function resolveVersionInput(): string {
let version = core.getInput('go-version');
const versionFilePath = core.getInput('go-version-file');
let versionFilePath = core.getInput('go-version-file');
if (version && versionFilePath) {
core.warning(
'Both go-version and go-version-file inputs are specified, only go-version will be used'
);
versionFilePath = '';
}
if (version) {
return version;
}
if (versionFilePath) {
if (!fs.existsSync(versionFilePath)) {
version = 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;