mirror of
https://github.com/actions/setup-go.git
synced 2025-06-30 21:23:43 +00:00
Read go version from go.mod
This commit is contained in:
parent
f5fe54e5a4
commit
55b9afc327
4 changed files with 76 additions and 22 deletions
|
@ -266,3 +266,12 @@ export function makeSemver(version: string): string {
|
|||
|
||||
return `${verPart}${prereleasePart}`;
|
||||
}
|
||||
|
||||
export function parseGoVersionFile(contents: string, isMod: boolean): string {
|
||||
if (!isMod) {
|
||||
return contents.trim();
|
||||
}
|
||||
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
|
|
27
src/main.ts
27
src/main.ts
|
@ -12,14 +12,7 @@ export async function run() {
|
|||
// versionSpec is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||
//
|
||||
const versionFilePath = core.getInput('go-version-from-file');
|
||||
const versionSpecFromFile =
|
||||
versionFilePath &&
|
||||
fs
|
||||
.readFileSync(versionFilePath)
|
||||
.toString()
|
||||
.trim();
|
||||
let versionSpec = core.getInput('go-version') || versionSpecFromFile;
|
||||
const versionSpec = resolveVersionInput();
|
||||
|
||||
// stable will be true unless false is the exact input
|
||||
// since getting unstable versions should be explicit
|
||||
|
@ -97,3 +90,21 @@ function isGhes(): boolean {
|
|||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('go-version');
|
||||
const versionFilePath = core.getInput('go-version-file');
|
||||
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (versionFilePath) {
|
||||
version = installer.parseGoVersionFile(
|
||||
fs.readFileSync(versionFilePath).toString(),
|
||||
path.basename(versionFilePath) === 'go.mod'
|
||||
);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue