mirror of
https://github.com/stCarolas/setup-maven.git
synced 2026-03-20 10:12:31 +00:00
28 lines
803 B
TypeScript
28 lines
803 B
TypeScript
import * as path from 'path';
|
|
|
|
import * as core from '@actions/core';
|
|
import * as exec from '@actions/exec';
|
|
|
|
export function getVersionFromToolcachePath(toolPath: string): string {
|
|
return !toolPath ? toolPath : path.basename(path.dirname(toolPath));
|
|
}
|
|
|
|
/**
|
|
* Determine version of the current used Maven.
|
|
*/
|
|
export async function getActiveMavenVersion(): Promise<string | undefined> {
|
|
try {
|
|
const { stdout } = await exec.getExecOutput('mvn', ['-v'], { silent: true });
|
|
|
|
const found = /^[^\d]*(\d\S*)/.exec(stdout);
|
|
const installedVersion = !found ? '' : found[1];
|
|
core.debug(`Retrieved activated Maven version: ${installedVersion}`);
|
|
|
|
return installedVersion;
|
|
} catch (err) {
|
|
core.info(`Failed to get activated Maven version. ${String(err)}`);
|
|
}
|
|
|
|
return undefined;
|
|
}
|