Skip to content

Switch JAVA_HOME to 21 for JRuby #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 12, 2025
31 changes: 31 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
}
})
}
39 changes: 38 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ruby-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading