Release System: Auto Update 'Addon Table' URLs & Upload Addon Zips #123

Closed
Nick Alberelli wants to merge 3 commits from (deleted):feature/release-system-atuo-update-table into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 41da5ecfe4 - Show all commits

View File

@ -124,6 +124,17 @@ def write_file(file_path: Path, content):
file.close() file.close()
def replace_line(file_path: Path, new_line: str, line_number: int):
file = open(
file_path,
)
lines = file.readlines()
lines[line_number] = new_line
out = open(file_path, 'w')
out.writelines(lines)
out.close()
def get_directory(repo_root: Path, folder_name: str) -> Path: def get_directory(repo_root: Path, folder_name: str) -> Path:
"""Returns directory PATH, creates one if none exists""" """Returns directory PATH, creates one if none exists"""
path = repo_root.joinpath(folder_name) path = repo_root.joinpath(folder_name)
@ -263,6 +274,20 @@ def changelog_file_write(file_path: Path, content: str):
return file_path return file_path
def update_release_table(addon_dir: Path, version: str):
table_file = addon_dir.parent.parent.joinpath("README.md")
with open(table_file, 'r') as myFile:
for num, line in enumerate(myFile):
if addon_dir.name in line:
line_to_replace = num
break # Use first line found
splitted_line = line.split("|[v")
version_bump_text = splitted_line[1].replace(splitted_line[1][0:5], version)
new_line = line[: len(splitted_line[0]) + 3] + version_bump_text
replace_line(table_file, new_line, line_to_replace)
return table_file
def addon_package(directory: Path, commit_prefix: str, is_major=False, force=False): def addon_package(directory: Path, commit_prefix: str, is_major=False, force=False):
""" """
For a give directory, if new commits are found after the commit matching 'commit_prefix', For a give directory, if new commits are found after the commit matching 'commit_prefix',
@ -282,9 +307,11 @@ def addon_package(directory: Path, commit_prefix: str, is_major=False, force=Fal
change_log_file = changelog_file_write( change_log_file = changelog_file_write(
directory.joinpath("CHANGELOG.md"), change_log directory.joinpath("CHANGELOG.md"), change_log
) )
table_file = update_release_table(directory, version)
cli_command(f'git reset') cli_command(f'git reset')
cli_command(f'git stage {change_log_file}') cli_command(f'git stage {change_log_file}')
cli_command(f'git stage {init_file}') cli_command(f'git stage {init_file}')
cli_command(f'git stage {table_file}')
subprocess.run( subprocess.run(
['git', 'commit', '-m', f"Version Bump: {directory.name} {version}"], ['git', 'commit', '-m', f"Version Bump: {directory.name} {version}"],
capture_output=True, capture_output=True,
@ -352,10 +379,7 @@ def addon_version_bump(directory: Path, is_major: bool):
lines = file.readlines() lines = file.readlines()
version = addon_version_get(lines[version_line], is_major) version = addon_version_get(lines[version_line], is_major)
repl_str = f' "version": ({version}),\n' repl_str = f' "version": ({version}),\n'
lines[version_line] = repl_str replace_line(init_file, repl_str, version_line)
out = open(init_file, 'w')
out.writelines(lines)
out.close()
return init_file, version.replace(', ', '.').replace(',', '.') return init_file, version.replace(', ', '.').replace(',', '.')