Skip to content

Commit

Permalink
Update update_version.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rysiulg authored Nov 6, 2024
1 parent 1e71c25 commit 00b2d9c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ 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}')

# Replace unreleased section in CHANGELOG.md
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}')

0 comments on commit 00b2d9c

Please sign in to comment.