Use latest Int/Pack repo commit hash as sysd_commit var 71/53671/5
authorAkshita Jha <zenith158@gmail.com>
Fri, 24 Mar 2017 20:09:52 +0000 (01:39 +0530)
committerAkshita Jha <zenith158@gmail.com>
Fri, 24 Mar 2017 20:09:52 +0000 (01:39 +0530)
This adds logic to use the latest Int/Pack repo commit hash as sysd_commit
var unless passed by param.

Change-Id: I7b1e703648fb2eee6b8ed962532126276f7a12d9
Signed-off-by: Akshita Jha <zenith158@gmail.com>
rpm/build.py

index b42e353b4d6d5ac5c5ccf863b56ee63dbc71be55..fccc849fac2ad3c455980e6987e44f77af55ee90 100755 (executable)
@@ -239,6 +239,21 @@ def build_snapshot_rpm(build):
         build_rpm(build)
 
 
+def get_sysd_commit():
+    """Get latest Int/Pack repo commit hash"""
+
+    int_pack_repo = "https://github.com/opendaylight/integration-packaging.git"
+    # Get the commit hash at the tip of the master branch
+    args_git = ['git', 'ls-remote', int_pack_repo, "HEAD"]
+    args_awk = ['awk', '{print $1}']
+    references = subprocess.Popen(args_git, stdout=subprocess.PIPE,
+                                  shell=False)
+    sysd_commit = subprocess.check_output(args_awk, stdin=references.stdout,
+                                          shell=False).strip()
+
+    return sysd_commit
+
+
 # When run as a script, accept a set of builds and execute them
 if __name__ == "__main__":
     # Load RPM build variables from a YAML config file
@@ -294,7 +309,7 @@ if __name__ == "__main__":
     builds = []
 
     # Check if `changelog_date` has been passed as an arg
-    # The current datetime should be the default date for RPM changelog dates
+    # The current datetime should be the default date for RPM changelog date
     # but can still accept optional `changelog_date` param
     # `changelog_date` is in the format: 'Sat Dec 10 2016'
     # Docs:
@@ -302,6 +317,12 @@ if __name__ == "__main__":
     if not args.changelog_date:
         args.changelog_date = datetime.date.today().strftime("%a %b %d %Y")
 
+    # Check if `sysd_commit` has been passed as an arg
+    # Use latest Int/Pack repo commit hash as sysd_commit var
+    # unless passed by param
+    if not args.sysd_commit:
+        args.sysd_commit = get_sysd_commit()
+
     if args.version:
         # Build a list of requested versions as dicts of version components
         versions = []
@@ -339,7 +360,7 @@ if __name__ == "__main__":
                       "download_url": args.download_url
                       })
 
-        # If download_url is given, get version info
+        # If download_url is given, update version info
         if args.download_url:
             version = extract_version(args.download_url)
             build.update(version)