|
| 1 | +"use strict"; |
| 2 | +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 | + if (k2 === undefined) k2 = k; |
| 4 | + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); |
| 5 | +}) : (function(o, m, k, k2) { |
| 6 | + if (k2 === undefined) k2 = k; |
| 7 | + o[k2] = m[k]; |
| 8 | +})); |
| 9 | +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 10 | + Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 11 | +}) : function(o, v) { |
| 12 | + o["default"] = v; |
| 13 | +}); |
| 14 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 15 | + if (mod && mod.__esModule) return mod; |
| 16 | + var result = {}; |
| 17 | + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
| 18 | + __setModuleDefault(result, mod); |
| 19 | + return result; |
| 20 | +}; |
| 21 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 22 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 23 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 24 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 25 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 26 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 27 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 28 | + }); |
| 29 | +}; |
| 30 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 31 | +exports.install = void 0; |
| 32 | +const core = __importStar(require("@actions/core")); |
| 33 | +const shell = __importStar(require("shelljs")); |
| 34 | +const path = __importStar(require("path")); |
| 35 | +const homedir = require("os").homedir(); |
| 36 | +const bin = path.join(homedir, "bin"); |
| 37 | +function install(javaVersion, jabbaVersion) { |
| 38 | + return __awaiter(this, void 0, void 0, function* () { |
| 39 | + setEnvironmentVariableCI(); |
| 40 | + installJava(javaVersion, jabbaVersion); |
| 41 | + installSbt(); |
| 42 | + }); |
| 43 | +} |
| 44 | +exports.install = install; |
| 45 | +function setEnvironmentVariableCI() { |
| 46 | + core.exportVariable("CI", "true"); |
| 47 | +} |
| 48 | +function jabbaUrlSuffix() { |
| 49 | + const runnerOs = shell.env["RUNNER_OS"] || "undefined"; |
| 50 | + switch (runnerOs.toLowerCase()) { |
| 51 | + case "linux": |
| 52 | + const arch = shell.exec("uname -m", { silent: true }).stdout; |
| 53 | + switch (arch) { |
| 54 | + case "arm64": |
| 55 | + case "aarch64": |
| 56 | + return "linux-arm64"; |
| 57 | + default: |
| 58 | + return "linux-amd64"; |
| 59 | + } |
| 60 | + case "macos": |
| 61 | + return "darwin-amd64"; |
| 62 | + case "windows": |
| 63 | + return "windows-amd64.exe"; |
| 64 | + default: |
| 65 | + throw new Error(`unknown runner OS: ${runnerOs}, expected one of Linux, macOS or Windows.`); |
| 66 | + } |
| 67 | +} |
| 68 | +function isWindows() { |
| 69 | + return shell.env["RUNNER_OS"] === "Windows"; |
| 70 | +} |
| 71 | +function jabbaName() { |
| 72 | + if (isWindows()) |
| 73 | + return "jabba.exe"; |
| 74 | + else |
| 75 | + return "jabba"; |
| 76 | +} |
| 77 | +function installJava(javaVersion, jabbaVersion) { |
| 78 | + core.startGroup("Install Java"); |
| 79 | + core.addPath(bin); |
| 80 | + const jabbaUrl = `https://github.com/shyiko/jabba/releases/download/${jabbaVersion}/jabba-${jabbaVersion}-${jabbaUrlSuffix()}`; |
| 81 | + shell.mkdir(bin); |
| 82 | + const jabba = path.join(bin, jabbaName()); |
| 83 | + shell.set("-ev"); |
| 84 | + shell.exec(`curl -sL -o ${jabba} ${jabbaUrl}`, { silent: true }); |
| 85 | + shell.chmod(755, jabba); |
| 86 | + const jabbaInstall = javaVersion.includes("=") |
| 87 | + ? installJavaByExactVersion(javaVersion) |
| 88 | + : installJavaByFuzzyVersion(jabba, javaVersion); |
| 89 | + if (!jabbaInstall) |
| 90 | + return; |
| 91 | + console.log(`Installing ${jabbaInstall.name}`); |
| 92 | + const result = shell.exec(`${jabba} install ${jabbaInstall.install}`); |
| 93 | + if (result.code > 0) { |
| 94 | + core.setFailed(`Failed to install Java ${javaVersion}, Jabba stderr: ${result.stderr}`); |
| 95 | + return; |
| 96 | + } |
| 97 | + const javaHome = shell |
| 98 | + .exec(`${jabba} which --home ${jabbaInstall.name}`) |
| 99 | + .stdout.trim(); |
| 100 | + core.exportVariable("JAVA_HOME", javaHome); |
| 101 | + core.addPath(path.join(javaHome, "bin")); |
| 102 | + core.endGroup(); |
| 103 | +} |
| 104 | +function installJavaByFuzzyVersion(jabba, javaVersion) { |
| 105 | + const toInstall = shell |
| 106 | + .exec(`${jabba} ls-remote`) |
| 107 | + .grep(javaVersion) |
| 108 | + .head({ "-n": 1 }) |
| 109 | + .stdout.trim(); |
| 110 | + if (!toInstall) { |
| 111 | + core.setFailed(`Couldn't find Java ${javaVersion}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.`); |
| 112 | + return; |
| 113 | + } |
| 114 | + return { |
| 115 | + name: toInstall, |
| 116 | + install: toInstall, |
| 117 | + }; |
| 118 | +} |
| 119 | +function installJavaByExactVersion(javaVersion) { |
| 120 | + return { |
| 121 | + name: javaVersion.split("=")[0], |
| 122 | + install: javaVersion, |
| 123 | + }; |
| 124 | +} |
| 125 | +function installSbt() { |
| 126 | + core.startGroup("Install sbt"); |
| 127 | + core.addPath(bin); |
| 128 | + curl("https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt", path.join(bin, "sbt")); |
| 129 | + curl("https://raw.githubusercontent.com/coursier/sbt-extras/master/sbt", path.join(bin, "csbt")); |
| 130 | + core.endGroup(); |
| 131 | +} |
| 132 | +function curl(url, outputFile) { |
| 133 | + shell.exec(`curl -sL ${url}`, { silent: true }).to(outputFile); |
| 134 | + shell.chmod(755, outputFile); |
| 135 | + shell.cat(outputFile); |
| 136 | + console.log(`Downloaded '${path.basename(outputFile)}' to ${outputFile}`); |
| 137 | +} |
0 commit comments