|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import re |
| 4 | +import requests |
| 5 | +import json |
| 6 | +import ast |
| 7 | + |
| 8 | +readme_ver_pattern = r'(?:(?<=Supports code from Java 1\.5 to Java )(\d+)|(?<=JavaSE-)~|(?<=path/to/jdk-)~)' # After resolving current_jdk, we will replace ~ |
| 9 | + |
| 10 | +# Query the Oracle website for the latest JDK version |
| 11 | +response = requests.get('http://javadl-esd-secure.oracle.com/update/baseline.version') |
| 12 | +latest_jdk = re.search(r'(?P<major>\d+)\.', response.text) |
| 13 | +if latest_jdk is None: |
| 14 | + print('Failed to retrieve latest JDK version') |
| 15 | + exit(1) |
| 16 | +latest_jdk = latest_jdk.group('major') |
| 17 | +print(f'Latest JDK version: {latest_jdk}') |
| 18 | + |
| 19 | +# Query the vscode-java repo for the current supported JDK version |
| 20 | +with open('README.md', 'r') as f: # Open the README.md file in read mode |
| 21 | + readme = f.read() # Read the file content as a string |
| 22 | +current_jdk = re.search(readme_ver_pattern, readme) # Search for the JDK version in the string |
| 23 | +if current_jdk is None: |
| 24 | + print('Failed to retrieve current JDK version') |
| 25 | + exit(1) |
| 26 | +current_jdk = current_jdk.group(1) |
| 27 | +print(f'Current supported JDK version: {current_jdk}') |
| 28 | + |
| 29 | +# If the latest JDK version is not the same as the current supported JDK version, check the test status and update the files |
| 30 | +if latest_jdk != current_jdk: |
| 31 | + print(f'New JDK version detected: {latest_jdk}') |
| 32 | + # Create a formatted string template from the URI structure |
| 33 | + uri_base = 'https://ci.eclipse.org/ls/job/jdt-ls-master/lastCompletedBuild/testReport/org.eclipse.jdt.ls.core.internal.{package}/{java_class}/{method}/api/python' |
| 34 | + # Define the test URLs to check using the template and list comprehension |
| 35 | + tests = [ |
| 36 | + uri_base.format(package='correction', java_class='ModifierCorrectionsQuickFixTest', method=m) for m in ['testAddSealedMissingClassModifierProposal', 'testAddSealedAsDirectSuperClass', 'testAddPermitsToDirectSuperClass'] |
| 37 | + ] + [ |
| 38 | + uri_base.format(package='correction', java_class='UnresolvedTypesQuickFixTest', method='testTypeInSealedTypeDeclaration') |
| 39 | + ] + [ |
| 40 | + uri_base.format(package='managers', java_class=c, method=m) for c, m in [('EclipseProjectImporterTest', 'testPreviewFeaturesDisabledByDefault'), ('InvisibleProjectImporterTest', 'testPreviewFeaturesEnabledByDefault'), ('MavenProjectImporterTest', f'testJava{latest_jdk}Project')] |
| 41 | + ] |
| 42 | + |
| 43 | + # Check the test status for each test URL |
| 44 | + all_tests_passed = True |
| 45 | + for i in range(len(tests)): |
| 46 | + response = requests.get(tests[i]) |
| 47 | + data = ast.literal_eval(response.text) # Use ast.literal_eval, because response.json() fails |
| 48 | + try: |
| 49 | + if data['status'] != 'PASSED': |
| 50 | + print(f'Test #{i + 1} failed ({tests[i]})') |
| 51 | + all_tests_passed = False |
| 52 | + break |
| 53 | + except KeyError: |
| 54 | + print(f'Test #{i + 1} not found ({tests[i]})') |
| 55 | + all_tests_passed = False |
| 56 | + break |
| 57 | + |
| 58 | + # If all tests passed, update the README.md and the package.json files |
| 59 | + if all_tests_passed: |
| 60 | + print('All tests passed') |
| 61 | + |
| 62 | + # Replace the ~ with current_jdk |
| 63 | + readme_ver_pattern = re.sub('~', current_jdk, readme_ver_pattern) |
| 64 | + |
| 65 | + # Write this to a file for the create-pull-request workflow |
| 66 | + with open('latest_jdk.txt', 'w') as f: |
| 67 | + f.write(latest_jdk) |
| 68 | + |
| 69 | + # Replace the current supported JDK version with the latest JDK version |
| 70 | + readme = re.sub(readme_ver_pattern, latest_jdk, readme) |
| 71 | + |
| 72 | + # Write the updated README.md file |
| 73 | + with open('README.md', 'w') as f: |
| 74 | + f.write(readme) |
| 75 | + |
| 76 | + # Read the package.json file |
| 77 | + with open('package.json', 'r') as f: |
| 78 | + package = json.load(f) |
| 79 | + |
| 80 | + # Add the latest JDK version to the java.configuration.runtimes array |
| 81 | + jdks_config = next(filter(lambda e: e['id'] == "java-jdks", package['contributes']['configuration'])) |
| 82 | + jdks_config['properties']['java.configuration.runtimes']['items']['properties']['name']['enum'].append(f'JavaSE-{latest_jdk}') |
| 83 | + |
| 84 | + # Write the updated package.json file |
| 85 | + with open('package.json', 'w') as f: |
| 86 | + json.dump(package, f, indent=2) |
| 87 | + else: |
| 88 | + print('Some tests failed, aborting update') |
| 89 | + exit(1) |
| 90 | +else: |
| 91 | + print('No new JDK version detected, nothing to do') |
| 92 | + exit(0) |
| 93 | +exit(0) |
0 commit comments