From 06dd43790d23b3010b11fdc5cfb9dd895722df3c Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:43:49 +0100 Subject: [PATCH 1/2] GHA to update jib image with the latest version --- .github/workflows/update-jib-base-image.yml | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/update-jib-base-image.yml diff --git a/.github/workflows/update-jib-base-image.yml b/.github/workflows/update-jib-base-image.yml new file mode 100644 index 0000000..9d838b6 --- /dev/null +++ b/.github/workflows/update-jib-base-image.yml @@ -0,0 +1,65 @@ +name: Auto-Update Jib Base Image + +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * 5" # Every Friday at Midnight + +jobs: + update_build_gradle: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install GitHub CLI + run: | + sudo apt-get update + sudo apt-get install gh + + - name: Update build.gradle and create PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Extract current version from JShellAPI build.gradle + gradle_file="JShellAPI/build.gradle" + current_version=$(grep -oP "(?<=from\.image\s=\s'eclipse-temurin:)\d+" $gradle_file) + + if [ -z "$current_version" ]; then + echo "Failed to extract version from $gradle_file \"from.image\"" + exit 1 + fi + + # Fetch the latest eclipse-temurin image + latest_version=$(curl -s "https://hub.docker.com/v2/repositories/library/eclipse-temurin/tags/?page_size=100" | \ + jq -r '[.results[].name | select(test("^[0-9]+"))] | map(capture("^(?[0-9]+)")) | max_by(.major | tonumber) | .major') + + # Check if a new version is available + if [ "$latest_version" -le "$current_version" ]; then + echo "No new versions available" + exit 0 + fi + + # Update the build.gradle with the new version + sed -i "s/eclipse-temurin:$current_version/eclipse-temurin:$latest_version/" $gradle_file + + echo "Updated eclipse-temurin version from $current_version to $latest_version" + + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + branch_name="update-eclipse-temurin-$latest_version" + git checkout -b "$branch_name" + + git add "$gradle_file" + git commit -m "Update eclipse-temurin version to $latest_version" + + git fetch origin + git rebase origin/develop + git push origin "$branch_name" + + gh pr create --title "Update eclipse-temurin version to $latest_version" \ + --body "This PR updates the eclipse-temurin version in the JShellAPI build.gradle file from $current_version to $latest_version." \ + --head "$branch_name" \ + --base "develop" From 8ff67820be1fd0eaa936d5aa2080af51a516be1b Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:55:26 +0100 Subject: [PATCH 2/2] Switch project to JShellWrapper and use alpine --- .github/workflows/update-jib-base-image.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-jib-base-image.yml b/.github/workflows/update-jib-base-image.yml index 9d838b6..1d70247 100644 --- a/.github/workflows/update-jib-base-image.yml +++ b/.github/workflows/update-jib-base-image.yml @@ -23,7 +23,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Extract current version from JShellAPI build.gradle - gradle_file="JShellAPI/build.gradle" + gradle_file="JShellWrapper/build.gradle" current_version=$(grep -oP "(?<=from\.image\s=\s'eclipse-temurin:)\d+" $gradle_file) if [ -z "$current_version" ]; then @@ -33,8 +33,9 @@ jobs: # Fetch the latest eclipse-temurin image latest_version=$(curl -s "https://hub.docker.com/v2/repositories/library/eclipse-temurin/tags/?page_size=100" | \ - jq -r '[.results[].name | select(test("^[0-9]+"))] | map(capture("^(?[0-9]+)")) | max_by(.major | tonumber) | .major') - + jq -r '[.results[].name | select(test("alpine")) | select(test("^[0-9]+"))] | map(capture("^(?[0-9]+)")) | max_by(.major | tonumber) | .major') + + # Check if a new version is available if [ "$latest_version" -le "$current_version" ]; then echo "No new versions available" @@ -42,7 +43,7 @@ jobs: fi # Update the build.gradle with the new version - sed -i "s/eclipse-temurin:$current_version/eclipse-temurin:$latest_version/" $gradle_file + sed -i "s/eclipse-temurin:$current_version-alpine/eclipse-temurin:$latest_version-alpine/" $gradle_file echo "Updated eclipse-temurin version from $current_version to $latest_version"