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

feat(gitpod): Install SDKMAN in GitHub runners and GitPod, and keep JDK versions up-to-date #121

Merged
merged 41 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ed75dd3
feat(sdkman): Very first version of the JDK versions handling.
gounthar Jul 24, 2024
ad788ca
feat(gitpod): Very first version of the JDK versions handling.
gounthar Jul 24, 2024
33750d3
feat(gitpod): Uses updatecli to keep the JDK version up to date thank…
gounthar Jul 24, 2024
ccded32
chore: [GitPod] Update the JDK21 version for SDKMAN
jenkins-infra-bot Jul 24, 2024
fbd4936
chore: [GitPod] Update the JDK17 version for SDKMAN
jenkins-infra-bot Jul 24, 2024
a1eef7d
chore: [GitPod] Update the JDK11 version for SDKMAN
jenkins-infra-bot Jul 24, 2024
465499d
chore: [GitPod] Update the JDK8 version for SDKMAN
jenkins-infra-bot Jul 24, 2024
6dab7b5
Merge pull request #1 from gounthar/updatecli_sdkman_b95cb2648dfd66de…
gounthar Jul 24, 2024
6f77d58
fix(gitpod): Documentation
gounthar Jul 24, 2024
4a466e8
fix(gitpod): JDK17 should be installed last, as that's the one we're …
gounthar Jul 25, 2024
e7164da
fix(ga): Let the action run.
gounthar Jul 25, 2024
0daa961
fix(ga): Renaming.
gounthar Jul 25, 2024
8dd1b77
fix(ga): Renaming branch.
gounthar Jul 25, 2024
c870015
fix(ga): Error code when the JDK is not found.
gounthar Jul 25, 2024
bb999f4
fix(ga): Installs SDKMAN.
gounthar Jul 25, 2024
c09a216
fix(ga): Redirects output to error.
gounthar Jul 25, 2024
f7dc53f
fix(ga): Silences output.
gounthar Jul 25, 2024
86b8161
fix(updatecli): Wrong versions in purpose.
gounthar Jul 25, 2024
c81050f
chore: [sdkman.properties] Update the JDK8 version
jenkins-infra-bot Jul 25, 2024
c0f14cf
chore: [sdkman.properties] Update the JDK21 version
jenkins-infra-bot Jul 25, 2024
2dfdb62
chore: [sdkman.properties] Update the JDK17 version
jenkins-infra-bot Jul 25, 2024
cd88494
chore: [sdkman.properties] Update the JDK11 version
jenkins-infra-bot Jul 25, 2024
4a98079
Merge pull request #4 from gounthar/updatecli_sdkman_dac059977a0bdb06…
gounthar Jul 25, 2024
18f6cb0
fix(updatecli): Changes PR title.
gounthar Jul 25, 2024
f33d38b
fix(updatecli): Targetting the right repo/branch combo.
gounthar Jul 25, 2024
8e02ab0
fix(updatecli): Adds JAVA_HOME
gounthar Jul 25, 2024
f4f7b73
fix(updatecli): Adds JAVA_HOME
gounthar Jul 25, 2024
7bff1b9
fix(updatecli): Thanks, Damien!
gounthar Jul 25, 2024
bc5f163
fix(updatecli): Install SDKMAN if needed.
gounthar Jul 25, 2024
bffddc0
fix(updatecli): Install JDKs.
gounthar Jul 25, 2024
0d1b641
fix(updatecli): Uses PAGER=cat.
gounthar Jul 25, 2024
4104137
fix(updatecli): Get some logs.
gounthar Jul 25, 2024
bc2185a
fix(updatecli): Get some logs.
gounthar Jul 25, 2024
24439dc
fix(updatecli): Calls the script locally.
gounthar Jul 25, 2024
1033126
fix(updatecli): Removes debug logs.
gounthar Jul 25, 2024
3d43d81
fix(updatecli): Installs SDKMAN and needed JDKs.
gounthar Jul 25, 2024
735140a
Merge remote-tracking branch 'upstream/main' into sdkman
gounthar Jul 25, 2024
16ae0b5
Merge remote-tracking branch 'upstream/main' into sdkman
gounthar Jul 25, 2024
b284c0d
fix(updatecli): Installs SDKMAN if not found.
gounthar Jul 25, 2024
7e9cdef
Merge branch 'sdkman' into jhjkl
gounthar Aug 3, 2024
6d5e358
Merge pull request #13 from gounthar/jhjkl
gounthar Aug 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/updatecli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: updatecli
on:
# Allow to be run manually
workflow_dispatch:
schedule:
# Run once per week (to avoid alert fatigue)
- cron: '0 2 * * 1' # Every Monday at 2am UTC
push:
pull_request:
jobs:
updatecli:
runs-on: ubuntu-latest
if: github.repository_owner == 'jenkinsci'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Updatecli in the runner
uses: updatecli/[email protected]

