Skip to content

Commit 679f731

Browse files
authored
Restructure CI workflow and improve JDK caching (#178)
1 parent e408734 commit 679f731

File tree

7 files changed

+530
-977
lines changed

7 files changed

+530
-977
lines changed

.github/actions/extract_versions/action.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
name: Extract Java and Gradle Versions
22
description: Versions are reported in JAVA_VERSION and GRADLE_VERSION environment variables
3+
34
runs:
45
using: "composite"
56
steps:
67
- name: Extract Versions
78
id: extract_versions
89
shell: bash
910
run: |
11+
set +e
12+
1013
# Extract Java version
11-
java_version="${{ matrix.java_version }}"
12-
echo "JAVA_VERSION=${java_version%%+*}" >> $GITHUB_ENV
14+
${{ env.JAVA_TEST_HOME }}/bin/java -version
15+
JAVA_VERSION=$(${{ env.JAVA_TEST_HOME }}/bin/java -version 2>&1 | awk -F '"' '/version/ {
16+
split($2, v, "[._]");
17+
if (v[1] == "1") {
18+
# Java 8 or older: Include major, minor, and update
19+
printf "%s.%s.%s\n", v[2], v[3], v[4]
20+
} else {
21+
# Java 9 or newer: Major, minor, and patch
22+
printf "%s.%s.%s\n", v[1], v[2], v[3]
23+
}
24+
}')
25+
echo "JAVA_VERSION=${JAVA_VERSION}" >> $GITHUB_ENV
1326
1427
# Extract Gradle version from gradle-wrapper.properties
1528
gradle_version=$(grep 'distributionUrl' gradle/wrapper/gradle-wrapper.properties | cut -d'=' -f2)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "Setup test Java environment"
2+
description: "Setup Java environment for testing"
3+
4+
inputs:
5+
version:
6+
description: "The test JDK version to install"
7+
required: true
8+
default: "11"
9+
arch:
10+
description: "The architecture"
11+
required: true
12+
default: "amd64"
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Infer Build JDK
18+
shell: bash
19+
id: infer_build_jdk
20+
run: |
21+
echo "Infering JDK 11 [${{ inputs.arch }}]"
22+
if [[ ${{ inputs.arch }} =~ "-musl" ]]; then
23+
echo "build_jdk=jdk11-librca" >> $GITHUB_OUTPUT
24+
else
25+
echo "build_jdk=jdk11" >> $GITHUB_OUTPUT
26+
fi
27+
- name: Cache Build JDK [${{ inputs.arch }}]
28+
id: cache_build_jdk
29+
uses: actions/cache/restore@v4
30+
with:
31+
path: |
32+
jdks/${{ steps.infer_build_jdk.outputs.build_jdk }}
33+
key: ${{ steps.infer_build_jdk.outputs.build_jdk }}-${{ inputs.arch }}--${{ hashFiles('.github/workflows/cache_java.yml', '.github/scripts/java_setup.sh') }}
34+
restore-keys: |
35+
${{ steps.infer_build_jdk.outputs.build_jdk }}-${{ inputs.arch }}--
36+
- name: Cache JDK ${{ inputs.version }} [${{ inputs.arch }}]
37+
id: cache_jdk
38+
uses: actions/cache/restore@v4
39+
with:
40+
path: |
41+
jdks/jdk${{ inputs.version }}
42+
key: jdk${{ inputs.version }}-${{ inputs.arch }}--${{ hashFiles('.github/workflows/cache_java.yml', '.github/scripts/java_setup.sh') }}
43+
restore-keys: |
44+
jdk${{ inputs.version }}-${{ inputs.arch }}--
45+
- name: JDK cache miss
46+
if: steps.cache_jdk.outputs.cache-hit != 'true' || steps.cache_build_jdk.outputs.cache-hit != 'true'
47+
shell: bash
48+
run: |
49+
# well, the cache-hit is not alway set to 'true', even when cache is hit (but it is not freshly recreated, whatever that means)
50+
if [ ! -d "jdks/jdk${{ inputs.version }}" ]; then
51+
OWNER=${{ github.repository_owner }}
52+
REPO=${{ github.event.repository.name }}
53+
BRANCH=${{ github.ref_name }}
54+
WORKFLOW="cache_java.yml"
55+
56+
URL="https://github.com/$OWNER/$REPO/actions/workflows/$WORKFLOW"
57+
58+
echo "### ⚠️ JDK Cache Miss Detected" >> $GITHUB_STEP_SUMMARY
59+
echo "🛠️ [Click here and select ${BRANCH} branch to manually refresh the cache](<$URL>)" >> $GITHUB_STEP_SUMMARY
60+
exit 1
61+
fi
62+
- name: Setup Environment
63+
shell: bash
64+
run: |
65+
chmod a+rx -R jdks
66+
echo "Setting up JDK ${{ inputs.version }} [${{ inputs.arch }}]"
67+
JAVA_HOME=$(pwd)/jdks/${{ steps.infer_build_jdk.outputs.build_jdk }}
68+
JAVA_TEST_HOME=$(pwd)/jdks/jdk${{ inputs.version }}
69+
PATH=$JAVA_HOME/bin:$PATH
70+
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
71+
echo "JAVA_TEST_HOME=$JAVA_TEST_HOME" >> $GITHUB_ENV
72+
echo "PATH=$JAVA_HOME/bin:$PATH" >> $GITHUB_ENV
73+
74+
ldd $JAVA_HOME/bin/java

.github/scripts/java_setup.sh

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,76 @@
11
#!/usr/bin/env bash
22

33
function prepareJdk() {
4-
local jdk_distro=$1
5-
local target_path=$2
4+
local variant=$1
5+
local arch=$2
6+
local version=${variant%%-*}
7+
local qualifier=${variant#*-}
68

7-
if [ -e "$target_path/bin/java" ]; then
8-
echo "JDK $jdk_distro already installed at $jdk_path"
9+
local target_path="${GITHUB_WORKSPACE}/${JDKS_DIR}/jdk${variant}"
10+
11+
mkdir -p ${target_path}
12+
13+
if [[ ${qualifier} == "librca" ]] && [[ "${arch}" =~ "-musl" ]]; then
14+
URL_VAR="JAVA_${version}_MUSL_URL"
15+
URL="${!URL_VAR}"
16+
if [[ -z "${URL}" ]]; then
17+
echo "Musl/Liberica JDK URL not found for ${arch}/${variant}"
18+
exit 1
19+
fi
20+
curl -L --fail "${URL}" | tar -xvzf - -C ${target_path} --strip-components 1
921
return
1022
fi
1123

12-
echo 'n' | sdk install java ${jdk_distro}
13-
ln -s ~/.sdkman/candidates/java/${jdk_distro} ${target_path}
14-
}
24+
if [[ ${qualifier} == "orcl" ]]; then
25+
if [[ ${version} == "8" ]]; then
26+
mkdir -p "${target_path}"
27+
curl -L --fail "${JAVA_8_ORACLE_URL}" | sudo tar -xvzf - -C ${target_path} --strip-components 1
28+
return
29+
else
30+
echo "Oracle JDK 8 only!"
31+
exit 1
32+
fi
33+
fi
34+
35+
if [[ ${qualifier} == "zing" ]]; then
36+
URL_VAR="JAVA_${version}_ZING_URL"
37+
if [[ "${arch}" == "aarch64" ]]; then
38+
URL_VAR="JAVA_${version}_ZING_AARCH64_URL"
39+
fi
40+
41+
URL="${!URL_VAR}"
42+
if [[ -z "${URL}" ]]; then
43+
echo "Zing JDK URL not found for ${variant}"
44+
exit 1
45+
fi
46+
curl -L --fail "${URL}" | sudo tar -xvzf - -C ${target_path} --strip-components 1
47+
if [[ "${arch}" != "aarch64" ]]; then
48+
# rename the bundled libstdc++.so to avoid conflicts with the system one
49+
sudo mv ${target_path}/etc/libc++/libstdc++.so.6 ${target_path}/etc/libc++/libstdc++.so.6.bak
50+
fi
51+
return
52+
fi
53+
54+
# below the installation of the SDKMAN-managed JDK
55+
source ~/.sdkman/bin/sdkman-init.sh
56+
57+
local suffix="tem"
58+
local versionVar="JAVA_${version}_VERSION"
59+
if [[ "${qualifier}" == "j9" ]]; then
60+
suffix="sem"
61+
versionVar="JAVA_${version}_J9_VERSION"
62+
elif [[ "${qualifier}" == "graal" ]]; then
63+
suffix="graal"
64+
versionVar="JAVA_${version}_GRAAL_VERSION"
65+
fi
66+
67+
local distro_base
68+
distro_base="${!versionVar}"
69+
local jdk_distro="${distro_base}-${suffix}"
70+
71+
echo 'n' | sdk install java ${jdk_distro} > /dev/null
72+
73+
rm -rf ${target_path}
74+
mkdir -p "$(dirname ${target_path})"
75+
mv ${SDKMAN_DIR}/candidates/java/${jdk_distro} ${target_path}
76+
}

.github/scripts/prepare_reports.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
mkdir -p reports
5+
cp /tmp/hs_err* reports/ || true
6+
cp ddprof-test/build/hs_err* reports/ || true
7+
cp -r ddprof-lib/build/tmp reports/native_build || true
8+
cp -r ddprof-test/build/reports/tests reports/tests || true
9+
cp -r /tmp/recordings reports/recordings || true
10+
find ddprof-lib/build -name 'libjavaProfiler.*' -exec cp {} reports/ \; || true

0 commit comments

Comments
 (0)