Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/libcbor/misc/update_version.py
39536 views
1
import sys, re
2
from datetime import date
3
import logging
4
5
logging.basicConfig(level=logging.INFO)
6
7
# Update version label in all configuration files
8
# Usage: python3 misc/update_version.py X.Y.Z
9
10
# When testing, reset local state using:
11
# git checkout -- CHANGELOG.md Doxyfile CMakeLists.txt doc/source/conf.py examples/bazel/third_party/libcbor/cbor/configuration.h
12
13
version = sys.argv[1]
14
release_date = date.today().strftime('%Y-%m-%d')
15
major, minor, patch = version.split('.')
16
17
18
def replace(file_path, pattern, replacement):
19
logging.info(f'Updating {file_path}')
20
original = open(file_path).read()
21
updated = re.sub(pattern, replacement, original)
22
assert updated != original
23
with open(file_path, 'w') as f:
24
f.write(updated)
25
26
# Update changelog
27
SEP = '---------------------'
28
NEXT = f'Next\n{SEP}'
29
changelog_header = f'{NEXT}\n\n{version} ({release_date})\n{SEP}'
30
replace('CHANGELOG.md', NEXT, changelog_header)
31
32
# Update Doxyfile
33
DOXY_VERSION = 'PROJECT_NUMBER = '
34
replace('Doxyfile', DOXY_VERSION + '.*', DOXY_VERSION + version)
35
36
# Update CMakeLists.txt
37
replace('CMakeLists.txt',
38
'''SET\\(CBOR_VERSION_MAJOR "\d+"\\)
39
SET\\(CBOR_VERSION_MINOR "\d+"\\)
40
SET\\(CBOR_VERSION_PATCH "\d+"\\)''',
41
f'''SET(CBOR_VERSION_MAJOR "{major}")
42
SET(CBOR_VERSION_MINOR "{minor}")
43
SET(CBOR_VERSION_PATCH "{patch}")''')
44
45
# Update Basel build example
46
replace('examples/bazel/third_party/libcbor/cbor/configuration.h',
47
'''#define CBOR_MAJOR_VERSION \d+
48
#define CBOR_MINOR_VERSION \d+
49
#define CBOR_PATCH_VERSION \d+''',
50
f'''#define CBOR_MAJOR_VERSION {major}
51
#define CBOR_MINOR_VERSION {minor}
52
#define CBOR_PATCH_VERSION {patch}''')
53
54
# Update Sphinx
55
replace('doc/source/conf.py',
56
"""version = '.*'
57
release = '.*'""",
58
f"""version = '{major}.{minor}'
59
release = '{major}.{minor}.{patch}'""")
60
61