rakelib/workflow.rake
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 04 Dec 2016 22:21:22 +0000
changeset 88 112075e99cef
parent 86 f2a7a4378c22
child 105 983a637074e6
permissions -rw-r--r--
Support for 'upstream' repositories refactored. Each repository (factory) may define a 'staging' and an 'uptream' repository. A 'canonical' repository is mandatory. When checking out and/or updating, first changes from 'staging' are pulled, then from 'upstream' and at last from 'canonical repository'. Mercurial paths are defined. Repository sets updated accordingly.

# 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 hg_repositories()     
    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)          
          yield hg          
        end
      end
    end    
  end
  
  def push(remote, user, pass, review_only, push_bookmark)  
    hg_repositories do | hg |
      opts = {
        :user => user,
        :pass => pass,
      }                  
      if review_only then
        opts[:rev] = '.'
        remote_url = hg.paths[remote] || remote
        bookmark = hg.bookmark()
        puts ""
        puts "== changes going to #{remote_url} =="
        puts ""
        hg.outgoing(remote, **opts)
        puts ""
        if push_bookmark and bookmark then
          puts "Will update bookmark '#{bookmark}"
        end
        puts "===================================="
        puts ""
      else
        if push_bookmark && bookmark then
          opts[:bookmarks] = ['.']
        else
          opts[:rev] = '.'
        end        
        hg.push(remote, **opts)
      end
    end
  end

  desc "Display changes to be pushed to upstream repositores (use it to review what workflow:push-upstream would do)"
  task :'out-upstream', :user, :pass do | t, args |
    push('upstream', args[:user], args[:pass], true, false)
  end
  task :'out-upstream' => :'setup'

  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('upstream', args[:user], args[:pass], false, false)
  end
  task :'push-upstream' => :'setup'


  desc "Display changes to be pushed to staging repositores (use it to review what workflow:push-staging would do)"
  task :'out-staging', :user, :pass do | t, args |
    push('staging', args[:user], args[:pass], true, true)
  end
  task :'out-staging' => :'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], args[:pass], false, true)
  end
  task :'push-staging' => :'setup'

  desc "(Auto)merge changes (from eXept)"
  task :'merge' => :'setup' do
    if not which("hg-automerge.rb") then
      info "Cannot find 'hg-automerge.rb' in PATH"
      info "You may find it at https://bitbucket.org/janvrany/jv-scripts"
      error "Cannot find 'hg-automerge.rb' in PATH"
    end    
    hg_repositories_failed_to_merge = []
    hg_repositories do | hg |
      if File.exist? (hg.path / '.hgautomerge') then
        info "Merging #{hg.path}"
        sh "hg-automerge.rb --cwd #{hg.path}"
      else 
        info "Not merging #{hg.path} - no merge config found."
        info "To configure run: 'hg-automerge.rb --cwd #{hg.path} --config'"
      end
    end
  end

end