[Asterisk-code-review] mkrelease.py: Generate new releases in a single commit. (repotools[master])

Corey Farrell asteriskteam at digium.com
Thu Sep 29 20:21:32 CDT 2016


Corey Farrell has uploaded a new change for review.

  https://gerrit.asterisk.org/4008

Change subject: mkrelease.py: Generate new releases in a single commit.
......................................................................

mkrelease.py: Generate new releases in a single commit.

Change-Id: Icb56b356ecc38ddb3683eb64bbc47947e9f07149
---
M mkrelease.py
1 file changed, 39 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/repotools refs/changes/08/4008/1

diff --git a/mkrelease.py b/mkrelease.py
index d9a9799..682f6fc 100755
--- a/mkrelease.py
+++ b/mkrelease.py
@@ -241,6 +241,22 @@
     repo    - Our local Git repo
     """
 
+    remove_files = []
+    generated_files = []
+    change_log_path = os.path.join(options.local_root, options.project, 'ChangeLog')
+    old_log_path = os.path.join(options.local_root, options.project, 'OldLog')
+
+    def get_old_changelog():
+        # Check out the start tag and copy over its ChangeLog
+        LOGGER.debug("Getting previous change log from '{0}'".format(start_version))
+        repo.checkout(start_version)
+        shutil.copyfile(change_log_path, old_log_path)
+        LOGGER.debug("Copied '{0}' to '{1}'".format(change_log_path, old_log_path))
+
+        # Switch back to our branch
+        LOGGER.debug("Switching back to {0}".format(branch))
+        repo.checkout(branch)
+
     def create_change_log(summary):
         """Create the change log for the release
 
@@ -267,21 +283,6 @@
             summary = ReleaseSummary(
                 sum_opts, debug=options.loglevel == logging.DEBUG)
 
-        change_log_path = os.path.join(options.local_root, options.project,
-                                       'ChangeLog')
-        old_log_path = os.path.join(options.local_root, options.project,
-                                    'OldLog')
-
-        # Check out the start tag and copy over its ChangeLog
-        LOGGER.debug("Getting previous change log from '{0}'".format(start_version))
-        repo.checkout(start_version)
-        shutil.copyfile(change_log_path, old_log_path)
-        LOGGER.debug("Copied '{0}' to '{1}'".format(change_log_path, old_log_path))
-
-        # Switch back to our branch
-        LOGGER.debug("Switching back to {0}".format(branch))
-        repo.checkout(branch)
-
         if os.path.isfile(change_log_path):
             LOGGER.debug("Removing old ChangeLog")
             os.unlink(change_log_path)
@@ -305,9 +306,7 @@
         LOGGER.debug("Removing temporary OldLog file")
         os.unlink(old_log_path)
 
-        LOGGER.debug("Commiting changes to ChangeLog")
-        repo.add_and_commit([change_log_path],
-                            "ChangeLog: Updated for {0}\n".format(version))
+        generated_files.append(change_log_path)
         return
 
     def create_release_summaries():
@@ -318,20 +317,18 @@
         """
 
         file_dir = os.path.join(options.local_root, options.project)
+        file_name = '{0}-summary'.format(release_name)
 
         # Remove any old summaries in the directory
-        removed = False
         for f_name in os.listdir(file_dir):
+            if f_name == '{0}.html'.format(file_name):
+                continue
+            if f_name == '{0}.txt'.format(file_name):
+                continue
+
             project = options.project
             if fnmatch.fnmatch(f_name, '{0}-*-summary.*'.format(project)):
-                LOGGER.debug("Removing old summary: '{0}'".format(f_name))
-                f_path = os.path.join(file_dir, f_name)
-                os.unlink(f_path)
-                repo.repo.git.rm(f_path)
-                removed = True
-        if removed:
-            msg = "Release summaries: Remove previous versions\n"
-            repo.repo.git.commit(message=msg)
+                remove_files.append(os.path.join(file_dir, f_name))
 
         sum_opts = ReleaseSummaryOptions()
         # For release summaries, we re-build the full release summary
@@ -357,7 +354,6 @@
             # New feature release of a major branch
             sum_opts.release_type = ReleaseSummaryOptions.RELEASE_TYPE_FEATURE
 
-        file_name = '{0}-summary'.format(release_name)
         file_path = os.path.join(file_dir, file_name)
 
         summary = ReleaseSummary(
@@ -365,10 +361,8 @@
         summary.to_html(out_file=file_path)
         LOGGER.debug("Release summaries created as '{0}'".format(file_path))
 
-        msg = "Release summaries: Add summaries for {0}\n".format(version)
-        repo.add_and_commit(['{0}.html'.format(file_path),
-                             '{0}.txt'.format(file_path)],
-                            msg)
+        generated_files.append('{0}.html'.format(file_path))
+        generated_files.append('{0}.txt'.format(file_path))
         return summary
 
     def create_version_file():
@@ -380,8 +374,7 @@
             ver_file.write(version)
 
         LOGGER.debug(".version file written as '{0}'".format(version))
-        repo.add_and_commit([ver_file_path],
-                            ".version: Update for {0}\n".format(version))
+        generated_files.append(ver_file_path)
         return
 
     def create_lastclean():
@@ -393,8 +386,7 @@
                                 options.project,
                                 '.lastclean')
         shutil.copyfile(src_file, dst_file)
-        repo.add_and_commit([dst_file],
-                            ".lastclean: Update for {0}\n".format(version))
+        generated_files.append(dst_file)
         return
 
     def create_database_scripts():
@@ -410,7 +402,6 @@
                                 options.project,
                                 'contrib/realtime')
         os.chdir(work_path)
-        generated_files = []
         for db in ['mysql', 'oracle', 'postgresql', 'mssql']:
 
             out_db_dir = os.path.join(out_path, db)
@@ -425,15 +416,23 @@
                     os.path.join(out_db_dir, "{0}_{1}.sql".format(db, script)))
 
         msg = "realtime: Add database scripts for {0}\n".format(version)
-        repo.add_and_commit(generated_files, msg)
         os.chdir(curdir)
         return
+
+    get_old_changelog()
+    summary = create_release_summaries()
+    # No more changing branches after this point.
+    create_change_log(summary)
 
     create_database_scripts()
     create_lastclean()
     create_version_file()
-    summary = create_release_summaries()
-    create_change_log(summary)
+
+    for f_path in remove_files:
+        os.unlink(f_path)
+        repo.repo.git.rm(f_path)
+    repo.add_and_commit(generated_files,
+                        "Update for {0}\n".format(version))
 
     prompt_to_continue("Confirm tag creation of '{0}'".format(version))
     repo.create_tag(version)

-- 
To view, visit https://gerrit.asterisk.org/4008
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb56b356ecc38ddb3683eb64bbc47947e9f07149
Gerrit-PatchSet: 1
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>



More information about the asterisk-code-review mailing list