Skip to content

Commit 06dd437

Browse files
committed
GHA to update jib image with the latest version
1 parent b359b3c commit 06dd437

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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: Update build.gradle and create PR
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
# Extract current version from JShellAPI build.gradle
26+
gradle_file="JShellAPI/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("^[0-9]+"))] | map(capture("^(?<major>[0-9]+)")) | max_by(.major | tonumber) | .major')
37+
38+
# Check if a new version is available
39+
if [ "$latest_version" -le "$current_version" ]; then
40+
echo "No new versions available"
41+
exit 0
42+
fi
43+
44+
# Update the build.gradle with the new version
45+
sed -i "s/eclipse-temurin:$current_version/eclipse-temurin:$latest_version/" $gradle_file
46+
47+
echo "Updated eclipse-temurin version from $current_version to $latest_version"
48+
49+
git config --global user.name "github-actions[bot]"
50+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
branch_name="update-eclipse-temurin-$latest_version"
53+
git checkout -b "$branch_name"
54+
55+
git add "$gradle_file"
56+
git commit -m "Update eclipse-temurin version to $latest_version"
57+
58+
git fetch origin
59+
git rebase origin/develop
60+
git push origin "$branch_name"
61+
62+
gh pr create --title "Update eclipse-temurin version to $latest_version" \
63+
--body "This PR updates the eclipse-temurin version in the JShellAPI build.gradle file from $current_version to $latest_version." \
64+
--head "$branch_name" \
65+
--base "develop"

0 commit comments

Comments
 (0)