Skip to content

Commit f0a4d6b

Browse files
authored
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
1 parent bbda858 commit f0a4d6b

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

common.js

+31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const stream = require('stream')
66
const crypto = require('crypto')
77
const core = require('@actions/core')
88
const tc = require('@actions/tool-cache')
9+
const exec = require('@actions/exec')
910
const { performance } = require('perf_hooks')
1011
const linuxOSInfo = require('linux-os-info')
1112

@@ -403,3 +404,33 @@ export function setupPath(newPathEntries) {
403404
core.addPath(newPath.join(path.delimiter))
404405
return msys2Type
405406
}
407+
408+
export async function setupJavaHome() {
409+
await measure("Modifying JAVA_HOME for JRuby", async () => {
410+
console.log("attempting to run with existing JAVA_HOME")
411+
412+
let ret = await exec.exec('ruby', ['--version'])
413+
414+
if (ret === 0) {
415+
console.log("JRuby successfully starts, using existing JAVA_HOME")
416+
} else {
417+
console.log("JRuby failed to start, try Java 21 envs")
418+
419+
let arch = os.arch()
420+
if (arch === "x64" || os.platform() !== "darwin") {
421+
arch = "X64"
422+
}
423+
424+
let newHomeVar = `JAVA_HOME_21_${arch}`
425+
let newHome = process.env[newHomeVar]
426+
427+
if (newHome === "undefined") {
428+
throw new Error(`JAVA_HOME is not Java 21+ needed for JRuby and \$${newHomeVar} is not defined`)
429+
}
430+
431+
console.log(`Setting JAVA_HOME to ${newHomeVar} path ${newHome}`)
432+
433+
core.exportVariable("JAVA_HOME", newHome)
434+
}
435+
})
436+
}

dist/index.js

+38-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ruby-builder.js

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export async function install(platform, engine, version) {
5454
await downloadAndExtract(platform, engine, version, rubyPrefix)
5555
}
5656

57+
// Ensure JRuby has minimum Java version to run
58+
if (engine === "jruby") {
59+
await common.setupJavaHome()
60+
}
61+
5762
return rubyPrefix
5863
}
5964

0 commit comments

Comments
 (0)