- name: Install SDKMAN in the runner
run: ./updatecli/scripts/install-sdk.sh

- name: Install needed JDKs in the runner
run: ./updatecli/scripts/install-jdk-versions.sh

- name: Run Updatecli in Dry Run mode
run: updatecli diff --config ./updatecli/updatecli.d --values ./updatecli/values.github-action.yaml
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run Updatecli in Apply mode
if: github.ref == 'refs/heads/main'
run: updatecli apply --config ./updatecli/updatecli.d --values ./updatecli/values.github-action.yaml
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 14 additions & 1 deletion .gitpod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Start from a base image that includes JDK 17 and Git. This serves as the foundation for the development environment.
FROM gitpod/workspace-java-17

# Define the versions of the JDKs to install. This is used by the `sdk install java` command to install the specified JDK.
ARG JDK8_PACKAGE=8.0.422-tem
ARG JDK11_PACKAGE=11.0.24-tem
ARG JDK17_PACKAGE=17.0.12-tem
ARG JDK21_PACKAGE=21.0.4-tem

# Update the package list and install Maven. Maven is required for building Java projects, including Jenkins plugins.
# The `apt-get update` command updates the list of available packages and their versions, but it does not install or
# upgrade any packages. The `apt-get install -y maven` command installs Maven without requiring confirmation from the user.
Expand All @@ -19,11 +25,18 @@ RUN file="$HOME/.bashrc.d/770-scm_token.sh" \
&& printf '%s\n' 'if [[ "${GITPOD_WORKSPACE_CONTEXT_URL:-}" == *gitlab* ]]; then : "gitlab"; else : "github"; fi; scm_name="$_"' > "${file}" \
&& printf 'export SCM_TOKEN="$(%s)"\n' "gp credential-helper get <<<host=\${scm_name}.com | sed -n 's/^password=//p'" >> "${file}"

