From 43b495c511e7e3b1292daae266bbc78e1459de1f Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Thu, 11 Jun 2015 12:48:33 -0700 Subject: [PATCH] Teach roll_versions.py how to update CHANGELOG.md files. This is feature creep. But it was simple and fun. :p R=abarth@chromium.org Review URL: https://codereview.chromium.org/1175393002. --- engine/src/flutter/tools/roll_versions.py | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tools/roll_versions.py b/engine/src/flutter/tools/roll_versions.py index 0108cca0156..ec9adc7afb5 100755 --- a/engine/src/flutter/tools/roll_versions.py +++ b/engine/src/flutter/tools/roll_versions.py @@ -3,9 +3,12 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import os +import subprocess import yaml import xml.etree.ElementTree as ET + PUBSPECS = [ 'sky/sdk/pubspec.yaml', 'mojo/public/dart/pubspec.yaml', @@ -38,6 +41,15 @@ def sort_dict(unsorted): return sorted_dict +def count_commits(start, end): + return subprocess.check_output([ + 'git', 'rev-list', '%s...%s' % (start, end)]).count('\n') + + +def last_commit_to(file_path): + return subprocess.check_output(['git', 'log', '-1', '--format=%h', file_path]).strip() + + def update_pubspec(pubspec): # TODO(eseidel): This does not prserve any manual sort-order of the yaml. with open(pubspec, 'r') as stream: @@ -48,6 +60,20 @@ def update_pubspec(pubspec): with open(pubspec, 'w') as stream: yaml.dump(spec, stream=stream, default_flow_style=False) + return spec['version'] + + +def update_changelog(changelog, pubspec, version): + old = last_commit_to(pubspec) + new = last_commit_to('.') + url = "https://github.com/domokit/mojo/compare/%s...%s" % (old, new) + count = count_commits(old, new) + message = """## %s + + - %s changes: %s + +""" % (version, count, url) + prepend_to_file(message, changelog) def prepend_to_file(to_prepend, filepath): @@ -77,9 +103,13 @@ def update_manifest(manifest): def main(): + # Should chdir to the root directory. + print 'Pub packages:' for pubspec in PUBSPECS: - update_pubspec(pubspec) + new_version = update_pubspec(pubspec) + changelog = os.path.join(os.path.dirname(pubspec), 'CHANGELOG.md') + update_changelog(changelog, pubspec, new_version) # TODO(eseidel): Without this ET uses 'ns0' for 'android' which is wrong. ET.register_namespace('android', 'http://schemas.android.com/apk/res/android')