Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Cache SDKMan java and fix run-id passing #29247

Merged
2 changes: 1 addition & 1 deletion .github/actions/deploy-artifact-jfrog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ runs:

- uses: ./.github/actions/maven-job
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ inputs.github-token }}
stage-name: "Deploy Artifacts Validate"
maven-args: "validate" # We don't need to build just get the repo and use validate to check everything exists
artifacts-from: ${{ inputs.artifact-run-id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/publish-npm-cli/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ runs:
echo "::group::NPM Package setup"
echo "Adding bin folder with all the binaries"
mkdir -p bin
find ${{ github.workspace }}/artifacts/cli/target/distributions/ -name "*.zip" -exec unzip -d bin {} \;
find ${{ github.workspace }}/artifacts/ -name "*.zip" -exec unzip -d bin {} \;

echo "Adding wrapper script"
mv src/postinstall.js.seed src/postinstall.js
Expand Down
117 changes: 79 additions & 38 deletions .github/actions/setup-java/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,83 @@ inputs:
runs:
using: 'composite'
steps:
- name: 'Setup SDKMan'
id: sdkman-java
- name: Determine Architecture
id: determine-arch
shell: bash
run: echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV

- name: Get Requested Version
id: get-requested-version
shell: bash
run: |
DEFAULT_GRAALVM="21.0.2-graalce"

if [ ! -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
echo "Using sdkman to install SDKMAN"
curl -s "https://get.sdkman.io" | bash
fi

# Note sdkman-init.sh adds sdk as a function to the current shell
# sdk command is therefore not directly available on subsequent actions
# to use sdkman in a subsequent action you will need to call the following command
# with each script that uses sdk command directly.
# This script otherwise sets the PATH and JAVA_HOME to the selected java so further tasks do not
# need to be aware of sdkman directly

source "$HOME/.sdkman/bin/sdkman-init.sh"

REQUESTED_VERSION="${{ inputs.java-version }}"
REQUIRE_GRAALVM="${{ inputs.require-graalvm }}"
GRAALVM_VERSION="${{ inputs.graalvm-version }}"

# Handle default values for REQUESTED_VERSION and GRAALVM_VERSION
if [ -z "$REQUESTED_VERSION" ]; then
if [ -f .sdkmanrc ]; then
REQUESTED_VERSION=$(awk -F "=" '/^java=/ {print $2}' .sdkmanrc)
echo "Extracted Java version from .sdkmanrc: $REQUESTED_VERSION"
else
echo "No Java version provided and .sdkmanrc file not found."
exit 1
fi
if [ -z "${{ inputs.java-version }}" ] && [ -f .sdkmanrc ]; then
REQUESTED_VERSION=$(awk -F "=" '/^java=/ {print $2}' .sdkmanrc)
echo "using default Java version from .sdkmanrc: REQUESTED_VERSION"
else
echo "Using provided Java version: $REQUESTED_VERSION"
REQUESTED_VERSION="${{ inputs.java-version }}"
echo "using Java version from inputs: REQUESTED_VERSION"
fi

echo "requested_version=$REQUESTED_VERSION" >> $GITHUB_OUTPUT
GRAALVM_VERSION="${{ inputs.graalvm-version }}"
if [ -z "$GRAALVM_VERSION" ]; then
GRAALVM_VERSION=${DEFAULT_GRAALVM}
echo "No GraalVM version provided, using default: $GRAALVM_VERSION"
else
echo "Using provided GraalVM version: $GRAALVM_VERSION"
fi
echo "graalvm_version=$GRAALVM_VERSION" >> $GITHUB_OUTPUT
- name: Restore Cache SDKMan install
id: restore-cache-sdkman
uses: actions/cache/restore@v4
with:
path: ~/.sdkman
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-install
- name: Install SDKMan
id: install-sdkman
if: ${{ steps.restore-cache-sdkman.outputs.cache-hit != 'true' }}
shell: bash
run: |
if [ ! -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
echo "Downloading SDKMAN install"
curl -s "https://get.sdkman.io" | bash
fi
- name: Save Cache SDKMan install
id: save-cache-sdkman
if: ${{ steps.restore-cache-sdkman.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: ~/.sdkman
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-install

- name: Restore Cache Java SDK
id: restore-cache-java
uses: actions/cache/restore@v4
with:
path: ~/.sdkman/candidates/java/${{ steps.get-requested-version.outputs.requested_version }}
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-java-${{ steps.get-requested-version.outputs.requested_version }}

- name: Restore Cache GraalVM SDK
id: restore-cache-graalvm
if: ${{ inputs.require-graalvm == 'true' }}
uses: actions/cache/restore@v4
with:
path: ~/.sdkman/candidates/java/${{ steps.get-requested-version.outputs.graalvm_version }}
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-java-${{ steps.get-requested-version.outputs.graalvm_version }}

- name: 'Setup SDKMan'
id: sdkman-java
shell: bash
run: |

source "$HOME/.sdkman/bin/sdkman-init.sh"

REQUESTED_VERSION="${{ steps.get-requested-version.outputs.requested_version }}"
REQUIRE_GRAALVM="${{ inputs.require-graalvm }}"
GRAALVM_VERSION="${{ steps.get-requested-version.outputs.graalvm_version }}"


TEST_HOME=$(sdk home java "$REQUESTED_VERSION" 2>/dev/null) || true
if [ -z "$TEST_HOME" ]; then
echo "Java version $REQUESTED_VERSION is not installed. Installing now..."
Expand All @@ -69,22 +102,17 @@ runs:
sdk use java "$REQUESTED_VERSION"
fi


# Ensure JAVA_HOME and path update persist in subsequent steps
echo "JAVA_HOME=$TEST_HOME" >> $GITHUB_ENV
JAVA_BIN_PATH="$HOME/.sdkman/candidates/java/current/bin"
echo "$JAVA_BIN_PATH" >> $GITHUB_PATH

# Ensure PATH is set correctly for the current script
export JAVA_HOME=$TEST_HOME
export PATH=$JAVA_BIN_PATH:$PATH

# Set GRAALVM_HOME if the version ends with "-graalce", "-mandrel", or "-graal"
if [[ "$REQUESTED_VERSION" == *"-graalce" || "$REQUESTED_VERSION" == *"-mandrel" || "$REQUESTED_VERSION" == *"-graal" ]]; then
echo "GRAALVM_HOME=$TEST_HOME" >> $GITHUB_ENV
fi

# Install and set GRAALVM_HOME if required and not already set
if [[ "$REQUIRE_GRAALVM" == "true" ]]; then
if [ -z "$GRAALVM_HOME" ] && [ "$REQUESTED_VERSION" != "$GRAALVM_VERSION" ]; then
echo "Requested version does not match required GraalVM version and GRAALVM_HOME is not set. Installing GraalVM version $GRAALVM_VERSION..."
Expand All @@ -105,8 +133,21 @@ runs:
echo "Default Java version is already set to $REQUESTED_VERSION"
fi

# Echo JAVA_HOME, Java version, and path to Java command
echo "JAVA_HOME is set to: $JAVA_HOME"
echo "Path to java command: $(which java)"
echo "Java version:"
java -version
java -version

- name: Save Cache Java SDK
uses: actions/cache/save@v4
if: ${{ steps.restore-cache-java.outputs.cache-hit != 'true' }}
with:
path: ~/.sdkman/candidates/java/${{ steps.get-requested-version.outputs.requested_version }}
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-java-${{ steps.get-requested-version.outputs.requested_version }}

- name: Save Cache GraalVM SDK
if: ${{ inputs.require-graalvm == 'true' && steps.restore-cache-graalvm.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: ~/.sdkman/candidates/java/${{ steps.get-requested-version.outputs.graalvm_version }}
key: ${{ runner.os }}-${{ env.ARCHITECTURE }}-sdkman-java-${{ steps.get-requested-version.outputs.graalvm_version }}
2 changes: 1 addition & 1 deletion .github/workflows/build-test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
#
build-cli:
name: CLI Build
needs: [ test ]
needs: [ initialize,test ]
if: always() && !failure() && !cancelled()
uses: ./.github/workflows/cli-build-artifacts.yml
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
packages: write
build-cli:
name: Nightly CLI Build
needs: [ test ]
needs: [ initialize, test ]
if: always() && !failure() && !cancelled()
uses: ./.github/workflows/cli-build-artifacts.yml
with:
Expand Down