|
| 1 | +name: Auto-Update JShell Image version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 0 * * 5" # Every Friday at Midnight |
| 7 | + |
| 8 | +jobs: |
| 9 | + update_build_gradle: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Install GitHub CLI |
| 17 | + run: | |
| 18 | + sudo apt-get update |
| 19 | + sudo apt-get install gh |
| 20 | +
|
| 21 | + - name: Update build.gradle and create PR |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run: | |
| 25 | + # Extract current version from JShellWrapper build.gradle |
| 26 | + gradle_file="JShellWrapper/build.gradle" |
| 27 | + current_version=$(grep -oP "(?<=from\.image\s=\s'eclipse-temurin:)\d+" $gradle_file) |
| 28 | + |
| 29 | + if [ -z "$current_version" ]; then |
| 30 | + echo "Failed to extract version from $gradle_file \"from.image\"" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + |
| 34 | + # Fetch the latest eclipse-temurin image |
| 35 | + latest_version=$(curl -s "https://hub.docker.com/v2/repositories/library/eclipse-temurin/tags/?page_size=100" | \ |
| 36 | + jq -r '[.results[].name | select(test("alpine")) | select(test("^[0-9]+"))] | map(capture("^(?<major>[0-9]+)")) | max_by(.major | tonumber) | .major') |
| 37 | + |
| 38 | + |
| 39 | + # Check if a new version is available |
| 40 | + if [ "$latest_version" -le "$current_version" ]; then |
| 41 | + echo "No new versions available" |
| 42 | + exit 0 |
| 43 | + fi |
| 44 | + |
| 45 | + # Update the build.gradle with the new version |
| 46 | + sed -i "s/eclipse-temurin:$current_version-alpine/eclipse-temurin:$latest_version-alpine/" $gradle_file |
| 47 | + |
| 48 | + echo "Updated JDK version from $current_version to $latest_version" |
| 49 | +
|
| 50 | + git config --global user.name "github-actions[bot]" |
| 51 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + |
| 53 | + branch_name="update-jshell-java-version-$latest_version" |
| 54 | + git checkout -b "$branch_name" |
| 55 | + |
| 56 | + git add "$gradle_file" |
| 57 | + git commit -m "JShell Java version to $latest_version" |
| 58 | + |
| 59 | + git fetch origin |
| 60 | + git rebase origin/develop |
| 61 | + git push origin "$branch_name" |
| 62 | +
|
| 63 | + gh pr create --title "Update JShell java version to $latest_version" \ |
| 64 | + --body "This PR updates the JShell java version in the JShellWrapper build.gradle file from $current_version to $latest_version." \ |
| 65 | + --head "$branch_name" \ |
| 66 | + --base "develop" |
0 commit comments