From 0f82238b516a96b22e179e31e83f7987a5ff427c Mon Sep 17 00:00:00 2001 From: Alathreon Date: Fri, 4 Oct 2024 20:20:31 +0200 Subject: [PATCH 1/4] GHA JShell auto update java version --- .../update-jshell-image-version.yaml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/update-jshell-image-version.yaml diff --git a/.github/workflows/update-jshell-image-version.yaml b/.github/workflows/update-jshell-image-version.yaml new file mode 100644 index 0000000..0ab5fa0 --- /dev/null +++ b/.github/workflows/update-jshell-image-version.yaml @@ -0,0 +1,66 @@ +name: Auto-Update JShell Image version + +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="JShellWrapper/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("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" + exit 0 + fi + + # Update the build.gradle with the new version + 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" + + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + branch_name="update-jshell-java-version-$latest_version" + git checkout -b "$branch_name" + + git add "$gradle_file" + git commit -m "JShell Java version to $latest_version" + + git fetch origin + git rebase origin/develop + git push origin "$branch_name" + + gh pr create --title "Update JShell java version to $latest_version" \ + --body "This PR updates the JShell java version in the JShellWrapper build.gradle file from $current_version to $latest_version." \ + --head "$branch_name" \ + --base "develop" From 68047b18da21fbfc605c0d3a64c4005fe84992a5 Mon Sep 17 00:00:00 2001 From: Alathreon Date: Fri, 4 Oct 2024 20:42:36 +0200 Subject: [PATCH 2/4] added failsafe for auto update of jshell version --- .github/workflows/update-jshell-image-version.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/update-jshell-image-version.yaml b/.github/workflows/update-jshell-image-version.yaml index 0ab5fa0..da4dddc 100644 --- a/.github/workflows/update-jshell-image-version.yaml +++ b/.github/workflows/update-jshell-image-version.yaml @@ -51,6 +51,12 @@ jobs: git config --global user.email "github-actions[bot]@users.noreply.github.com" branch_name="update-jshell-java-version-$latest_version" + + if gh api repos/Together-Java/JShellPlaygroundBackend/branches/$branch_name >/dev/null 2>&1 + then + return 0 + fi + git checkout -b "$branch_name" git add "$gradle_file" From bdc260302612ca25310d811ddea3176be2e90cec Mon Sep 17 00:00:00 2001 From: Alathreon Date: Fri, 4 Oct 2024 20:52:18 +0200 Subject: [PATCH 3/4] Fixing some names in JShell GHA --- .github/workflows/update-jshell-image-version.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-jshell-image-version.yaml b/.github/workflows/update-jshell-image-version.yaml index da4dddc..67c7873 100644 --- a/.github/workflows/update-jshell-image-version.yaml +++ b/.github/workflows/update-jshell-image-version.yaml @@ -22,7 +22,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Extract current version from JShellAPI build.gradle + # Extract current version from JShellWrapper build.gradle gradle_file="JShellWrapper/build.gradle" current_version=$(grep -oP "(?<=from\.image\s=\s'eclipse-temurin:)\d+" $gradle_file) @@ -45,7 +45,7 @@ jobs: # Update the build.gradle with the new version 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" + echo "Updated JDK 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" From 2e155b19ca0a8b31f09b8cfb7f1eaa206f7d27aa Mon Sep 17 00:00:00 2001 From: Alathreon Date: Fri, 4 Oct 2024 20:59:41 +0200 Subject: [PATCH 4/4] Rollback changes for the failfast --- .github/workflows/update-jshell-image-version.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/update-jshell-image-version.yaml b/.github/workflows/update-jshell-image-version.yaml index 67c7873..27fe132 100644 --- a/.github/workflows/update-jshell-image-version.yaml +++ b/.github/workflows/update-jshell-image-version.yaml @@ -51,12 +51,6 @@ jobs: git config --global user.email "github-actions[bot]@users.noreply.github.com" branch_name="update-jshell-java-version-$latest_version" - - if gh api repos/Together-Java/JShellPlaygroundBackend/branches/$branch_name >/dev/null 2>&1 - then - return 0 - fi - git checkout -b "$branch_name" git add "$gradle_file"