When setting $JAVA_HOME also add $JAVA_HOME/bin to PATH

* See discussion in https://github.com/rake-compiler/rake-compiler/pull/247
  it is messy if that's not the case and also creates inconsistencies
  based on which Java tool/executable is used.
This commit is contained in:
Benoit Daloze
2025-12-13 21:06:12 +01:00
parent 5f8a775744
commit ac793fdd38
2 changed files with 20 additions and 14 deletions
Generated Vendored
+10 -7
View File
@@ -344,6 +344,7 @@ const linuxOSInfo = __nccwpck_require__(962)
const windows = (os.platform() === 'win32')
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
const drive = (windows ? (process.env['RUNNER_TEMP'] || 'C')[0] : undefined)
const PATH_ENV_VAR = windows ? 'Path' : 'PATH'
const inputs = {
selfHosted: undefined
@@ -696,23 +697,22 @@ function win2nix(path) {
}
function setupPath(newPathEntries) {
const envPath = windows ? 'Path' : 'PATH'
const originalPath = process.env[envPath].split(path.delimiter)
const originalPath = process.env[PATH_ENV_VAR].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
core.group(`Modifying ${envPath}`, async () => {
core.group(`Modifying ${PATH_ENV_VAR}`, async () => {
// First remove the conflicting path entries
if (cleanPath.length !== originalPath.length) {
console.log(`Entries removed from ${envPath} to avoid conflicts with default Ruby:`)
console.log(`Entries removed from ${PATH_ENV_VAR} to avoid conflicts with default Ruby:`)
for (const entry of originalPath) {
if (!cleanPath.includes(entry)) {
console.log(` ${entry}`)
}
}
core.exportVariable(envPath, cleanPath.join(path.delimiter))
core.exportVariable(PATH_ENV_VAR, cleanPath.join(path.delimiter))
}
console.log(`Entries added to ${envPath} to use selected Ruby:`)
console.log(`Entries added to ${PATH_ENV_VAR} to use selected Ruby:`)
for (const entry of newPathEntries) {
console.log(` ${entry}`)
}
@@ -746,14 +746,17 @@ async function setupJavaHome(rubyPrefix) {
// JAVA_HOME_21_X64 - https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#java
let newHomeVar = `JAVA_HOME_21_${arch}`
let newHome = process.env[newHomeVar]
let bin = path.join(newHome, 'bin')
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)
console.log(`Adding ${bin} to ${PATH_ENV_VAR}`)
core.addPath(bin)
}
})
}