Skip to content

Commit 7bbdafb

Browse files
authored
Add new scripts to support automatic updating vesions of spring (#29325)
* update to support automatic work
1 parent e9cce37 commit 7bbdafb

10 files changed

+135
-32
lines changed

sdk/spring/scripts/README.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

sdk/spring/scripts/compatibility_delete_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
def main():
1818
start_time = time.time()
19-
change_to_root_dir()
19+
change_to_repo_root_dir()
2020
log.debug('Current working directory = {}.'.format(os.getcwd()))
2121
find_all_poms_do_version_control("./sdk/spring")
2222
elapsed_time = time.time() - start_time
2323
log.info('elapsed_time = {}'.format(elapsed_time))
2424

2525

26-
def change_to_root_dir():
26+
def change_to_repo_root_dir():
2727
os.chdir(os.path.dirname(os.path.realpath(__file__)))
2828
os.chdir('../../..')
2929

sdk/spring/scripts/compatibility_get_spring_cloud_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_args():
1616
return parser.parse_args()
1717

1818

19-
def change_to_root_dir():
19+
def change_to_repo_root_dir():
2020
os.chdir(os.path.dirname(os.path.realpath(__file__)))
2121
os.chdir('../../..')
2222

@@ -35,7 +35,7 @@ def get_spring_cloud_version(filepath):
3535

3636

3737
def main():
38-
change_to_root_dir()
38+
change_to_repo_root_dir()
3939
get_spring_cloud_version("./sdk/spring/spring-cloud-azure-supported-spring.json")
4040

4141

sdk/spring/scripts/compatibility_insert_dependencymanagement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def get_args():
2525

2626
def main():
2727
start_time = time.time()
28-
change_to_root_dir()
28+
change_to_repo_root_dir()
2929
log.debug('Current working directory = {}.'.format(os.getcwd()))
3030
add_dependency_management_for_all_poms_files_in_directory("./sdk/spring", get_args().spring_boot_dependencies_version, get_args().spring_cloud_dependencies_version)
3131
elapsed_time = time.time() - start_time
3232
log.info('elapsed_time = {}'.format(elapsed_time))
3333

3434

35-
def change_to_root_dir():
35+
def change_to_repo_root_dir():
3636
os.chdir(os.path.dirname(os.path.realpath(__file__)))
3737
os.chdir('../../..')
3838

sdk/spring/scripts/compatibility_update_supported_version_matrix_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import json
1414

1515

16-
def change_to_root_dir():
16+
def change_to_repo_root_dir():
1717
os.chdir(os.path.dirname(os.path.realpath(__file__)))
1818
os.chdir('../../..')
1919

@@ -43,7 +43,7 @@ def get_supported_spring_boot_version(filepath):
4343

4444
def main():
4545
start_time = time.time()
46-
change_to_root_dir()
46+
change_to_repo_root_dir()
4747
log.debug('Current working directory = {}.'.format(os.getcwd()))
4848
suppoerted_spring_boot_version = get_supported_spring_boot_version("./sdk/spring/spring-cloud-azure-supported-spring.json")
4949
update_supported_version_matrix_json_file("./sdk/spring/supported-version-matrix.json", suppoerted_spring_boot_version)

sdk/spring/scripts/get_spring_boot_managed_external_dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_spring_boot_managed_external_dependencies_file_name(spring_boot_dependen
5858

5959
def main():
6060
start_time = time.time()
61-
change_to_root_dir()
61+
change_to_repo_root_dir()
6262
log.debug('Current working directory = {}.'.format(os.getcwd()))
6363
dependency_dict = {}
6464
args = get_args()
@@ -71,7 +71,7 @@ def main():
7171
log.info('elapsed_time = {}'.format(elapsed_time))
7272

7373

74-
def change_to_root_dir():
74+
def change_to_repo_root_dir():
7575
os.chdir(os.path.dirname(os.path.realpath(__file__)))
7676
os.chdir('../../..')
7777

sdk/spring/scripts/replace_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
def main():
5050
start_time = time.time()
51-
change_to_root_dir()
51+
change_to_repo_root_dir()
5252
log.debug('Current working directory = {}.'.format(os.getcwd()))
5353
args = get_args()
5454
init_log(args)
@@ -57,7 +57,7 @@ def main():
5757
log.info('elapsed_time = {}'.format(elapsed_time))
5858

5959

60-
def change_to_root_dir():
60+
def change_to_repo_root_dir():
6161
os.chdir(os.path.dirname(os.path.realpath(__file__)))
6262
os.chdir('../../..')
6363

sdk/spring/scripts/sync_external_dependencies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#
55
# How to use this script.
66
# 1. Get `SPRING_BOOT_VERSION` from https://github.com/spring-projects/spring-boot/tags.
7-
# 2. Make sure file(`.\sdk\spring\spring_boot_SPRING_BOOT_VERSION_managed_external_dependencies.txt`) exist. If it doesn't exist, please run
7+
# 2. Make sure file(`.\sdk\spring\spring_boot_${SPRING_BOOT_VERSION}_managed_external_dependencies.txt`) exist. If it doesn't exist, please run
88
# `.\sdk\spring\scripts\get_spring_boot_managed_external_dependencies.py` to create that file.
9-
# 3. Run command, sample: `python .\sdk\spring\scripts\sync_external_dependencies.py -b 2.7.0`.
9+
# 3. Run command: `python .\sdk\spring\scripts\sync_external_dependencies.py -b 2.7.0`.
1010
# Or `python .\sdk\spring\scripts\sync_external_dependencies.py --spring_boot_dependencies_version 2.7.0`.
1111
# 4. Then `eng/versioning/external_dependencies.txt` will be updated.
1212
#
@@ -50,15 +50,15 @@ def get_args():
5050

5151
def main():
5252
start_time = time.time()
53-
change_to_root_dir()
53+
change_to_repo_root_dir()
5454
args = get_args()
5555
log.debug('Current working directory = {}.'.format(os.getcwd()))
5656
sync_external_dependencies(get_spring_boot_managed_external_dependencies_file_name(args.spring_boot_dependencies_version), EXTERNAL_DEPENDENCIES_FILE)
5757
elapsed_time = time.time() - start_time
5858
log.info('elapsed_time = {}'.format(elapsed_time))
5959

6060

61-
def change_to_root_dir():
61+
def change_to_repo_root_dir():
6262
os.chdir(os.path.dirname(os.path.realpath(__file__)))
6363
os.chdir('../../..')
6464

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Python version 3.4 or higher is required to run this script.
2+
#
3+
# This script is used to update changelog about Spring Boot and Spring Cloud dependencies versions in `/sdk/spring/CHANGELOG.md`.
4+
#
5+
# Sample:
6+
# 1. python .\sdk\spring\scripts\update_changelog.py --spring_boot_dependencies_version 2.7.0 --spring_cloud_dependencies_version 2021.0.3
7+
# 2. python .\sdk\spring\scripts\update_changelog.py -b 2.7.0 -c 2021.0.3
8+
#
9+
# The script must be run at the root of azure-sdk-for-java.
10+
11+
12+
import os
13+
import time
14+
import argparse
15+
16+
from log import log
17+
18+
19+
CHANGELOG_FILE = 'sdk/spring/CHANGELOG.md'
20+
21+
22+
def get_args():
23+
parser = argparse.ArgumentParser()
24+
parser.add_argument('-b', '--spring_boot_dependencies_version', type = str, required = True)
25+
parser.add_argument('-c', '--spring_cloud_dependencies_version', type = str, required = True)
26+
return parser.parse_args()
27+
28+
29+
def get_change_log_content(spring_boot_dependencies_version, spring_cloud_dependencies_version):
30+
return "\nUpgrade Spring Boot dependencies version to {} and Spring Cloud dependencies version to {}".format(spring_boot_dependencies_version,spring_cloud_dependencies_version)
31+
32+
33+
def update_changelog(spring_boot_dependencies_version, spring_cloud_dependencies_version, target_file):
34+
with open(target_file, 'r', encoding = 'utf-8') as file:
35+
file_content = file.read()
36+
insert_position = file_content.find('(Unreleased)') + len('(Unreleased)')
37+
insert_content = get_change_log_content(spring_boot_dependencies_version, spring_cloud_dependencies_version)
38+
final_content = file_content[:insert_position] + insert_content + file_content[insert_position:]
39+
with open(target_file, 'r+', encoding = 'utf-8') as file:
40+
file.writelines(final_content)
41+
42+
43+
def main():
44+
start_time = time.time()
45+
change_to_repo_root_dir()
46+
log.debug('Current working directory = {}.'.format(os.getcwd()))
47+
args = get_args()
48+
update_changelog(args.spring_boot_dependencies_version, args.spring_cloud_dependencies_version, CHANGE_LOG_FILE)
49+
elapsed_time = time.time() - start_time
50+
log.info('elapsed_time = {}'.format(elapsed_time))
51+
52+
53+
def change_to_repo_root_dir():
54+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
55+
os.chdir('../../..')
56+
57+
58+
if __name__ == '__main__':
59+
main()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
############################################################################################################################################
2+
# This script is used to update comments at the beginning of `eng/versioning/external_dependencies.txt`.
3+
#
4+
# How to use this script.
5+
# 1. Get `SPRING_BOOT_VERSION` from (.\sdk\spring\spring_boot_${SPRING_BOOT_VERSION}_managed_external_dependencies.txt) filename.
6+
# 2. Run command: `python .\sdk\spring\scripts\update_external_dependencies_comment.py -b 2.7.0`.
7+
# Or `python .\sdk\spring\scripts\sync_external_dependencies.py --spring_boot_dependencies_version 2.7.0`.
8+
# 3. Then `eng/versioning/external_dependencies.txt` will be updated.
9+
#
10+
# Please refer to ./README.md to get more information about this script.
11+
############################################################################################################################################
12+
13+
import time
14+
import os
15+
import argparse
16+
17+
from log import log
18+
19+
EXTERNAL_DEPENDENCIES_FILE = 'eng/versioning/external_dependencies.txt'
20+
21+
22+
def get_spring_boot_managed_external_dependencies_file_name(spring_boot_version):
23+
return 'sdk/spring/scripts/spring_boot_{}_managed_external_dependencies.txt'.format(spring_boot_version)
24+
25+
26+
def get_args():
27+
parser = argparse.ArgumentParser()
28+
parser.add_argument('-b', '--spring_boot_dependencies_version', type = str, required = True)
29+
args = parser.parse_args()
30+
log.set_log_level(args.log)
31+
return args
32+
33+
34+
def update_external_dependencies_comment(source_name, target_file):
35+
with open(target_file, 'r', encoding = 'utf-8') as file:
36+
lines = file.readlines()
37+
lines[1] = '# make sure the version is same to {}\n'.format(source_name)
38+
lines[2] = '# If your version is different from {},\n'.format(source_name)
39+
with open(target_file, 'w', encoding = 'utf-8') as file:
40+
file.writelines(lines)
41+
42+
43+
def main():
44+
start_time = time.time()
45+
change_to_repo_root_dir()
46+
args = get_args()
47+
log.debug('Current working directory = {}.'.format(os.getcwd()))
48+
file_name = get_spring_boot_managed_external_dependencies_file_name(args.spring_boot_dependencies_version)
49+
update_external_dependencies_comment(file_name, EXTERNAL_DEPENDENCIES_FILE)
50+
elapsed_time = time.time() - start_time
51+
log.info('elapsed_time = {}'.format(elapsed_time))
52+
53+
54+
def change_to_repo_root_dir():
55+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
56+
os.chdir('../../..')
57+
58+
59+
if __name__ == '__main__':
60+
main()

0 commit comments

Comments
 (0)