1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-go synced 2025-06-08 19:48:21 +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

@ -13,7 +13,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.
//
let versionSpec = core.getInput('go-version');
const versionSpec = resolveVersionInput();
core.info(`Setup go version spec ${versionSpec}`);
@ -104,3 +104,29 @@ export function parseGoVersion(versionString: string): string {
// expecting go<version> for runtime.Version()
return versionString.split(' ')[2].slice('go'.length);
}
function resolveVersionInput(): string {
let version = core.getInput('go-version');
const 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'
);
}
if (version) {
return version;
}
if (versionFilePath) {
if (!fs.existsSync(versionFilePath)) {
throw new Error(
`The specified go version file at: ${versionFilePath} does not exist`
);
}
version = installer.parseGoVersionFile(versionFilePath);
}
return version;
}