Release System: Auto Update 'Addon Table' URLs & Upload Addon Zips #123
@ -124,6 +124,17 @@ def write_file(file_path: Path, content):
|
||||
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:
|
||||
"""Returns directory PATH, creates one if none exists"""
|
||||
path = repo_root.joinpath(folder_name)
|
||||
@ -263,6 +274,20 @@ def changelog_file_write(file_path: Path, content: str):
|
||||
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):
|
||||
"""
|
||||
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(
|
||||
directory.joinpath("CHANGELOG.md"), change_log
|
||||
)
|
||||
table_file = update_release_table(directory, version)
|
||||
cli_command(f'git reset')
|
||||
cli_command(f'git stage {change_log_file}')
|
||||
cli_command(f'git stage {init_file}')
|
||||
cli_command(f'git stage {table_file}')
|
||||
subprocess.run(
|
||||
['git', 'commit', '-m', f"Version Bump: {directory.name} {version}"],
|
||||
capture_output=True,
|
||||
@ -352,10 +379,7 @@ def addon_version_bump(directory: Path, is_major: bool):
|
||||
lines = file.readlines()
|
||||
version = addon_version_get(lines[version_line], is_major)
|
||||
repl_str = f' "version": ({version}),\n'
|
||||
lines[version_line] = repl_str
|
||||
out = open(init_file, 'w')
|
||||
out.writelines(lines)
|
||||
out.close()
|
||||
replace_line(init_file, repl_str, version_line)
|
||||
return init_file, version.replace(', ', '.').replace(',', '.')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user