2017-12-07 18:03:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Read the Docs invoke tasks."""
|
|
|
|
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
|
|
|
|
import os
|
|
|
|
import textwrap
|
|
|
|
|
2017-12-15 03:50:05 +00:00
|
|
|
from dateutil.parser import parse
|
2017-12-07 18:03:00 +00:00
|
|
|
from future.moves.configparser import RawConfigParser
|
2017-12-15 03:50:05 +00:00
|
|
|
from invoke import task, Exit
|
2017-12-07 18:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def prepare(ctx, version):
|
|
|
|
"""
|
|
|
|
Prepare the next release version by updating files.
|
|
|
|
|
|
|
|
This will stage a few updates for manual review and commit:
|
|
|
|
|
|
|
|
* Prepend the most recent PRs and issues that were closed to CHANGELOG.rst.
|
|
|
|
* Update the setup.cfg version
|
|
|
|
|
|
|
|
Changelog uses the file modification date to track the last time it was
|
|
|
|
updated. New entries will end up at the top of the file, under a heading
|
|
|
|
for the new version.
|
|
|
|
"""
|
2017-12-15 03:50:05 +00:00
|
|
|
# Ensure we're on the master branch first
|
|
|
|
git_rev_parse = ctx.run('git rev-parse --abbrev-ref HEAD', hide=True)
|
|
|
|
current_branch = git_rev_parse.stdout.strip()
|
|
|
|
if current_branch != 'rel':
|
|
|
|
print('You must be on master branch!')
|
|
|
|
raise Exit(1)
|
|
|
|
|
2017-12-07 18:03:00 +00:00
|
|
|
print('Updating release version in setup.cfg')
|
|
|
|
setupcfg_path = os.path.join(os.path.dirname(__file__), 'setup.cfg')
|
|
|
|
config = RawConfigParser()
|
|
|
|
config.read(setupcfg_path)
|
|
|
|
config.set('metadata', 'version', version)
|
|
|
|
with open(setupcfg_path, 'wb') as configfile:
|
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
print('Installing github-changelog')
|
2017-12-15 03:50:05 +00:00
|
|
|
# Get last modified date from Git instead of assuming the file metadata is
|
|
|
|
# correct. This can change depending on git reset, etc.
|
|
|
|
git_log = ctx.run('git log -1 --format="%ad" -- CHANGELOG.rst')
|
|
|
|
last_modified = parse(git_log.stdout.strip()).strftime('%Y-%m-%d')
|
|
|
|
# Install and run
|
2017-12-07 18:03:00 +00:00
|
|
|
ctx.run('npm install git+https://github.com/agjohnson/github-changelog.git')
|
|
|
|
changelog_path = os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst')
|
|
|
|
template_path = os.path.join(
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
'contrib',
|
|
|
|
'changelog.hbs',
|
|
|
|
)
|
2017-12-14 19:27:42 +00:00
|
|
|
bin_path = os.path.join(
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
'node_modules',
|
|
|
|
'.bin',
|
|
|
|
)
|
2017-12-07 18:03:00 +00:00
|
|
|
cmd = (
|
2017-12-14 19:27:42 +00:00
|
|
|
'{bin_path}/gh-changelog '
|
2017-12-07 18:03:00 +00:00
|
|
|
'-o rtfd -r readthedocs.org '
|
|
|
|
'--file {changelog_path} '
|
2017-12-15 03:50:05 +00:00
|
|
|
'--since {last_modified} '
|
2017-12-07 18:03:00 +00:00
|
|
|
'--template {template_path} '
|
|
|
|
'--header "Version {version}"'
|
|
|
|
).format(
|
2017-12-14 19:27:42 +00:00
|
|
|
bin_path=bin_path,
|
2017-12-07 18:03:00 +00:00
|
|
|
version=version,
|
|
|
|
template_path=template_path,
|
|
|
|
changelog_path=changelog_path,
|
2017-12-15 03:50:05 +00:00
|
|
|
last_modified=last_modified,
|
2017-12-07 18:03:00 +00:00
|
|
|
) # yapf: disable
|
|
|
|
try:
|
|
|
|
token = os.environ['GITHUB_TOKEN']
|
|
|
|
cmd += '--token ' + token + ' '
|
|
|
|
except KeyError:
|
|
|
|
print('')
|
|
|
|
print(
|
|
|
|
'\n'.join(
|
|
|
|
textwrap.wrap(
|
|
|
|
'In order to avoid rate limiting on the GitHub API, you can specify '
|
|
|
|
'an environment variable `GITHUB_TOKEN` with a personal access token. '
|
|
|
|
'There is no need for the token to have any permissions unless the '
|
|
|
|
'repoistory is private.')))
|
|
|
|
print('')
|
|
|
|
print('Updating changelog')
|
|
|
|
ctx.run(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def release(ctx, version):
|
|
|
|
"""
|
|
|
|
Tag release of Read the Docs.
|
|
|
|
|
|
|
|
Do this after prepare task and manual cleanup/commit
|
|
|
|
"""
|
|
|
|
ctx.run(
|
2017-12-15 03:50:05 +00:00
|
|
|
('git tag {version} && '
|
2017-12-07 18:03:00 +00:00
|
|
|
'git push --tags').format(version=version))
|