From 00b2d9ca433205f7b99b21a8cf20758fc9965f25 Mon Sep 17 00:00:00 2001 From: rysiulg Date: Wed, 6 Nov 2024 23:15:09 +0100 Subject: [PATCH] Update update_version.py --- .github/scripts/update_version.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/update_version.py b/.github/scripts/update_version.py index 6872719..8cf6153 100644 --- a/.github/scripts/update_version.py +++ b/.github/scripts/update_version.py @@ -27,13 +27,13 @@ def construct_yaml_str(self, node): with open(YAML_FILE, 'r') as yaml_file: yaml_content = yaml.load(yaml_file, Loader=IgnoreTagsLoader) -# Update the version field under esphome +# Update the version field under esphome if available if 'esphome' in yaml_content and 'project' in yaml_content['esphome']: yaml_content['esphome']['project']['version'] = new_version # Use the default YAML Dumper to maintain order and write back the modified YAML with open(YAML_FILE, 'w') as yaml_file: - yaml.safe_dump(yaml_content, yaml_file, default_flow_style=False, sort_keys=False) + yaml.safe_dump(yaml_content, yaml_file, default_flow_style=False, sort_keys=False, allow_unicode=True) print(f'Updated version to {new_version} in {YAML_FILE}') @@ -41,16 +41,16 @@ def construct_yaml_str(self, node): with open(CHANGELOG_FILE, 'r') as f: changelog = f.read() -# Update the [Unreleased] section with the new version and date in the format: -# ## [1.2.3] - 2024-11-06 +# Insert "## [Unreleased]\n### Changed:\n- " before the new version part updated_changelog = re.sub( r'\[Unreleased\](.*?)\n##', - f'## [{new_version}] - {current_date}\\1\n##', + f'## [Unreleased]\n### Changed:\n- \n[{new_version}] - {current_date}\\1\n', changelog, flags=re.DOTALL ) +# Write updated changelog to the file with open(CHANGELOG_FILE, 'w') as f: f.write(updated_changelog) -print(f'Replaced [Unreleased] with [{new_version}] - {current_date} in {CHANGELOG_FILE}') +print(f'Replaced [Unreleased] with ## [Unreleased]\n### Changed:\n- \n[{new_version}] - {current_date} in {CHANGELOG_FILE}')