|
| 1 | +name: Auto-Update Jib Base Image |
| 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: Run bash script |
| 22 | + run: | |
| 23 | + # Extract current version from JShellAPI build.gradle |
| 24 | + gradle_file="JShellAPI/build.gradle" |
| 25 | + current_version=$(grep -oP "(?<=from\.image\s=\s'eclipse-temurin:)\d+" $gradle_file) |
| 26 | + |
| 27 | + if [ -z "$current_version" ]; then |
| 28 | + echo "Failed to extract version from $gradle_file \"from.image\"" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + |
| 32 | + # Fetch the latest eclipse-temurin image |
| 33 | + latest_version=$(curl -s "https://hub.docker.com/v2/repositories/library/eclipse-temurin/tags/?page_size=100" | \ |
| 34 | + jq -r '[.results[].name | select(test("^[0-9]+"))] | map(capture("^(?<major>[0-9]+)")) | max_by(.major | tonumber) | .major') |
| 35 | + |
| 36 | + # Check if a new version is available |
| 37 | + if [ "$latest_version" -le "$current_version" ]; then |
| 38 | + echo "No new versions available" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + |
| 42 | + # Update the build.gradle with the new version |
| 43 | + sed -i "s/eclipse-temurin:$current_version/eclipse-temurin:$latest_version/" $gradle_file |
| 44 | + |
| 45 | + echo "Updated eclipse-temurin version from $current_version to $latest_version" |
| 46 | +
|
| 47 | + - name: Commit changes |
| 48 | + run: | |
| 49 | + git config --global user.name "github-actions[bot]" |
| 50 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + |
| 52 | + # Create a new branch |
| 53 | + branch_name="update-eclipse-temurin-$latest_version" |
| 54 | + git checkout -b "$branch_name" |
| 55 | + |
| 56 | + # Add and commit the changes |
| 57 | + git add JShellAPI/build.gradle |
| 58 | + git commit -m "Update eclipse-temurin version to $latest_version" |
| 59 | + |
| 60 | + # Push the new branch to the remote repository |
| 61 | + git push origin "$branch_name" |
| 62 | +
|
| 63 | + - name: Create a pull request |
| 64 | + run: | |
| 65 | + gh pr create --title "Update eclipse-temurin version to $latest_version" \ |
| 66 | + --body "This PR updates the eclipse-temurin version in the JShellAPI build.gradle file from $current_version to $latest_version." \ |
| 67 | + --head "$branch_name" \ |
| 68 | + --base "main" |
0 commit comments