Skip to content
33 changes: 33 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,35 @@ export function setupPath(newPathEntries) {
core.addPath(newPath.join(path.delimiter))
return msys2Type
}

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'])

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()
}
40 changes: 39 additions & 1 deletion dist/index.js

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

4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']))

Expand Down
Loading