Path: blob/main/contrib/libcbor/misc/update_version.py
39536 views
import sys, re1from datetime import date2import logging34logging.basicConfig(level=logging.INFO)56# Update version label in all configuration files7# Usage: python3 misc/update_version.py X.Y.Z89# When testing, reset local state using:10# git checkout -- CHANGELOG.md Doxyfile CMakeLists.txt doc/source/conf.py examples/bazel/third_party/libcbor/cbor/configuration.h1112version = sys.argv[1]13release_date = date.today().strftime('%Y-%m-%d')14major, minor, patch = version.split('.')151617def replace(file_path, pattern, replacement):18logging.info(f'Updating {file_path}')19original = open(file_path).read()20updated = re.sub(pattern, replacement, original)21assert updated != original22with open(file_path, 'w') as f:23f.write(updated)2425# Update changelog26SEP = '---------------------'27NEXT = f'Next\n{SEP}'28changelog_header = f'{NEXT}\n\n{version} ({release_date})\n{SEP}'29replace('CHANGELOG.md', NEXT, changelog_header)3031# Update Doxyfile32DOXY_VERSION = 'PROJECT_NUMBER = '33replace('Doxyfile', DOXY_VERSION + '.*', DOXY_VERSION + version)3435# Update CMakeLists.txt36replace('CMakeLists.txt',37'''SET\\(CBOR_VERSION_MAJOR "\d+"\\)38SET\\(CBOR_VERSION_MINOR "\d+"\\)39SET\\(CBOR_VERSION_PATCH "\d+"\\)''',40f'''SET(CBOR_VERSION_MAJOR "{major}")41SET(CBOR_VERSION_MINOR "{minor}")42SET(CBOR_VERSION_PATCH "{patch}")''')4344# Update Basel build example45replace('examples/bazel/third_party/libcbor/cbor/configuration.h',46'''#define CBOR_MAJOR_VERSION \d+47#define CBOR_MINOR_VERSION \d+48#define CBOR_PATCH_VERSION \d+''',49f'''#define CBOR_MAJOR_VERSION {major}50#define CBOR_MINOR_VERSION {minor}51#define CBOR_PATCH_VERSION {patch}''')5253# Update Sphinx54replace('doc/source/conf.py',55"""version = '.*'56release = '.*'""",57f"""version = '{major}.{minor}'58release = '{major}.{minor}.{patch}'""")596061