From 4158eb5def5049d4ad611291c199da04567a261e Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 15:52:00 -0500 Subject: [PATCH 01/12] Switch JAVA_HOME to 21 for JRuby JRuby 10 requires Java 21. Since the previous default was 17 and all JRuby releases should work fine on 21, we do this for all JRuby installs. Implements #718 --- common.js | 4 ++++ ruby-builder.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/common.js b/common.js index 99a7b71e2..a366e3a4d 100644 --- a/common.js +++ b/common.js @@ -403,3 +403,7 @@ export function setupPath(newPathEntries) { core.addPath(newPath.join(path.delimiter)) return msys2Type } + +export function setupJavaHome() { + core.exportVariable("JAVA_HOME", process.env[`JAVA_HOME_21_${os.arch().toUpperCase()}`]); +} diff --git a/ruby-builder.js b/ruby-builder.js index 985ad2c86..74d56b224 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -49,6 +49,10 @@ export async function install(platform, engine, version) { // Set the PATH now, so the MSYS2 'tar' is in Path on Windows common.setupPath([path.join(rubyPrefix, 'bin')]) + if (engine == "jruby") { + common.setupJavaHome(); + } + if (!inToolCache) { await io.mkdirP(rubyPrefix) await downloadAndExtract(platform, engine, version, rubyPrefix) From ef749c32fa90c5997f4cd92501557fa61e8ff67a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 16:04:02 -0500 Subject: [PATCH 02/12] Add group and logging to JAVA_HOME setup --- common.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common.js b/common.js index a366e3a4d..3cbc792c0 100644 --- a/common.js +++ b/common.js @@ -405,5 +405,10 @@ export function setupPath(newPathEntries) { } export function setupJavaHome() { - core.exportVariable("JAVA_HOME", process.env[`JAVA_HOME_21_${os.arch().toUpperCase()}`]); + core.startGroup(`Modifying JAVA_HOME for JRuby`) + let newHomeVar = `JAVA_HOME_21_${os.arch().toUpperCase()}`; + let newHome = process.env[newHomeVar]; + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome); + core.endGroup() } From 745e0101e1038af56034c3c5bff95750beca7a0a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 16:05:46 -0500 Subject: [PATCH 03/12] Generate index from updated setup --- dist/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 1762cf830..9940618cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -315,7 +315,8 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "toolCacheCompleteFile": () => (/* binding */ toolCacheCompleteFile), /* harmony export */ "createToolCacheCompleteFile": () => (/* binding */ createToolCacheCompleteFile), /* harmony export */ "win2nix": () => (/* binding */ win2nix), -/* harmony export */ "setupPath": () => (/* binding */ setupPath) +/* harmony export */ "setupPath": () => (/* binding */ setupPath), +/* harmony export */ "setupJavaHome": () => (/* binding */ setupJavaHome) /* harmony export */ }); const os = __nccwpck_require__(2037) const path = __nccwpck_require__(1017) @@ -723,6 +724,15 @@ function setupPath(newPathEntries) { return msys2Type } +function setupJavaHome() { + core.startGroup(`Modifying JAVA_HOME for JRuby`) + let newHomeVar = `JAVA_HOME_21_${os.arch().toUpperCase()}`; + let newHome = process.env[newHomeVar]; + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome); + core.endGroup() +} + /***/ }), @@ -74052,6 +74062,10 @@ async function install(platform, engine, version) { // Set the PATH now, so the MSYS2 'tar' is in Path on Windows common.setupPath([path.join(rubyPrefix, 'bin')]) + if (engine == "jruby") { + common.setupJavaHome(); + } + if (!inToolCache) { await io.mkdirP(rubyPrefix) await downloadAndExtract(platform, engine, version, rubyPrefix) From ef40e17bd0adf86f3da1fa00f2c69b29180b18fa Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 16:16:05 -0500 Subject: [PATCH 04/12] Only upcase x64 platform The JAVA_HOME_* variables use 'arm64' on ARM. --- common.js | 6 +++++- dist/index.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common.js b/common.js index 3cbc792c0..b8a9e84c1 100644 --- a/common.js +++ b/common.js @@ -406,7 +406,11 @@ export function setupPath(newPathEntries) { export function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) - let newHomeVar = `JAVA_HOME_21_${os.arch().toUpperCase()}`; + let arch = os.arch(); + if (arch == "x64") { + arch = "X64" + } + let newHomeVar = `JAVA_HOME_21_${arch}`; let newHome = process.env[newHomeVar]; console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) core.exportVariable("JAVA_HOME", newHome); diff --git a/dist/index.js b/dist/index.js index 9940618cc..45ddfd974 100644 --- a/dist/index.js +++ b/dist/index.js @@ -726,7 +726,11 @@ function setupPath(newPathEntries) { function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) - let newHomeVar = `JAVA_HOME_21_${os.arch().toUpperCase()}`; + let arch = os.arch(); + if (arch == "x64") { + arch = "X64" + } + let newHomeVar = `JAVA_HOME_21_${arch}`; let newHome = process.env[newHomeVar]; console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) core.exportVariable("JAVA_HOME", newHome); From efa9afc92eeca5e5209c1b756f3f3ea0552ab820 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 16:24:49 -0500 Subject: [PATCH 05/12] Use 'X64' variable everywhere except macos --- common.js | 2 +- dist/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common.js b/common.js index b8a9e84c1..e19c2a570 100644 --- a/common.js +++ b/common.js @@ -407,7 +407,7 @@ export function setupPath(newPathEntries) { export function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) let arch = os.arch(); - if (arch == "x64") { + if (arch == "x64" || os.platform() != "darwin") { arch = "X64" } let newHomeVar = `JAVA_HOME_21_${arch}`; diff --git a/dist/index.js b/dist/index.js index 45ddfd974..407d04e34 100644 --- a/dist/index.js +++ b/dist/index.js @@ -727,7 +727,7 @@ function setupPath(newPathEntries) { function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) let arch = os.arch(); - if (arch == "x64") { + if (arch == "x64" || os.platform() != "darwin") { arch = "X64" } let newHomeVar = `JAVA_HOME_21_${arch}`; From 2502fcd16d01d939a7e681af17509a48fd577aed Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 16:55:06 -0500 Subject: [PATCH 06/12] Only change JAVA_HOME if JRuby fails to start --- common.js | 32 +++++++++++++++++++++------- dist/index.js | 56 +++++++++++++++++++++++++++++++++++++------------ index.js | 4 ++++ ruby-builder.js | 4 ---- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/common.js b/common.js index e19c2a570..2f5c1d3ee 100644 --- a/common.js +++ b/common.js @@ -1,3 +1,5 @@ +import exec from "@actions/exec"; + const os = require('os') const path = require('path') const fs = require('fs') @@ -404,15 +406,29 @@ export function setupPath(newPathEntries) { return msys2Type } -export function setupJavaHome() { +export async function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) - let arch = os.arch(); - if (arch == "x64" || os.platform() != "darwin") { - arch = "X64" + + console.log("attempting to run with existing JAVA_HOME") + let ret = await exec.exec('ruby', ['--version']); + + if (ret === 0) { + console.log("JRuby successfully starts, using existing JAVA_HOME") + } else { + console.log("JRuby failed to start, try Java 21 envs") + let arch = os.arch(); + if (arch == "x64" || os.platform() != "darwin") { + arch = "X64" + } + let newHomeVar = `JAVA_HOME_21_${arch}`; + let newHome = process.env[newHomeVar]; + + if (newHome === "undefined") { + throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) + } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome) } - let newHomeVar = `JAVA_HOME_21_${arch}`; - let newHome = process.env[newHomeVar]; - console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) - core.exportVariable("JAVA_HOME", newHome); + core.endGroup() } diff --git a/dist/index.js b/dist/index.js index 407d04e34..963ac212d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -318,6 +318,10 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "setupPath": () => (/* binding */ setupPath), /* harmony export */ "setupJavaHome": () => (/* binding */ setupJavaHome) /* harmony export */ }); +/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(1514); +/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_0__); + + const os = __nccwpck_require__(2037) const path = __nccwpck_require__(1017) const fs = __nccwpck_require__(7147) @@ -724,16 +728,30 @@ function setupPath(newPathEntries) { return msys2Type } -function setupJavaHome() { +async function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) - let arch = os.arch(); - if (arch == "x64" || os.platform() != "darwin") { - arch = "X64" - } - let newHomeVar = `JAVA_HOME_21_${arch}`; - let newHome = process.env[newHomeVar]; - console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) - core.exportVariable("JAVA_HOME", newHome); + + console.log("attempting to run with existing JAVA_HOME") + let ret = await _actions_exec__WEBPACK_IMPORTED_MODULE_0___default().exec('ruby', ['--version']); + + if (ret === 0) { + console.log("JRuby successfully starts, using existing JAVA_HOME") + } else { + console.log("JRuby failed to start, try Java 21 envs") + let arch = os.arch(); + if (arch == "x64" || os.platform() != "darwin") { + arch = "X64" + } + let newHomeVar = `JAVA_HOME_21_${arch}`; + let newHome = process.env[newHomeVar]; + + if (newHome === "undefined") { + throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) + } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome) + } + core.endGroup() } @@ -74066,10 +74084,6 @@ async function install(platform, engine, version) { // Set the PATH now, so the MSYS2 'tar' is in Path on Windows common.setupPath([path.join(rubyPrefix, 'bin')]) - if (engine == "jruby") { - common.setupJavaHome(); - } - if (!inToolCache) { await io.mkdirP(rubyPrefix) await downloadAndExtract(platform, engine, version, rubyPrefix) @@ -74777,6 +74791,18 @@ module.exports = JSON.parse('{"2.0.0":"https://github.com/oneclick/rubyinstaller /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __nccwpck_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __nccwpck_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports @@ -74900,6 +74926,10 @@ async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) + if (engine == "jruby") { + await common.setupJavaHome(); + } + await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) diff --git a/index.js b/index.js index 1bba0a4be..e47ec4693 100644 --- a/index.js +++ b/index.js @@ -79,6 +79,10 @@ export async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) + if (engine == "jruby") { + await common.setupJavaHome(); + } + await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) diff --git a/ruby-builder.js b/ruby-builder.js index 74d56b224..985ad2c86 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -49,10 +49,6 @@ export async function install(platform, engine, version) { // Set the PATH now, so the MSYS2 'tar' is in Path on Windows common.setupPath([path.join(rubyPrefix, 'bin')]) - if (engine == "jruby") { - common.setupJavaHome(); - } - if (!inToolCache) { await io.mkdirP(rubyPrefix) await downloadAndExtract(platform, engine, version, rubyPrefix) From 7ffdbb4db7cfec1b1b193307bc01a1fde32b29c0 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 17:00:53 -0500 Subject: [PATCH 07/12] Cleanup based on review --- common.js | 13 +++++++++---- dist/index.js | 17 +++++++++++------ index.js | 4 ++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/common.js b/common.js index 2f5c1d3ee..e1039ef82 100644 --- a/common.js +++ b/common.js @@ -410,23 +410,28 @@ export async function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) console.log("attempting to run with existing JAVA_HOME") - let ret = await exec.exec('ruby', ['--version']); + + let ret = await exec.exec('ruby', ['--version']) if (ret === 0) { console.log("JRuby successfully starts, using existing JAVA_HOME") } else { console.log("JRuby failed to start, try Java 21 envs") + let arch = os.arch(); - if (arch == "x64" || os.platform() != "darwin") { + if (arch === "x64" || os.platform() !== "darwin") { arch = "X64" } - let newHomeVar = `JAVA_HOME_21_${arch}`; - let newHome = process.env[newHomeVar]; + + let newHomeVar = `JAVA_HOME_21_${arch}` + let newHome = process.env[newHomeVar] if (newHome === "undefined") { throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome) } diff --git a/dist/index.js b/dist/index.js index 963ac212d..7500a07a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -732,23 +732,28 @@ async function setupJavaHome() { core.startGroup(`Modifying JAVA_HOME for JRuby`) console.log("attempting to run with existing JAVA_HOME") - let ret = await _actions_exec__WEBPACK_IMPORTED_MODULE_0___default().exec('ruby', ['--version']); + + let ret = await _actions_exec__WEBPACK_IMPORTED_MODULE_0___default().exec('ruby', ['--version']) if (ret === 0) { console.log("JRuby successfully starts, using existing JAVA_HOME") } else { console.log("JRuby failed to start, try Java 21 envs") + let arch = os.arch(); - if (arch == "x64" || os.platform() != "darwin") { + if (arch === "x64" || os.platform() !== "darwin") { arch = "X64" } - let newHomeVar = `JAVA_HOME_21_${arch}`; - let newHome = process.env[newHomeVar]; + + let newHomeVar = `JAVA_HOME_21_${arch}` + let newHome = process.env[newHomeVar] if (newHome === "undefined") { throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + core.exportVariable("JAVA_HOME", newHome) } @@ -74926,8 +74931,8 @@ async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) - if (engine == "jruby") { - await common.setupJavaHome(); + if (engine === "jruby") { + await common.setupJavaHome() } await common.measure('Print Ruby version', async () => diff --git a/index.js b/index.js index e47ec4693..bd92b9140 100644 --- a/index.js +++ b/index.js @@ -79,8 +79,8 @@ export async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) - if (engine == "jruby") { - await common.setupJavaHome(); + if (engine === "jruby") { + await common.setupJavaHome() } await common.measure('Print Ruby version', async () => From f3baf96b8059cbd488365d869ad3dd9350ffecf7 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 11 Mar 2025 17:18:34 -0500 Subject: [PATCH 08/12] Set up exec constant for JRuby check --- common.js | 3 +-- dist/index.js | 19 ++----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/common.js b/common.js index e1039ef82..8451b4364 100644 --- a/common.js +++ b/common.js @@ -1,5 +1,3 @@ -import exec from "@actions/exec"; - const os = require('os') const path = require('path') const fs = require('fs') @@ -8,6 +6,7 @@ const stream = require('stream') const crypto = require('crypto') const core = require('@actions/core') const tc = require('@actions/tool-cache') +const exec = require('@actions/exec') const { performance } = require('perf_hooks') const linuxOSInfo = require('linux-os-info') diff --git a/dist/index.js b/dist/index.js index 7500a07a7..ddf34be7a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -318,10 +318,6 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "setupPath": () => (/* binding */ setupPath), /* harmony export */ "setupJavaHome": () => (/* binding */ setupJavaHome) /* harmony export */ }); -/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(1514); -/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_0__); - - const os = __nccwpck_require__(2037) const path = __nccwpck_require__(1017) const fs = __nccwpck_require__(7147) @@ -330,6 +326,7 @@ const stream = __nccwpck_require__(2781) const crypto = __nccwpck_require__(6113) const core = __nccwpck_require__(2186) const tc = __nccwpck_require__(7784) +const exec = __nccwpck_require__(1514) const { performance } = __nccwpck_require__(4074) const linuxOSInfo = __nccwpck_require__(8487) @@ -733,7 +730,7 @@ async function setupJavaHome() { console.log("attempting to run with existing JAVA_HOME") - let ret = await _actions_exec__WEBPACK_IMPORTED_MODULE_0___default().exec('ruby', ['--version']) + let ret = await exec.exec('ruby', ['--version']) if (ret === 0) { console.log("JRuby successfully starts, using existing JAVA_HOME") @@ -74796,18 +74793,6 @@ module.exports = JSON.parse('{"2.0.0":"https://github.com/oneclick/rubyinstaller /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __nccwpck_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __nccwpck_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports From 5c0bbf74310f29f84c0f040facd7af8f7fb19086 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 12 Mar 2025 11:30:47 -0500 Subject: [PATCH 09/12] Move JAVA_HOME setup into install --- dist/index.js | 9 +++++---- index.js | 4 ---- ruby-builder.js | 5 +++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index ddf34be7a..8c346b7b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74091,6 +74091,11 @@ async function install(platform, engine, version) { await downloadAndExtract(platform, engine, version, rubyPrefix) } + // Ensure JRuby has minimum Java version to run + if (engine === "jruby") { + await common.setupJavaHome() + } + return rubyPrefix } @@ -74916,10 +74921,6 @@ async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) - if (engine === "jruby") { - await common.setupJavaHome() - } - await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) diff --git a/index.js b/index.js index bd92b9140..1bba0a4be 100644 --- a/index.js +++ b/index.js @@ -79,10 +79,6 @@ export async function setupRuby(options = {}) { const rubyPrefix = await installer.install(platform, engine, version) - if (engine === "jruby") { - await common.setupJavaHome() - } - await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) diff --git a/ruby-builder.js b/ruby-builder.js index 985ad2c86..6ec7e191d 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -54,6 +54,11 @@ export async function install(platform, engine, version) { await downloadAndExtract(platform, engine, version, rubyPrefix) } + // Ensure JRuby has minimum Java version to run + if (engine === "jruby") { + await common.setupJavaHome() + } + return rubyPrefix } From 2e82a486164290038ff951687986637efb5c35f9 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 12 Mar 2025 11:43:51 -0500 Subject: [PATCH 10/12] Clean up rogue semicolon --- common.js | 2 +- dist/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common.js b/common.js index 8451b4364..f4418ad14 100644 --- a/common.js +++ b/common.js @@ -417,7 +417,7 @@ export async function setupJavaHome() { } else { console.log("JRuby failed to start, try Java 21 envs") - let arch = os.arch(); + let arch = os.arch() if (arch === "x64" || os.platform() !== "darwin") { arch = "X64" } diff --git a/dist/index.js b/dist/index.js index 8c346b7b5..d44f7b40c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -737,7 +737,7 @@ async function setupJavaHome() { } else { console.log("JRuby failed to start, try Java 21 envs") - let arch = os.arch(); + let arch = os.arch() if (arch === "x64" || os.platform() !== "darwin") { arch = "X64" } From dad12fe36c92f7a93c81a868e551902530385fd0 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 12 Mar 2025 11:45:29 -0500 Subject: [PATCH 11/12] Use measure to track JAVA_HOME setup time --- common.js | 43 +++++++++++++++++++++---------------------- dist/index.js | 43 +++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/common.js b/common.js index f4418ad14..ee8d22aa3 100644 --- a/common.js +++ b/common.js @@ -7,6 +7,7 @@ const crypto = require('crypto') const core = require('@actions/core') const tc = require('@actions/tool-cache') const exec = require('@actions/exec') +const common = require('./common') const { performance } = require('perf_hooks') const linuxOSInfo = require('linux-os-info') @@ -406,33 +407,31 @@ export function setupPath(newPathEntries) { } export async function setupJavaHome() { - core.startGroup(`Modifying JAVA_HOME for JRuby`) + common.measure("Modifying JAVA_HOME for JRuby", async () => { + console.log("attempting to run with existing JAVA_HOME") - console.log("attempting to run with existing JAVA_HOME") + let ret = await exec.exec('ruby', ['--version']) - let ret = await exec.exec('ruby', ['--version']) + if (ret === 0) { + console.log("JRuby successfully starts, using existing JAVA_HOME") + } else { + console.log("JRuby failed to start, try Java 21 envs") - if (ret === 0) { - console.log("JRuby successfully starts, using existing JAVA_HOME") - } else { - console.log("JRuby failed to start, try Java 21 envs") - - let arch = os.arch() - if (arch === "x64" || os.platform() !== "darwin") { - arch = "X64" - } - - let newHomeVar = `JAVA_HOME_21_${arch}` - let newHome = process.env[newHomeVar] + let arch = os.arch() + if (arch === "x64" || os.platform() !== "darwin") { + arch = "X64" + } - if (newHome === "undefined") { - throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) - } + let newHomeVar = `JAVA_HOME_21_${arch}` + let newHome = process.env[newHomeVar] - console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + if (newHome === "undefined") { + throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) + } - core.exportVariable("JAVA_HOME", newHome) - } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) - core.endGroup() + core.exportVariable("JAVA_HOME", newHome) + } + }) } diff --git a/dist/index.js b/dist/index.js index d44f7b40c..43e831941 100644 --- a/dist/index.js +++ b/dist/index.js @@ -327,6 +327,7 @@ const crypto = __nccwpck_require__(6113) const core = __nccwpck_require__(2186) const tc = __nccwpck_require__(7784) const exec = __nccwpck_require__(1514) +const common = __nccwpck_require__(4717) const { performance } = __nccwpck_require__(4074) const linuxOSInfo = __nccwpck_require__(8487) @@ -726,35 +727,33 @@ function setupPath(newPathEntries) { } async function setupJavaHome() { - core.startGroup(`Modifying JAVA_HOME for JRuby`) - - console.log("attempting to run with existing JAVA_HOME") + common.measure("Modifying JAVA_HOME for JRuby", async () => { + console.log("attempting to run with existing JAVA_HOME") - let ret = await exec.exec('ruby', ['--version']) + let ret = await exec.exec('ruby', ['--version']) - if (ret === 0) { - console.log("JRuby successfully starts, using existing JAVA_HOME") - } else { - console.log("JRuby failed to start, try Java 21 envs") + if (ret === 0) { + console.log("JRuby successfully starts, using existing JAVA_HOME") + } else { + console.log("JRuby failed to start, try Java 21 envs") - let arch = os.arch() - if (arch === "x64" || os.platform() !== "darwin") { - arch = "X64" - } + let arch = os.arch() + if (arch === "x64" || os.platform() !== "darwin") { + arch = "X64" + } - let newHomeVar = `JAVA_HOME_21_${arch}` - let newHome = process.env[newHomeVar] + let newHomeVar = `JAVA_HOME_21_${arch}` + let newHome = process.env[newHomeVar] - if (newHome === "undefined") { - throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) - } - - console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) + if (newHome === "undefined") { + throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`) + } - core.exportVariable("JAVA_HOME", newHome) - } + console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`) - core.endGroup() + core.exportVariable("JAVA_HOME", newHome) + } + }) } From 9b80b4df2c4550d18abb90a6287ceceadf38cabc Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 12 Mar 2025 21:03:46 +0100 Subject: [PATCH 12/12] Apply suggestions from code review --- common.js | 3 +-- dist/index.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common.js b/common.js index ee8d22aa3..f66798e44 100644 --- a/common.js +++ b/common.js @@ -7,7 +7,6 @@ const crypto = require('crypto') const core = require('@actions/core') const tc = require('@actions/tool-cache') const exec = require('@actions/exec') -const common = require('./common') const { performance } = require('perf_hooks') const linuxOSInfo = require('linux-os-info') @@ -407,7 +406,7 @@ export function setupPath(newPathEntries) { } export async function setupJavaHome() { - common.measure("Modifying JAVA_HOME for JRuby", async () => { + await measure("Modifying JAVA_HOME for JRuby", async () => { console.log("attempting to run with existing JAVA_HOME") let ret = await exec.exec('ruby', ['--version']) diff --git a/dist/index.js b/dist/index.js index 43e831941..1c0de8e91 100644 --- a/dist/index.js +++ b/dist/index.js @@ -327,7 +327,6 @@ const crypto = __nccwpck_require__(6113) const core = __nccwpck_require__(2186) const tc = __nccwpck_require__(7784) const exec = __nccwpck_require__(1514) -const common = __nccwpck_require__(4717) const { performance } = __nccwpck_require__(4074) const linuxOSInfo = __nccwpck_require__(8487) @@ -727,7 +726,7 @@ function setupPath(newPathEntries) { } async function setupJavaHome() { - common.measure("Modifying JAVA_HOME for JRuby", async () => { + await measure("Modifying JAVA_HOME for JRuby", async () => { console.log("attempting to run with existing JAVA_HOME") let ret = await exec.exec('ruby', ['--version'])