1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-go synced 2025-06-23 18:28:01 +02:00

Add go-version-file option (#62)

This commit is contained in:
So Jomura 2022-05-12 17:04:39 +09:00 committed by GitHub
parent 193b404f8a
commit 265edc1beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import * as path from 'path';
import * as semver from 'semver';
import * as httpm from '@actions/http-client';
import * as sys from './system';
import fs from 'fs';
import os from 'os';
type InstallationType = 'dist' | 'manifest';
@ -298,3 +299,14 @@ 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') {
const match = contents.match(/^go (\d+(\.\d+)*)/m);
return match ? match[1] : '';
}
return contents.trim();
}