|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 12 | + if (mod && mod.__esModule) return mod; |
| 13 | + var result = {}; |
| 14 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 15 | + result["default"] = mod; |
| 16 | + return result; |
| 17 | +}; |
| 18 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 19 | +let tempDirectory = process.env['RUNNER_TEMP'] || ''; |
| 20 | +const core = __importStar(require("@actions/core")); |
| 21 | +const io = __importStar(require("@actions/io")); |
| 22 | +const exec = __importStar(require("@actions/exec")); |
| 23 | +const tc = __importStar(require("@actions/tool-cache")); |
| 24 | +const fs = __importStar(require("fs")); |
| 25 | +const path = __importStar(require("path")); |
| 26 | +const os = __importStar(require("os")); |
| 27 | +const IS_WINDOWS = process.platform === 'win32'; |
| 28 | +if (!tempDirectory) { |
| 29 | + let baseLocation; |
| 30 | + if (IS_WINDOWS) { |
| 31 | + baseLocation = process.env['USERPROFILE'] || 'C:\\'; |
| 32 | + } |
| 33 | + else { |
| 34 | + if (process.platform === 'darwin') { |
| 35 | + baseLocation = '/Users'; |
| 36 | + } |
| 37 | + else { |
| 38 | + baseLocation = '/home'; |
| 39 | + } |
| 40 | + } |
| 41 | + tempDirectory = path.join(baseLocation, 'actions', 'temp'); |
| 42 | +} |
| 43 | +let platform = ''; |
| 44 | +if (IS_WINDOWS) { |
| 45 | + platform = 'windows'; |
| 46 | +} |
| 47 | +else { |
| 48 | + if (process.platform === 'darwin') { |
| 49 | + platform = 'darwin'; |
| 50 | + } |
| 51 | + else { |
| 52 | + platform = 'linux'; |
| 53 | + } |
| 54 | +} |
| 55 | +function getGraalVM(version) { |
| 56 | + return __awaiter(this, void 0, void 0, function* () { |
| 57 | + let toolPath = tc.find('GraalVM', getCacheVersionString(version), os.arch()); |
| 58 | + let compressedFileExtension = ''; |
| 59 | + if (toolPath) { |
| 60 | + core.debug(`GraalVM found in cache ${toolPath}`); |
| 61 | + } |
| 62 | + else { |
| 63 | + core.debug('Downloading GraalVM from https://github.com/oracle/graal/releases'); |
| 64 | + compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; |
| 65 | + let graalvmFile = yield tc.downloadTool(`https://github.com/oracle/graal/releases/download/vm-${version}/graalvm-ce-${platform}-amd64-${version}${compressedFileExtension}`); |
| 66 | + let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000)); |
| 67 | + const graalvmDir = yield unzipGraalVMDownload(graalvmFile, compressedFileExtension, tempDir); |
| 68 | + core.debug(`graalvm extracted to ${graalvmDir}`); |
| 69 | + toolPath = yield tc.cacheDir(graalvmDir, 'GraalVM', getCacheVersionString(version)); |
| 70 | + } |
| 71 | + let extendedJavaHome = 'JAVA_HOME_' + version; |
| 72 | + core.exportVariable('JAVA_HOME', toolPath); |
| 73 | + core.exportVariable(extendedJavaHome, toolPath); |
| 74 | + core.addPath(path.join(toolPath, 'bin')); |
| 75 | + }); |
| 76 | +} |
| 77 | +exports.getGraalVM = getGraalVM; |
| 78 | +function getCacheVersionString(version) { |
| 79 | + const versionArray = version.split('.'); |
| 80 | + const major = versionArray[0]; |
| 81 | + const minor = versionArray.length > 1 ? versionArray[1] : '0'; |
| 82 | + const patch = versionArray.length > 2 ? versionArray.slice(2).join('-') : '0'; |
| 83 | + return `${major}.${minor}.${patch}`; |
| 84 | +} |
| 85 | +function extractFiles(file, fileEnding, destinationFolder) { |
| 86 | + return __awaiter(this, void 0, void 0, function* () { |
| 87 | + const stats = fs.statSync(file); |
| 88 | + if (!stats) { |
| 89 | + throw new Error(`Failed to extract ${file} - it doesn't exist`); |
| 90 | + } |
| 91 | + else if (stats.isDirectory()) { |
| 92 | + throw new Error(`Failed to extract ${file} - it is a directory`); |
| 93 | + } |
| 94 | + if ('.tar.gz' === fileEnding) { |
| 95 | + yield tc.extractTar(file, destinationFolder); |
| 96 | + } |
| 97 | + else if ('.zip' === fileEnding) { |
| 98 | + yield tc.extractZip(file, destinationFolder); |
| 99 | + } |
| 100 | + }); |
| 101 | +} |
| 102 | +function unpackJars(fsPath, javaBinPath) { |
| 103 | + return __awaiter(this, void 0, void 0, function* () { |
| 104 | + if (fs.existsSync(fsPath)) { |
| 105 | + if (fs.lstatSync(fsPath).isDirectory()) { |
| 106 | + for (const file in fs.readdirSync(fsPath)) { |
| 107 | + const curPath = path.join(fsPath, file); |
| 108 | + yield unpackJars(curPath, javaBinPath); |
| 109 | + } |
| 110 | + } |
| 111 | + else if (path.extname(fsPath).toLowerCase() === '.pack') { |
| 112 | + // Unpack the pack file synchonously |
| 113 | + const p = path.parse(fsPath); |
| 114 | + const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200'; |
| 115 | + const args = IS_WINDOWS ? '-r -v -l ""' : ''; |
| 116 | + const name = path.join(p.dir, p.name); |
| 117 | + yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [ |
| 118 | + `${args} "${name}.pack" "${name}.jar"` |
| 119 | + ]); |
| 120 | + } |
| 121 | + } |
| 122 | + }); |
| 123 | +} |
| 124 | +function unzipGraalVMDownload(repoRoot, fileEnding, destinationFolder) { |
| 125 | + return __awaiter(this, void 0, void 0, function* () { |
| 126 | + yield io.mkdirP(destinationFolder); |
| 127 | + const graalvmFile = path.normalize(repoRoot); |
| 128 | + const stats = fs.statSync(graalvmFile); |
| 129 | + if (stats.isFile()) { |
| 130 | + yield extractFiles(graalvmFile, fileEnding, destinationFolder); |
| 131 | + const graalvmFolder = fs.readdirSync(destinationFolder)[0]; |
| 132 | + if (process.platform === 'darwin') { |
| 133 | + for (const f of fs.readdirSync(path.join(destinationFolder, graalvmFolder, 'Contents', 'Home'))) { |
| 134 | + yield io.cp(path.join(destinationFolder, graalvmFolder, 'Contents', 'Home', f), path.join(destinationFolder, graalvmFolder, f), { recursive: true }); |
| 135 | + } |
| 136 | + yield io.rmRF(path.join(destinationFolder, graalvmFolder, 'Contents')); |
| 137 | + } |
| 138 | + const graalvmDirectory = path.join(destinationFolder, graalvmFolder); |
| 139 | + yield unpackJars(graalvmDirectory, path.join(graalvmDirectory, 'bin')); |
| 140 | + return graalvmDirectory; |
| 141 | + } |
| 142 | + else { |
| 143 | + throw new Error(`Jdk argument ${graalvmFile} is not a file`); |
| 144 | + } |
| 145 | + }); |
| 146 | +} |
0 commit comments