Fix GLPK linking (#7357)
[cvc5.git] / contrib / make-release.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import collections
5 import logging
6 import os
7 import re
8 import subprocess
9 import sys
10
11 args = None
12
13
14 def exec(cmd):
15 """Execute given command"""
16 return subprocess.check_output(cmd).decode().strip()
17
18
19 def parse_options():
20 """Handle command line options"""
21 ap = argparse.ArgumentParser(description='Make a new release')
22 ap.add_argument('bump',
23 choices=['major', 'minor', 'patch'],
24 help='which version part to bump')
25 ap.add_argument('-v',
26 '--verbose',
27 action='store_true',
28 help='be more verbose')
29 global args
30 args = ap.parse_args()
31
32 logging.basicConfig(format='[%(levelname)s] %(message)s')
33 if args.verbose:
34 logging.getLogger().setLevel(level=logging.DEBUG)
35 else:
36 logging.getLogger().setLevel(level=logging.INFO)
37
38
39 def identify_next_version():
40 """Figure out the new version number"""
41 try:
42 curversion = exec(['git', 'describe', '--tags', '--match', 'cvc5-*'])
43 except:
44 logging.error('git describe was unable to produce a proper version')
45 sys.exit(1)
46 logging.debug('git version info: {}'.format(curversion))
47
48 re_release = re.compile('^cvc5-(\d+)\.(\d+)\.(\d+)')
49 m = re_release.match(curversion)
50 if m:
51 major, minor, patch = map(int, m.groups())
52 if args.bump == 'major':
53 major += 1
54 minor = 0
55 patch = 0
56 elif args.bump == 'minor':
57 minor += 1
58 patch = 0
59 elif args.bump == 'patch':
60 patch += 1
61 version = "{}.{}.{}".format(major, minor, patch)
62 logging.debug('target version: {}'.format(version))
63 return version
64
65 logging.error(
66 "Did not understand current git version: '{}'".format(curversion))
67 sys.exit(1)
68
69
70 def generate_cmake_version_file(version, is_release):
71 """Update the cmake version file"""
72 filename = os.path.join(os.path.dirname(os.path.dirname(__file__)),
73 'cmake/version-base.cmake')
74 tpl = open(filename + '.template').read()
75 tpl = tpl.replace('{{VERSION}}', version)
76 tpl = tpl.replace('{{IS_RELEASE}}', 'true' if is_release else 'false')
77 open(filename, 'w').write(tpl)
78
79
80 def make_release_commit(version):
81 """Make the release commit"""
82 tagname = 'cvc5-{}'.format(version)
83 exec(['git', 'add', 'cmake/version-base.cmake'])
84 exec(['git', 'commit', '-m', 'Bump version to {}'.format(version)])
85 exec(['git', 'tag', tagname])
86 return tagname
87
88
89 def make_post_release_commit(version):
90 """Make the post-release commit"""
91 exec(['git', 'add', 'cmake/version-base.cmake'])
92 exec(['git', 'commit', '-m', 'Start post-release for {}'.format(version)])
93 return exec(['git', 'rev-parse', 'HEAD'])
94
95
96 if __name__ == '__main__':
97 parse_options()
98
99 # Compute next version
100 version = identify_next_version()
101
102 # release commit
103 logging.info('Performing release commit')
104 generate_cmake_version_file(version, True)
105 tagname = make_release_commit(version)
106
107 # post-release commit
108 logging.info('Performing post-release commit')
109 generate_cmake_version_file(version, False)
110 postcommit = make_post_release_commit(version)
111
112 # Show commits and ask user to push
113 print('Please check the following commits carefully:')
114 subprocess.call(['git', 'show', tagname])
115 subprocess.call(['git', 'show', postcommit])
116
117 print(
118 'If you are sure you want to push this release, use the following command:'
119 )
120 print('\tgit push --tags origin master')