Switch JAVA_HOME to 21 for JRuby (#721)

* 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
This commit is contained in:
Charles Oliver Nutter
2025-03-12 21:19:38 +01:00
committed by GitHub
parent bbda85882f
commit f0a4d6bddd
3 changed files with 74 additions and 1 deletions
+31
View File
@@ -6,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')
@@ -403,3 +404,33 @@ export function setupPath(newPathEntries) {
core.addPath(newPath.join(path.delimiter))
return msys2Type
}
export async function setupJavaHome() {
await measure("Modifying JAVA_HOME for JRuby", async () => {
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)
}
})
}