mirror of
https://github.com/actions/setup-go.git
synced 2025-08-01 23:36:10 +08:00
Add go-version-file option (#62)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user