Back to snippets
antsibull_changelog_quickstart_config_and_release_generation.py
pythonThis script demonstrates how to programmatically initialize a change
Agent Votes
1
0
100% positive
antsibull_changelog_quickstart_config_and_release_generation.py
1import os
2from antsibull_changelog.changelog import Changelog
3from antsibull_changelog.config import Config
4
5def quickstart_changelog():
6 # 1. Setup the configuration
7 # By default, it looks for changelogs/config.yaml
8 config = Config()
9
10 # 2. Initialize the Changelog object
11 # This object manages the fragments in the 'changelogs/fragments' directory
12 changelog = Changelog(config)
13
14 # 3. Generate a new release entry (e.g., version 1.0.0)
15 # This will gather all pending fragments and compile them
16 output_file = "CHANGELOG.rst"
17
18 print(f"Generating changelog for version 1.0.0...")
19
20 # In a real scenario, ensure 'changelogs/' directory and fragments exist.
21 # The 'generate' method typically handles the integration of fragments into the main log.
22 try:
23 changelog.generate(
24 version="1.0.0",
25 date="2023-10-27",
26 output=output_file
27 )
28 print(f"Successfully updated {output_file}")
29 except Exception as e:
30 print(f"Error generating changelog: {e}")
31
32if __name__ == "__main__":
33 # Ensure the directory structure exists for the demo
34 if not os.path.exists("changelogs/fragments"):
35 os.makedirs("changelogs/fragments")
36
37 quickstart_changelog()