xref: /freebsd/contrib/libcbor/misc/update_version.py (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1import sys, re
2from datetime import date
3
4version = sys.argv[1]
5release_date = date.today().strftime('%Y-%m-%d')
6major, minor, patch = version.split('.')
7
8
9def replace(file_path, pattern, replacement):
10    updated = re.sub(pattern, replacement, open(file_path).read())
11    with open(file_path, 'w') as f:
12        f.write(updated)
13
14# Update changelog
15SEP = '---------------------'
16NEXT = f'Next\n{SEP}'
17changelog_header = f'{NEXT}\n\n{version} ({release_date})\n{SEP}'
18replace('CHANGELOG.md', NEXT, changelog_header)
19
20# Update Doxyfile
21DOXY_VERSION = 'PROJECT_NUMBER         = '
22replace('Doxyfile', DOXY_VERSION + '.*', DOXY_VERSION + version)
23
24# Update CMakeLists.txt
25replace('CMakeLists.txt',
26        '''SET\\(CBOR_VERSION_MAJOR "0"\\)
27SET\\(CBOR_VERSION_MINOR "7"\\)
28SET\\(CBOR_VERSION_PATCH "0"\\)''',
29        f'''SET(CBOR_VERSION_MAJOR "{major}")
30SET(CBOR_VERSION_MINOR "{minor}")
31SET(CBOR_VERSION_PATCH "{patch}")''')
32
33# Update Sphinx
34replace('doc/source/conf.py',
35        """version = '.*'
36release = '.*'""",
37        f"""version = '{major}.{minor}'
38release = '{major}.{minor}.{patch}'""")
39