Skip to content

Commit d901764

Browse files
authored
Merge pull request #1812 from larsewi/update-jdk21
ENT-13123: Added automated updates of JDK 21
2 parents 98e9cd1 + 9c20b0e commit d901764

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

.github/workflows/update-deps.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def parse_args():
5959
parser.add_argument(
6060
"--root", default=".", help="specify build scripts root directory"
6161
)
62+
parser.add_argument(
63+
"--jdk21",
64+
action="store_true",
65+
help="update SDK 21 on build hosts (needed by Jenkins)",
66+
)
6267

6368
return parser.parse_args()
6469

@@ -255,6 +260,87 @@ def update_deps(root, bump, skip):
255260
exit(1)
256261

257262

263+
def update_jdk21(root):
264+
base_url = "https://download.oracle.com/java/21/archive/"
265+
266+
filename = os.path.join(root, "ci/linux-install-jdk21.sh")
267+
with open(filename, "r") as f:
268+
content = f.read()
269+
270+
old_version = re.search(
271+
r"version=21\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", content
272+
).group()
273+
_, minor, patch = old_version.split(".")
274+
minor = int(minor)
275+
patch = int(patch)
276+
log.debug(f"Found version 21.{minor}.{patch} in '{filename}'")
277+
278+
# Let's try to increase the minor version number first
279+
response = requests.head(base_url + f"jdk-21.{minor + 1}.0_linux-x64_bin.tar.gz")
280+
while response.status_code == 200:
281+
minor += 1
282+
log.debug(f"Found more recent version 21.{minor}.0")
283+
284+
# Reset the patch version if there is a more recent minor version
285+
patch = 0
286+
287+
time.sleep(1) # Let's not DDOS them
288+
response = requests.head(
289+
base_url + f"jdk-21.{minor + 1}.0_linux-x64_bin.tar.gz"
290+
)
291+
292+
# Now try to increase the patch version number
293+
response = requests.head(
294+
base_url + f"jdk-21.{minor}.{patch + 1}_linux-x64_bin.tar.gz"
295+
)
296+
while response.status_code == 200:
297+
patch += 1
298+
log.debug(f"Found more recent version 21.{minor}.{patch}")
299+
time.sleep(1) # Let's not DDOS them
300+
response = requests.head(
301+
base_url + f"jdk-21.{minor}.{patch + 1}_linux-x64_bin.tar.gz"
302+
)
303+
304+
new_version = f"version=21.{minor}.{patch}"
305+
if new_version == old_version:
306+
log.debug(
307+
f"Java Development Kit 21 is already the newest version ('{new_version}' == '{old_version}')"
308+
)
309+
return
310+
311+
# Find old SHAs
312+
aarch64_old_sha, x64_old_sha = re.findall(r"sha=[0-9a-f]{64}", content)
313+
log.debug(f"Found SHA '{aarch64_old_sha}' for aarch64 in '{filename}'")
314+
log.debug(f"Found SHA '{x64_old_sha}' for x64 '{filename}'")
315+
316+
# Get new SHAs
317+
url = base_url + f"jdk-21.{minor}.{patch}_linux-aarch64_bin.tar.gz.sha256"
318+
aarch64_new_sha = f"sha={requests.get(url).text}"
319+
log.debug(f"Fetched new SHA '{aarch64_new_sha}' for aarch64")
320+
url = base_url + f"jdk-21.{minor}.{patch}_linux-x64_bin.tar.gz.sha256"
321+
x64_new_sha = f"sha={requests.get(url).text}"
322+
log.debug(f"Fetched new SHA '{x64_new_sha}' for x64")
323+
324+
# Replace version number and SHAs
325+
log.debug(f"Replacing old version '{old_version}' with new version '{new_version}'")
326+
content = content.replace(old_version, new_version, 1)
327+
log.debug(f"Replacing old SHA '{aarch64_old_sha}' with new sha '{aarch64_new_sha}'")
328+
content = content.replace(aarch64_old_sha, aarch64_new_sha, 1)
329+
log.debug(f"Replacing old SHA '{x64_old_sha}' with new sha '{x64_new_sha}'")
330+
content = content.replace(x64_old_sha, x64_new_sha, 1)
331+
332+
log.debug(f"Writing changes to file '{filename}'")
333+
with open(filename, "w") as f:
334+
f.write(content)
335+
336+
if not git_commit(
337+
root,
338+
f"Updated Java Development Kit to 21.{minor}.{patch}",
339+
):
340+
log.error(f"Failed to commit changes after updating Java Development Kit")
341+
exit(1)
342+
343+
258344
def main():
259345
args = parse_args()
260346
loglevel = "DEBUG" if args.debug else "INFO"
@@ -263,6 +349,8 @@ def main():
263349
)
264350

265351
update_deps(args.root, args.bump, args.skip)
352+
if args.jdk21:
353+
update_jdk21(args.root)
266354

267355

268356
if __name__ == "__main__":

.github/workflows/update-deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: |
4545
echo "COMMIT_HASH_BEFORE=$(git log -1 --format=%H)">> $GITHUB_ENV
4646
- name: Run update script
47-
run: python3 /tmp/update-deps.py --debug --bump=${{ matrix.branch == 'master' && 'major' || 'minor' }}
47+
run: python3 /tmp/update-deps.py --debug --bump=${{ matrix.branch == 'master' && 'major' || 'minor' }} {{ matrix.branch == 'master' && '--jdk21' }}
4848
- name: Save commit hash after
4949
run: |
5050
echo "COMMIT_HASH_AFTER=$(git log -1 --format=%H)">> $GITHUB_ENV

0 commit comments

Comments
 (0)