mirror of
https://github.com/actions/setup-go.git
synced 2025-06-18 23:02:59 -06:00
Merge 8e6a7f3c64
into 4de67c04ab
This commit is contained in:
commit
502b99df16
4 changed files with 50 additions and 53 deletions
|
@ -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();
|
||||
|
|
24
src/main.ts
24
src/main.ts
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue