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