From dcb086cb35d8ae94117d6ebe6be0acee491a5c20 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:24:36 +0100 Subject: [PATCH 1/3] Init of script to prepare a release --- preprelease.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 preprelease.py diff --git a/preprelease.py b/preprelease.py new file mode 100644 index 0000000..b36ad85 --- /dev/null +++ b/preprelease.py @@ -0,0 +1,63 @@ +import os +import json +import shutil +from urllib.parse import urlparse + +def get_current_version_from_link(link): + parsed_url = urlparse(link) + path_parts = parsed_url.path.split('/') + current_version = path_parts[-1] + return current_version + +def update_readme_version(readme_path, new_version): + with open(readme_path, 'r') as readme_file: + readme_content = readme_file.read() + + old_version_link = 'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/' + get_current_version_from_link(readme_content) + new_version_link = f'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/{new_version}' + + updated_readme_content = readme_content.replace(old_version_link, new_version_link) + + with open(readme_path, 'w') as readme_file: + readme_file.write(updated_readme_content) + +def update_json_version(file_path, new_version): + with open(file_path, 'r') as json_file: + data = json.load(json_file) + + data['version'] = new_version + + with open(file_path, 'w') as json_file: + json.dump(data, json_file, indent=2) + +def zip_files(source_folder, output_zip_path): + with shutil.ZipFile(output_zip_path, 'w') as zip_file: + for root, dirs, files in os.walk(source_folder): + for file in files: + file_path = os.path.join(root, file) + arcname = os.path.relpath(file_path, source_folder) + zip_file.write(file_path, arcname=arcname) + +def main(new_version): + plugin_folder = 'obsidian-gamified-pkm' + readme_path = os.path.join(plugin_folder, 'README.md') + manifest_path = os.path.join(plugin_folder, 'manifest.json') + package_path = os.path.join(plugin_folder, 'package.json') + + # Update README.md + update_readme_version(readme_path, new_version) + + # Update manifest.json + update_json_version(manifest_path, new_version) + + # Update package.json + update_json_version(package_path, new_version) + + # Zip files + files_to_zip = ['main.js', 'manifest.json', 'styles.css'] + zip_folder = os.path.join(plugin_folder, f'obsidian-gamified-pkm.zip') + zip_files(plugin_folder, zip_folder) + +if __name__ == "__main__": + new_version = input("Enter the new version: ") + main(new_version) From 2e9f35203a1135e91fec5d06c46cf8bab8babe7b Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Mon, 27 Nov 2023 20:47:11 +0100 Subject: [PATCH 2/3] Enters release link correctly into README.md --- preprelease.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/preprelease.py b/preprelease.py index b36ad85..6b9170c 100644 --- a/preprelease.py +++ b/preprelease.py @@ -3,24 +3,43 @@ import shutil from urllib.parse import urlparse -def get_current_version_from_link(link): - parsed_url = urlparse(link) - path_parts = parsed_url.path.split('/') - current_version = path_parts[-1] - return current_version + +def get_current_version_from_link(content): + link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/') + if link_start == -1: + return None + + link_end = content.find(')', link_start) + if link_end == -1: + link_end = content.find(']', link_start) + if link_end == -1: + link_end = len(content) + + link = content[link_start:link_end] + parsed_url = urlparse(link) + path_parts = parsed_url.path.split('/') + current_version = path_parts[-1] + return current_version + def update_readme_version(readme_path, new_version): - with open(readme_path, 'r') as readme_file: + with open(readme_path, 'r', encoding='utf-8') as readme_file: readme_content = readme_file.read() - old_version_link = 'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/' + get_current_version_from_link(readme_content) + old_version = get_current_version_from_link(readme_content) + if old_version is None: + print("Unable to extract the current version from the README.md file.") + return + + old_version_link = f'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/{old_version}' new_version_link = f'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/{new_version}' updated_readme_content = readme_content.replace(old_version_link, new_version_link) - with open(readme_path, 'w') as readme_file: + with open(readme_path, 'w', encoding='utf-8') as readme_file: readme_file.write(updated_readme_content) + def update_json_version(file_path, new_version): with open(file_path, 'r') as json_file: data = json.load(json_file) @@ -39,7 +58,7 @@ def zip_files(source_folder, output_zip_path): zip_file.write(file_path, arcname=arcname) def main(new_version): - plugin_folder = 'obsidian-gamified-pkm' + plugin_folder = '.' readme_path = os.path.join(plugin_folder, 'README.md') manifest_path = os.path.join(plugin_folder, 'manifest.json') package_path = os.path.join(plugin_folder, 'package.json') From b41aa01bdf2420caf25cbc0ac2eb9d3a6c6a929d Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Mon, 27 Nov 2023 21:06:10 +0100 Subject: [PATCH 3/3] ZIP plugin files for easy use --- preprelease.py | 61 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/preprelease.py b/preprelease.py index 6b9170c..7f3cea2 100644 --- a/preprelease.py +++ b/preprelease.py @@ -1,25 +1,34 @@ import os import json import shutil +import zipfile from urllib.parse import urlparse +def zip_files(source_folder, output_zip_path, files_to_zip): + with zipfile.ZipFile(output_zip_path, 'w') as zip_file: + for file_to_zip in files_to_zip: + file_path = os.path.join(source_folder, file_to_zip) + zip_file.write(file_path, arcname=file_to_zip) + + + def get_current_version_from_link(content): - link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/') - if link_start == -1: - return None + link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/') + if link_start == -1: + return None - link_end = content.find(')', link_start) - if link_end == -1: - link_end = content.find(']', link_start) - if link_end == -1: - link_end = len(content) + link_end = content.find(')', link_start) + if link_end == -1: + link_end = content.find(']', link_start) + if link_end == -1: + link_end = len(content) - link = content[link_start:link_end] - parsed_url = urlparse(link) - path_parts = parsed_url.path.split('/') - current_version = path_parts[-1] - return current_version + link = content[link_start:link_end] + parsed_url = urlparse(link) + path_parts = parsed_url.path.split('/') + current_version = path_parts[-1] + return current_version def update_readme_version(readme_path, new_version): @@ -49,13 +58,13 @@ def update_json_version(file_path, new_version): with open(file_path, 'w') as json_file: json.dump(data, json_file, indent=2) -def zip_files(source_folder, output_zip_path): - with shutil.ZipFile(output_zip_path, 'w') as zip_file: - for root, dirs, files in os.walk(source_folder): - for file in files: - file_path = os.path.join(root, file) - arcname = os.path.relpath(file_path, source_folder) - zip_file.write(file_path, arcname=arcname) +#def zip_files(source_folder, output_zip_path): +# with shutil.ZipFile(output_zip_path, 'w') as zip_file: +# for root, dirs, files in os.walk(source_folder): +# for file in files: +# file_path = os.path.join(root, file) +# arcname = os.path.relpath(file_path, source_folder) +# zip_file.write(file_path, arcname=arcname) def main(new_version): plugin_folder = '.' @@ -75,7 +84,17 @@ def main(new_version): # Zip files files_to_zip = ['main.js', 'manifest.json', 'styles.css'] zip_folder = os.path.join(plugin_folder, f'obsidian-gamified-pkm.zip') - zip_files(plugin_folder, zip_folder) + zip_files(plugin_folder, zip_folder, files_to_zip) + + # Move the zip archive to the 'install-zip' subfolder + install_zip_folder = os.path.join(plugin_folder, 'obsidian-gamified-pkm') + os.makedirs(install_zip_folder, exist_ok=True) + + # Create the new path for the zip archive in the 'install-zip' folder + new_zip_path = os.path.join(install_zip_folder, f'obsidian-gamified-pkm.zip') + + # Move the zip archive + shutil.move(zip_folder, new_zip_path) if __name__ == "__main__": new_version = input("Enter the new version: ")