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:
parent
193b404f8a
commit
265edc1beb
8 changed files with 179 additions and 3 deletions
28
src/main.ts
28
src/main.ts
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue