setup-maven/src/utils.ts
2022-08-02 18:09:12 +07:00

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;
}