# Install the gh cli tool \
# Install the gh cli tool
RUN (type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

# Initialize SDKMAN and install the various JDKs thanks to SDKMAN
RUN /bin/bash -c "source \"$HOME/.sdkman/bin/sdkman-init.sh\" && \
yes | sdk install java \"$JDK8_PACKAGE\" \
&& yes | sdk install java \"$JDK11_PACKAGE\" \
&& yes | sdk install java \"$JDK21_PACKAGE\" \
&& yes | sdk install java \"$JDK17_PACKAGE\""
12 changes: 12 additions & 0 deletions plugin-modernizer-cli/src/main/resources/sdkman.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# sdkman.properties
# This properties file defines the specific versions of the Temurin JDK to be installed using SDKMAN.
# Each property specifies the version of the JDK package corresponding to its major version number.

JDK8_PACKAGE=8.0.422-tem # JDK 8 package version
JAVA_8_HOME=$HOME/.sdkman/candidates/java/8.0.422-tem
JDK11_PACKAGE=11.0.24-tem # JDK 11 package version
JAVA_11_HOME=$HOME/.sdkman/candidates/java/11.0.24-tem
JDK17_PACKAGE=17.0.12-tem # JDK 17 package version
JAVA_17_HOME=$HOME/.sdkman/candidates/java/17.0.12-tem
JDK21_PACKAGE=21.0.4-tem # JDK 21 package version
JAVA_21_HOME=$HOME/.sdkman/candidates/java/21.0.4-tem
58 changes: 58 additions & 0 deletions updatecli/scripts/get-java-home.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Store the current directory
current_dir=$(pwd)

# Store the directory of the current script
script_dir=$(dirname "$0")

# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <major_java_version>"
exit 1
fi

major_version=$1

# Change to the directory where the script is located
cd "$script_dir" || exit

# Call install-sdk.sh and redirect output
# For silence:
./install-sdk.sh > /dev/null 2>&1
# Or, to redirect all output to stderr:
#./install-sdk.sh 2>&1 >&2

# Initialize SDKMAN
if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
source "$HOME/.sdkman/bin/sdkman-init.sh"
# Call install-jdk-versions.sh using the script directory
./install-jdk-versions.sh > /dev/null 2>&1
else
echo "SDKMAN is not installed or not found."
exit 2
fi

# Change back to the original directory
cd "$current_dir" || exit

# Retrieve the version identifier for the requested major version of Temurin JDK
identifier=$(PAGER=cat sdk list java | grep -E " $major_version\\.0.*-tem" | awk -v ver="$major_version" '$0 ~ " " ver "\\.0.*-tem" {print $NF}' | head -n 1)

if [ -z "$identifier" ]; then
echo "No Temurin JDK version found for Java $major_version"
exit 3
fi

# Get JAVA_HOME for the specified version
java_home=$(sdk home java "$identifier")

# Replace the expanded $HOME path with the literal $HOME string
java_home_modified=$(echo "$java_home" | sed "s|${HOME}|\\\$HOME|g")

if [ -z "$java_home_modified" ]; then
echo "JAVA_HOME could not be found for Java $major_version"
exit 4
fi

echo "$java_home_modified"
46 changes: 46 additions & 0 deletions updatecli/scripts/get-jdk-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Store the current directory
current_dir=$(pwd)

# Check if a version argument was provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <major_java_version>" >&2
exit 1
fi

major_version=$1

# Change to the directory where the script is located
cd "$(dirname "$0")" || exit

# Call install-sdk.sh and redirect output
# For silence:
./install-sdk.sh > /dev/null 2>&1
# Or, to redirect all output to stderr:
#./install-sdk.sh 2>&1 >&2

# Initialize SDKMAN
if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
source "$HOME/.sdkman/bin/sdkman-init.sh"
install-jdk-versions.sh > /dev/null 2>&1
else
echo "SDKMAN is not installed or not found."
exit 2
fi

# Change back to the original directory
cd "$current_dir" || exit

# Initialize SDKMAN
source "$HOME/.sdkman/bin/sdkman-init.sh"

# Find and output the Temurin JDK version identifier for the given major version
identifier=$(PAGER=cat sdk list java | grep -E " $major_version\\.0.*-tem" | awk -v ver="$major_version" '$0 ~ " " ver "\\.0.*-tem" {print $NF}' | head -n 1)

if [ -n "$identifier" ]; then
echo "$identifier"
else
echo "No Temurin JDK version found for Java $major_version" >&2
exit 2
fi
40 changes: 40 additions & 0 deletions updatecli/scripts/install-jdk-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Determine the directory of the current script
script_dir=$(dirname "$0")

# Check if SDKMAN is installed
if [[ ! -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
echo "SDKMAN is not installed. Attempting to install SDKMAN..."
# Attempt to install SDKMAN by calling install-sdk.sh from the same directory
if [[ -x "$script_dir/install-sdk.sh" ]]; then
"$script_dir/install-sdk.sh"
# Check if SDKMAN is successfully installed
if [[ ! -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
echo "Failed to install SDKMAN. Please install SDKMAN manually."
exit 1
fi
else
echo "install-sdk.sh script not found in $script_dir"
exit 1
fi
fi

# Initialize SDKMAN
source "$HOME/.sdkman/bin/sdkman-init.sh"

# Declare the JDK versions you're interested in
declare -a jdk_versions=("8" "11" "17" "21")

# Loop through each JDK version
for version in "${jdk_versions[@]}"; do
# Use sdk list java with --no-pager or pipe through cat to avoid pager behavior
identifier=$(PAGER=cat sdk list java | grep -E " $version\\.0.*-tem" | awk -v ver="$version" '$0 ~ " " ver "\\.0.*-tem" {print $NF}' | head -n 1)
if [ -n "$identifier" ]; then
echo "Installing Temurin JDK version $version with identifier $identifier"
# Install the JDK version using SDKMAN
yes | sdk install java "$identifier"
else
echo "No Temurin JDK version found for $version"
fi
done
23 changes: 23 additions & 0 deletions updatecli/scripts/install-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This script installs SDKMAN, a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.

# Define SDKMAN installation URL
SDKMAN_URL="https://get.sdkman.io"

# Check if SDKMAN is already installed by checking if the sdkman-init.sh script exists
if [ -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
echo "SDKMAN is already installed."
else
# Download and run the SDKMAN installation script
echo "Installing SDKMAN..."
curl -s "$SDKMAN_URL" | bash

# Source the SDKMAN initialization script to make the `sdk` command available in the current shell session
source "$HOME/.sdkman/bin/sdkman-init.sh"

echo "SDKMAN installation completed."
fi
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
# Verify SDKMAN installation by checking the sdk version
sdk version
Loading
Loading