-
Notifications
You must be signed in to change notification settings - Fork 66
/
installer.ts
48 lines (41 loc) · 1.39 KB
/
installer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${version}/apache-maven-${version}-bin.tar.gz`
console.log(`downloading ${downloadUrl}`)
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
}
}