15 """Execute given command"""
16 return subprocess
.check_output(cmd
).decode().strip()
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')
28 help='be more verbose')
30 args
= ap
.parse_args()
32 logging
.basicConfig(format
='[%(levelname)s] %(message)s')
34 logging
.getLogger().setLevel(level
=logging
.DEBUG
)
36 logging
.getLogger().setLevel(level
=logging
.INFO
)
39 def identify_next_version():
40 """Figure out the new version number"""
42 curversion
= exec(['git', 'describe', '--tags', '--match', 'cvc5-*'])
44 logging
.error('git describe was unable to produce a proper version')
46 logging
.debug('git version info: {}'.format(curversion
))
48 re_release
= re
.compile('^cvc5-(\d+)\.(\d+)\.(\d+)')
49 m
= re_release
.match(curversion
)
51 major
, minor
, patch
= map(int, m
.groups())
52 if args
.bump
== 'major':
56 elif args
.bump
== 'minor':
59 elif args
.bump
== 'patch':
61 version
= "{}.{}.{}".format(major
, minor
, patch
)
62 logging
.debug('target version: {}'.format(version
))
66 "Did not understand current git version: '{}'".format(curversion
))
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
)
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
])
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'])
96 if __name__
== '__main__':
99 # Compute next version
100 version
= identify_next_version()
103 logging
.info('Performing release commit')
104 generate_cmake_version_file(version
, True)
105 tagname
= make_release_commit(version
)
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
)
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
])
118 'If you are sure you want to push this release, use the following command:'
120 print('\tgit push --tags origin master')