Make release script create a GitHub release

This commit is contained in:
vitaut
2015-11-12 07:39:09 -08:00
parent 57ba9436a0
commit 11f946efff

View File

@ -2,7 +2,7 @@
# Release script # Release script
from __future__ import print_function from __future__ import print_function
import datetime, fileinput, re, sys import datetime, fileinput, json, os, re, requests, shutil, sys, tempfile
from docutils import nodes, writers, core from docutils import nodes, writers, core
from subprocess import check_call from subprocess import check_call
@ -125,33 +125,51 @@ class Runner:
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
check_call(args, cwd=self.cwd, **kwargs) check_call(args, cwd=self.cwd, **kwargs)
run = Runner() workdir = tempfile.mkdtemp()
run('git', 'clone', 'git@github.com:cppformat/cppformat.git') try:
run = Runner()
run('git', 'clone', 'git@github.com:cppformat/cppformat.git', workdir)
changelog = 'ChangeLog.rst' # Convert changelog from RST to GitHub-flavored Markdown and get the version.
changelog_path = 'cppformat/' + changelog changelog = 'ChangeLog.rst'
changes, version = core.publish_file(source_path=changelog_path, writer=MDWriter()) changelog_path = os.path.join(workdir, changelog)
for line in fileinput.input('cppformat/CMakeLists.txt', inplace=True): changes, version = core.publish_file(source_path=changelog_path, writer=MDWriter())
prefix = 'set(CPPFORMAT_VERSION ' cmakelists = 'CMakeLists.txt'
if line.startswith(prefix): for line in fileinput.input(os.path.join(workdir, cmakelists), inplace=True):
line = prefix + version + ')\n' prefix = 'set(CPPFORMAT_VERSION '
sys.stdout.write(line) if line.startswith(prefix):
line = prefix + version + ')\n'
sys.stdout.write(line)
title_len = 0 # Update the version in the changelog.
for line in fileinput.input(changelog_path, inplace=True): title_len = 0
if line.startswith(version + ' - TBD'): for line in fileinput.input(changelog_path, inplace=True):
line = version + ' - ' + datetime.date.today().isoformat() if line.startswith(version + ' - TBD'):
title_len = len(line) line = version + ' - ' + datetime.date.today().isoformat()
line += '\n' title_len = len(line)
elif title_len: line += '\n'
line = '-' * title_len + '\n' elif title_len:
title_len = 0 line = '-' * title_len + '\n'
sys.stdout.write(line) title_len = 0
sys.stdout.write(line)
run.cwd = workdir
run('git', 'checkout', '-b', 'release')
run('git', 'add', changelog, cmakelists)
run('git', 'commit', '-m', 'Update version')
run.cwd = 'cppformat' # Build the docs and package.
run('git', 'add', changelog, 'CMakeLists.txt') run('cmake', '.')
run('git', 'commit', '-m', 'Update version') run('make', 'doc', 'package_source')
run('cmake', '.')
run('make', 'doc', 'package_source')
# TODO: create a release on GitHub # Create a release on GitHub.
run('git', 'push', 'origin', 'release')
r = requests.post('https://api.github.com/repos/cppformat/cppformat/releases',
params={'access_token': os.getenv('CPPFORMAT_TOKEN')},
data=json.dumps({'tag_name': version, 'target_commitish': 'release',
'body': changes, 'draft': True}))
if r.status_code != 201:
raise Exception('Failed to create a release ' + str(r))
# TODO: update website
finally:
shutil.rmtree(workdir)