Added new tasks - `workflow:push-upstream` and `workflow:push-staging`
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 02 Nov 2016 10:39:54 +0000
changeset 68 61d8bee7c4d4
parent 67 75b6eb7b781c
child 69 23cdc822cfc5
child 71 68c8cccbdec5
Added new tasks - `workflow:push-upstream` and `workflow:push-staging` ...to push currently checked out revisios to upstream or staging repositories. * `workflow:push-staging` is meant to be used by developers to push changes to staging repositories in order to build them on CI and check whether all are correct. * `workflow:push-upstream` is to be used on CI server to push changes to an upstream (or canonical) repositories once all test pass on all platforms and configurations.
Rakefile
rakelib/hglib.rb
rakelib/workflow.rake
--- a/Rakefile	Wed Nov 02 00:18:25 2016 +0000
+++ b/Rakefile	Wed Nov 02 10:39:54 2016 +0000
@@ -9,6 +9,7 @@
 import 'rakelib/install.rake'
 import 'rakelib/dist-jv.rake'
 import 'rakelib/clean.rake'
+import 'rakelib/workflow.rake'
 
 desc "Fetch sources and compiles project (default task)"
 task :'default' => [ :'setup', :'checkout', :'compile' ]
--- a/rakelib/hglib.rb	Wed Nov 02 00:18:25 2016 +0000
+++ b/rakelib/hglib.rb	Wed Nov 02 10:39:54 2016 +0000
@@ -77,9 +77,12 @@
     end
     c_opts.reject! { | e | e.size == 0 }
     cmd = ['hg'] + g_opts + [command] + c_opts + args      
-    $LOGGER.debug("executing: #{cmd.shelljoin}")
+    cmd_info = cmd.shelljoin.
+                gsub(/username\\=\S+/, "username\\=***").
+                gsub(/password\\=\S+/, "password\\=***")
+    $LOGGER.debug("executing: #{cmd_info}")
     if defined? RakeFileUtils then
-      puts cmd.shelljoin
+      puts cmd_info
     end
     if block_given? then
       stdout, stderr, status = Open3.capture3(*cmd)
@@ -157,7 +160,7 @@
 
     def initialize(directory)
       @path = directory
-      config_file = hgrc()
+      config_file = hgrc()      
       if File.exist? ( config_file ) 
         $LOGGER.debug("Loading repository config from \"#{config_file}\"")
         @config = HG::config().merge(IniFile.new(:filename => config_file))
@@ -225,18 +228,18 @@
         uri = URI.parse(remote)
         uri.user = nil
         remote = uri.to_s        
-        authconf << "auth.bb.prefix=#{remote}"
+        aauthconf << "auth.bb.prefix = #{self.paths['remote'] || remote}"
         authconf << "auth.bb.username=#{user}"        
         authconf << "auth.bb.password=#{pass}"        
       end
       hg("pull", remote, config: authconf) do | status |
         if not status.success? then
-          raise Exception.new("Failed to pull from #{remote}")
+          raise Exception.new("Failed to pull from #{remote} (exit code #{status.exitstatus})")
         end
       end
     end
 
-    def push(remote = 'default', user: nil, pass: nil)
+    def push(remote = 'default', user: nil, pass: nil, rev: nil)
       authconf = []
       if pass != nil then
         if user == nil then
@@ -244,19 +247,28 @@
         end
         # If user/password is provided, make sure we don't have
         # username in remote URI. Otherwise Mercurial won't use 
-        # password from config!
-        uri = URI.parse(remote)
+        # password from config!        
+        uri = URI.parse(self.paths[remote] || remote)
         uri.user = nil
-        remote = uri.to_s                
-        authconf << "bb.prefix = #{remote}"
-        authconf << "bb.username = #{user}"        
-        authconf << "bb.password = #{pass}"        
+        uri = uri.to_s
+        uri_alias = if self.paths.has_key? remote then remote else 'xxx' end
+        authconf << "auth.#{uri_alias}.prefix=#{uri}"
+        authconf << "auth.#{uri_alias}.username=#{user}"        
+        authconf << "auth.#{uri_alias}.password=#{pass}"        
       end
-      hg("pull", remote, config: authconf) do | status |
-        if status.exitstatus != 0 and status.exitstatus != 1 then
-          raise Exception.new("Failed to pull from #{remote}")
+      if rev == nil then
+        hg("push", remote, config: authconf) do | status |
+          if status.exitstatus != 0 and status.exitstatus != 1 then
+            raise Exception.new("Failed to push to #{remote} (exit code #{status.exitstatus})")
+          end
+        end      
+      else
+        hg("push", remote, config: authconf, rev: rev) do | status |
+          if status.exitstatus != 0 and status.exitstatus != 1 then
+            raise Exception.new("Failed to push rev #{rev} to #{remote} (exit code #{status.exitstatus})")
+          end
         end
-      end      
+      end
     end
 
     # Create a shared clone in given directory, Return a new
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rakelib/workflow.rake	Wed Nov 02 10:39:54 2016 +0000
@@ -0,0 +1,36 @@
+# This file contains various tasks usefull for Smalltalk/X jv-branch 
+# development. Currently it only supports working with Mercurial repositories,
+# Honestly, there's not much one can do with CVS, we're using it only for
+# packages that have not been converted to Mercurial. 
+
+namespace :'workflow' do
+  # A helper function to :push-upstream and push-staging tasks
+  def push(remote, user, pass)
+    opts = {
+      :user => user,
+      :pass => pass,
+      :rev => '.',
+    }
+    project.packages_and_application.each do | pkg |
+      if not pkg.nested_package? then
+        repo = Rake::Stx::Configuration::Repository::find(pkg.repository)
+        if repo.type == :'hg' then
+          hg = HG::Repository.new(BUILD_DIR / pkg.directory)
+          hg.push(remote, **opts)
+        end
+      end
+    end
+  end
+
+  desc "Push currently checked out revisions to upstream repositories (to be called after all tests pass on all configurations)"
+  task :'push-upstream', :user, :pass do | t, args |
+    push('default', args[:user] || nil, args[:pass] || nil)
+  end
+  task :'push-upstream' => :'setup'
+
+  desc "Push currently checked out revisions to staging repositories (to be by developer to test her changes)"
+  task :'push-staging', :user, :pass do | t, args |
+    push('staging', args[:user] || nil, args[:pass] || nil)
+  end
+  task :'push-staging' => :'setup'
+end