From ecd2bf144889debd9148f048816b0c0dd1d28d46 Mon Sep 17 00:00:00 2001 From: ragsmpl Date: Sat, 10 Jun 2023 18:11:33 +0530 Subject: [PATCH 1/3] Auto download latest version of custom distribution JDK during run time --- docs/advanced-usage.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 7fbcc3a26..4b0294bf1 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -168,6 +168,30 @@ steps: - run: java -cp java HelloWorldApp ``` +If your use-case reuires a custom distribution or a version that is not provided by setup-java and always install the latest version during runtime, then you can use below code to auto download the latest JDK, determine the semver needed for the setup-java and setup-java will take care of the installation and caching on the VM: + +```yaml + steps: + - name: fetch latest temurin JDK + id: fetch_latest_jdk + run: | + cd $RUNNER_TEMP + response=$(curl -s "https://api.github.com/repos/adoptium/temurin${major_version}-binaries/releases") + latest_jdk_download_url=$(echo "$response" | jq -r '.[0].assets[] | select(.name | contains("jdk_x64_alpine-linux") and endswith(".tar.gz")) | .browser_download_url') + curl -Ls "$latest_jdk_download_url" -o java_package.tar.gz + latest_jdk_json_url=$(jdk_download_url "$response" | jq -r '.[0].assets[] | select(.name | contains("jdk_x64_alpine-linux") and endswith(".tar.gz.json")) | .browser_download_url') + latest_semver_version=$(curl -sL $latest_jdk_json_url | jq -r 'version.semver') + echo "java_version=$latest_semver_version" >> "$GITHUB_OUTPUT" + + - uses: actions/setup-java@v3 + with: + distribution: 'jdkfile' + jdkFile: ${{ runner.temp }}/java_package.tar.gz + java-version: {{ steps.fetch_latest_jdk.outputs.java_version }} + architecture: x64 + - run: java -cp java HelloWorldApp +``` + ## Testing against different Java distributions **NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions. ```yaml From dfa3adf2d1af4ccce218f760f1c30d7990ea598e Mon Sep 17 00:00:00 2001 From: ragsmpl Date: Sat, 10 Jun 2023 18:14:29 +0530 Subject: [PATCH 2/3] Update advanced-usage.md --- docs/advanced-usage.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 4b0294bf1..83ffd1e03 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -168,13 +168,14 @@ steps: - run: java -cp java HelloWorldApp ``` -If your use-case reuires a custom distribution or a version that is not provided by setup-java and always install the latest version during runtime, then you can use below code to auto download the latest JDK, determine the semver needed for the setup-java and setup-java will take care of the installation and caching on the VM: +If your use-case reuires a custom distribution (in the example alpine-linux is used) or a version that is not provided by setup-java and always install the latest version during runtime, then you can use below code to auto download the latest JDK, determine the semver needed for the setup-java and setup-java will take care of the installation and caching on the VM: ```yaml steps: - name: fetch latest temurin JDK id: fetch_latest_jdk run: | + major_version={{ env.JAVA_VERSION }} # Example 8 or 11 or 17 cd $RUNNER_TEMP response=$(curl -s "https://api.github.com/repos/adoptium/temurin${major_version}-binaries/releases") latest_jdk_download_url=$(echo "$response" | jq -r '.[0].assets[] | select(.name | contains("jdk_x64_alpine-linux") and endswith(".tar.gz")) | .browser_download_url') From 896dfb4026fa0c74ca7d6bed25ec1dc27c4103d8 Mon Sep 17 00:00:00 2001 From: ragsmpl Date: Fri, 16 Jun 2023 14:18:37 +0530 Subject: [PATCH 3/3] Updated the comment as per the suggestion --- docs/advanced-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 83ffd1e03..bf695f7a9 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -168,7 +168,7 @@ steps: - run: java -cp java HelloWorldApp ``` -If your use-case reuires a custom distribution (in the example alpine-linux is used) or a version that is not provided by setup-java and always install the latest version during runtime, then you can use below code to auto download the latest JDK, determine the semver needed for the setup-java and setup-java will take care of the installation and caching on the VM: +If your use-case requires a custom distribution (in the example, alpine-linux is used) or a version that is not provided by setup-java and you want to always install the latest version during runtime, then you can use the following code to auto-download the latest JDK, determine the semver needed for setup-java, and setup-java will take care of the installation and caching on the VM: ```yaml steps: