Files
Stirling-PDF/.github/actions/java/action.yml
T
2026-08-25 00:05:21 +02:00

95 lines
4.1 KiB
YAML

name: Local Java
description: Configure the JDK already installed on the GitHub Actions runner
inputs:
java-version:
description: JDK major version
required: false
default: "25"
architecture:
description: Compatibility input for existing workflow call sites
required: false
default: ""
runs:
using: composite
steps:
- name: Configure preinstalled JDK
shell: bash
env:
JAVA_VERSION: ${{ inputs.java-version }}
JAVA_ARCHITECTURE: ${{ inputs.architecture }}
RUNNER_ARCHITECTURE: ${{ runner.arch }}
RUNNER_OS_NAME: ${{ runner.os }}
run: |
set -euo pipefail
if [ "${JAVA_VERSION}" != "25" ]; then
echo "This repository requires JDK 25; received ${JAVA_VERSION}" >&2
exit 1
fi
architecture="${JAVA_ARCHITECTURE}"
if [ -z "${architecture}" ]; then
architecture="${RUNNER_ARCHITECTURE}"
fi
normalized_architecture="$(printf '%s' "${architecture}" | tr '[:lower:]' '[:upper:]')"
case "${normalized_architecture}" in
X64|AMD64|X86_64) architecture=X64 ;;
ARM64|AARCH64) architecture=ARM64 ;;
*) echo "Unsupported runner architecture: ${architecture}" >&2; exit 1 ;;
esac
java_home_variable="JAVA_HOME_${JAVA_VERSION}_${architecture}"
java_home="${!java_home_variable:-}"
if [ -z "${java_home}" ] && [ "${RUNNER_OS_NAME}" = "macOS" ]; then
runner_architecture="$(printf '%s' "${RUNNER_ARCHITECTURE}" | tr '[:lower:]' '[:upper:]')"
if [ "${architecture}" = "${runner_architecture}" ] && [ -n "${JAVA_HOME:-}" ]; then
java_home="${JAVA_HOME}"
fi
fi
if [ -z "${java_home}" ] && [ "${RUNNER_OS_NAME}" = "macOS" ] && [ "${architecture}" = "X64" ]; then
java_home="$(arch -x86_64 /usr/libexec/java_home -v "${JAVA_VERSION}" 2>/dev/null || true)"
fi
if [ -n "${java_home}" ] && [ "${RUNNER_OS_NAME}" = "macOS" ]; then
java_binary="${java_home}/bin/java"
if [ "${architecture}" = "X64" ] && ! file "${java_binary}" | grep -q "x86_64"; then
java_home=""
elif [ "${architecture}" = "ARM64" ] && ! file "${java_binary}" | grep -q "arm64"; then
java_home=""
fi
fi
if [ -z "${java_home}" ] && [ "${RUNNER_OS_NAME}" = "macOS" ] && [ "${architecture}" = "X64" ]; then
jdk_version="25.0.3+9"
jdk_archive="OpenJDK25U-jdk_x64_mac_hotspot_25.0.3_9.tar.gz"
jdk_sha256="4c539a18b4d656960ff6766727e9ca546fc17f7a29714dba9e7b47bdcb37c447"
jdk_root="${RUNNER_TEMP}/stirling-temurin-${jdk_version}"
archive_path="${jdk_root}/${jdk_archive}"
mkdir -p "${jdk_root}"
if [ ! -f "${archive_path}" ]; then
curl --fail --location --retry 3 --retry-delay 2 \
--output "${archive_path}" \
"https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.3%2B9/${jdk_archive}"
fi
printf '%s %s\n' "${jdk_sha256}" "${archive_path}" | shasum -a 256 -c -
if [ ! -x "${jdk_root}/Contents/Home/bin/jlink" ]; then
rm -rf "${jdk_root}/Contents"
tar -xzf "${archive_path}" -C "${jdk_root}"
fi
java_home="$(find "${jdk_root}" -type d -path '*/Contents/Home' -print -quit)"
fi
if [ -z "${java_home}" ]; then
echo "JDK 25 is not installed on this runner (${java_home_variable} is missing)" >&2
exit 1
fi
shell_java_home="${java_home}"
if command -v cygpath >/dev/null 2>&1; then
shell_java_home="$(cygpath --unix "${java_home}")"
fi
export JAVA_HOME="${shell_java_home}"
export PATH="${shell_java_home}/bin:${PATH}"
echo "JAVA_HOME_${JAVA_VERSION}_${architecture}=${java_home}" >> "${GITHUB_ENV}"
echo "JAVA_HOME=${java_home}" >> "${GITHUB_ENV}"
echo "${java_home}/bin" >> "${GITHUB_PATH}"
java -version 2>&1 | tee "${RUNNER_TEMP}/java-version.txt"
grep -Eq "version \"${JAVA_VERSION}(\.|\")" "${RUNNER_TEMP}/java-version.txt"