File: update_version.py

package info (click to toggle)
mysql-8.0 8.0.43-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,904 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,184; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,196; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (59 lines) | stat: -rwxr-xr-x 1,849 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys, re
from datetime import date
import logging

logging.basicConfig(level=logging.INFO)

# Update version label in all configuration files
# Usage: python3 misc/update_version.py X.Y.Z

# When testing, reset local state using:
# git checkout -- CHANGELOG.md Doxyfile CMakeLists.txt doc/source/conf.py examples/bazel/third_party/libcbor/cbor/configuration.h

version = sys.argv[1]
release_date = date.today().strftime('%Y-%m-%d')
major, minor, patch = version.split('.')


def replace(file_path, pattern, replacement):
    logging.info(f'Updating {file_path}')
    original = open(file_path).read()
    updated = re.sub(pattern, replacement, original)
    assert updated != original
    with open(file_path, 'w') as f:
        f.write(updated)

# Update changelog
SEP = '---------------------'
NEXT = f'Next\n{SEP}'
changelog_header = f'{NEXT}\n\n{version} ({release_date})\n{SEP}'
replace('CHANGELOG.md', NEXT, changelog_header)

# Update Doxyfile
DOXY_VERSION = 'PROJECT_NUMBER         = '
replace('Doxyfile', DOXY_VERSION + '.*', DOXY_VERSION + version)

# Update CMakeLists.txt
replace('CMakeLists.txt',
        '''SET\\(CBOR_VERSION_MAJOR "\d+"\\)
SET\\(CBOR_VERSION_MINOR "\d+"\\)
SET\\(CBOR_VERSION_PATCH "\d+"\\)''',
        f'''SET(CBOR_VERSION_MAJOR "{major}")
SET(CBOR_VERSION_MINOR "{minor}")
SET(CBOR_VERSION_PATCH "{patch}")''')

# Update Basel build example
replace('examples/bazel/third_party/libcbor/cbor/configuration.h',
        '''#define CBOR_MAJOR_VERSION \d+
#define CBOR_MINOR_VERSION \d+
#define CBOR_PATCH_VERSION \d+''',
        f'''#define CBOR_MAJOR_VERSION {major}
#define CBOR_MINOR_VERSION {minor}
#define CBOR_PATCH_VERSION {patch}''')

# Update Sphinx
replace('doc/source/conf.py',
        """version = '.*'
release = '.*'""",
        f"""version = '{major}.{minor}'
release = '{major}.{minor}.{patch}'""")