Sha256: 8c78834e5b352d626cc7760698f620b7967d940a20f18c26dcbc1097c887cfe5

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

namespace :deploy do
  desc "Return SHA-1 commit ID of deployed branch"
  task :show_revision do
    puts capture("cat #{deploy_to}/current/REVISION")
  end

  desc "Determine commit to use (may default to HEAD)."
  task :get_revision do
    def stage
      variables[:stage] && variables[:stage].to_s
    end

    def changed_in_git(filename)
      `git diff --name-only`.grep(/^#{filename}$/).length > 0 ? true : false
    end

    def commit_of_rev(branch)
      x=`git rev-parse --revs-only #{branch}`.chomp
      return nil if x.empty?
      return x
    end

    def commit_in_remote_branch?(commit,branch)
      return false if commit.nil?
      if  %x{git branch -r --contains #{commit}}.grep(/^\s*origin\/#{branch}/).empty?
          puts ""
          puts "no rev matches #{commit} in the remote #{branch} branch(es)"
          return false
      end
      true
    end

    def valid_commit?(commit)
      return false if commit.nil?
      if branch_stages.include? stage.to_s
        return false unless commit_in_remote_branch?(commit,fetch(:deploy_branch, stage.to_s))
      end
      return true
    end

    # returns the actual branch name, if it exists.  nil if it does not
    def remote_branch_name(branch)
      return nil if branch.nil?
      rem_branch = `git branch -r`.grep(/^\s*origin\/(v|)#{branch}$/)[0]
      return nil if rem_branch.nil?
      return rem_branch.sub(/^\s*origin\//, '').chomp
    end

    set :revision, begin
      deploy_version = ENV[ 'DEPLOY_VERSION' ]
      deploy_version ||= 'HEAD' unless branch_stages.include?(stage.to_s)
      
      commit = commit_of_rev(deploy_version)
      until valid_commit?(commit) do
        deploy_version=Capistrano::CLI.ui.ask( 'Enter release number to deploy: ' )
        commit = commit_of_rev(deploy_version)
      end
      commit
    end

    set :branch do
      revision
    end

    set :release_commit do
      branch
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
projectdx_pipeline-1.3.6 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.3.5 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.3.4 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.3.0 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.2.2 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.2.1 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.2.0 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.1.0 lib/projectdx_pipeline/capistrano/git_revision.rb
projectdx_pipeline-1.0.0 lib/projectdx_pipeline/capistrano/git_revision.rb