mirror of
https://gitea.com/actions/setup-maven.git
synced 2025-11-09 02:56:20 +08:00
draft
This commit is contained in:
47
src/installer.ts
Normal file
47
src/installer.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// Load tempDirectory before it gets wiped by tool-cache
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as path from 'path';
|
||||
|
||||
if (!tempDirectory) {
|
||||
let baseLocation: string;
|
||||
if (process.platform === 'win32') {
|
||||
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
||||
} else {
|
||||
if (process.platform === 'darwin') {
|
||||
baseLocation = '/Users';
|
||||
} else {
|
||||
baseLocation = '/home';
|
||||
}
|
||||
}
|
||||
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
||||
}
|
||||
|
||||
export async function getMaven(version: string) {
|
||||
let toolPath: string;
|
||||
toolPath = tc.find('maven', version);
|
||||
|
||||
if (!toolPath) {
|
||||
toolPath = await downloadMaven(version);
|
||||
}
|
||||
|
||||
toolPath = path.join(toolPath, 'bin');
|
||||
core.addPath(toolPath);
|
||||
}
|
||||
|
||||
async function downloadMaven(version: string): Promise<string> {
|
||||
const toolDirectoryName = 'apache-maven-${version}';
|
||||
const downloadUrl =
|
||||
'https://www-eu.apache.org/dist/maven/maven-3/${version}/binaries/${toolDirectoryName}-bin.tar.gz';
|
||||
|
||||
try {
|
||||
const downloadPath = await tc.downloadTool(downloadUrl);
|
||||
const extractedPath = await tc.extractTar(downloadPath);
|
||||
let toolRoot = path.join(extractedPath, toolDirectoryName);
|
||||
return await tc.cacheDir(toolRoot, 'maven', version);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
15
src/setup-maven.ts
Normal file
15
src/setup-maven.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as installer from './installer';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
let version = core.getInput('maven-version');
|
||||
if (version) {
|
||||
await installer.getMaven(version);
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user