feat: improve changelog update script to handle absolute paths and create new changelog if missing
This commit is contained in:
parent
ab33f423c8
commit
7bdebeab03
@ -3,7 +3,14 @@ import re
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
with open('../platformio.ini', 'r') as f:
|
# Get the script's directory
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
# Get the project root directory (one level up)
|
||||||
|
project_dir = os.path.dirname(script_dir)
|
||||||
|
|
||||||
|
platformio_path = os.path.join(project_dir, 'platformio.ini')
|
||||||
|
|
||||||
|
with open(platformio_path, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
version_match = re.search(r'version\s*=\s*"([^"]+)"', content)
|
version_match = re.search(r'version\s*=\s*"([^"]+)"', content)
|
||||||
return version_match.group(1) if version_match else None
|
return version_match.group(1) if version_match else None
|
||||||
@ -12,6 +19,11 @@ def update_changelog():
|
|||||||
version = get_version()
|
version = get_version()
|
||||||
today = datetime.now().strftime('%Y-%m-%d')
|
today = datetime.now().strftime('%Y-%m-%d')
|
||||||
|
|
||||||
|
# Get absolute paths
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
project_dir = os.path.dirname(script_dir)
|
||||||
|
changelog_path = os.path.join(project_dir, 'CHANGELOG.md')
|
||||||
|
|
||||||
changelog_template = f"""## [{version}] - {today}
|
changelog_template = f"""## [{version}] - {today}
|
||||||
### Added
|
### Added
|
||||||
-
|
-
|
||||||
@ -23,14 +35,21 @@ def update_changelog():
|
|||||||
-
|
-
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open('../CHANGELOG.md', 'r') as f:
|
if not os.path.exists(changelog_path):
|
||||||
content = f.read()
|
# Create new changelog if it doesn't exist
|
||||||
|
with open(changelog_path, 'w') as f:
|
||||||
# Insert new version template after the header
|
f.write(f"# Changelog\n\n{changelog_template}")
|
||||||
updated_content = content.replace("# Changelog\n", f"# Changelog\n\n{changelog_template}")
|
else:
|
||||||
|
# Update existing changelog
|
||||||
with open('../CHANGELOG.md', 'w') as f:
|
with open(changelog_path, 'r') as f:
|
||||||
f.write(updated_content)
|
content = f.read()
|
||||||
|
|
||||||
|
if f"[{version}]" not in content:
|
||||||
|
# Only add new version if it doesn't exist
|
||||||
|
updated_content = content.replace("# Changelog\n", f"# Changelog\n\n{changelog_template}")
|
||||||
|
|
||||||
|
with open(changelog_path, 'w') as f:
|
||||||
|
f.write(updated_content)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
update_changelog()
|
update_changelog()
|
Loading…
x
Reference in New Issue
Block a user