From 9c12e2cfbb58d0d85b72420f73da551643a6588e Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:20:48 +0100 Subject: [PATCH 1/4] GHA to update jib image with the latest version --- .github/workflows/update-jib-base-image.yml | 68 +++++++++++++++++++++ 1 file changed, 68 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..5665734 --- /dev/null +++ b/.github/workflows/update-jib-base-image.yml @@ -0,0 +1,68 @@ +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: Run bash script + 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 1 + 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" + + - name: Commit changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + # Create a new branch + branch_name="update-eclipse-temurin-$latest_version" + git checkout -b "$branch_name" + + # Add and commit the changes + git add JShellAPI/build.gradle + git commit -m "Update eclipse-temurin version to $latest_version" + + # Push the new branch to the remote repository + git push origin "$branch_name" + + - name: Create a pull request + run: | + 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 "main" From f4d9070ccc67778cc2a823196c347271d2c18841 Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:20:48 +0100 Subject: [PATCH 2/4] GHA to update jib image with the latest version --- .github/workflows/update-jib-base-image.yml | 70 +++++++++++++++++++++ 1 file changed, 70 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..0514370 --- /dev/null +++ b/.github/workflows/update-jib-base-image.yml @@ -0,0 +1,70 @@ +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 + 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 1 + 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" + + - name: Commit changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + # Create a new branch + branch_name="update-eclipse-temurin-$latest_version" + git checkout -b "$branch_name" + + # Add and commit the changes + git add JShellAPI/build.gradle + git commit -m "Update eclipse-temurin version to $latest_version" + + # Push the new branch to the remote repository + git push origin "$branch_name" + + - name: Create a pull request + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + 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 "main" From 5054b759a4f8ec1c5b4b5e006626a526a83bc5cb Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:33:53 +0100 Subject: [PATCH 3/4] Develop not main :fp: --- .github/workflows/update-jib-base-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-jib-base-image.yml b/.github/workflows/update-jib-base-image.yml index 0514370..912f303 100644 --- a/.github/workflows/update-jib-base-image.yml +++ b/.github/workflows/update-jib-base-image.yml @@ -67,4 +67,4 @@ jobs: 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 "main" + --base "develop" From f591d9d27209cdd8472c4bc5a4aee55c29d5e0a9 Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Sat, 28 Sep 2024 00:36:32 +0100 Subject: [PATCH 4/4] testt --- .github/workflows/update-jib-base-image.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-jib-base-image.yml b/.github/workflows/update-jib-base-image.yml index 912f303..db16a3d 100644 --- a/.github/workflows/update-jib-base-image.yml +++ b/.github/workflows/update-jib-base-image.yml @@ -49,15 +49,14 @@ jobs: git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - # Create a new branch branch_name="update-eclipse-temurin-$latest_version" git checkout -b "$branch_name" - # Add and commit the changes - git add JShellAPI/build.gradle + git add "$gradle_file" git commit -m "Update eclipse-temurin version to $latest_version" - # Push the new branch to the remote repository + git fetch origin + git rebase origin/develop git push origin "$branch_name" - name: Create a pull request