class Docman::Deployers::GitDeployer

Public Instance Methods

push() click to toggle source
# File lib/docman/deployers/git_deployer.rb, line 7
def push
  root = @docroot_config.root
  root.state_name = self['state']
  tag = nil

  if self['environment'].has_key?('tagger')
    filepath = File.join(root['full_build_path'], 'VERSION')
    prev_version = File.file?(filepath) ? File.open(filepath) : nil
    params = self['environment']['tagger']
    params['prev_version'] = prev_version
    version = ''
    docman_tag_var = "DOCMAN_TAG"
    docman_release_var = "RELEASE_VERSION"
    if ENV.has_key? docman_tag_var and ENV[docman_tag_var].length > 0
      puts "Variable #{docman_tag_var} => #{ENV[docman_tag_var]}"
      version = ENV[docman_tag_var]
    elsif ENV.has_key? docman_release_var and ENV[docman_release_var].length > 0
      puts "Variable #{docman_release_var} => #{ENV[docman_release_var]}"
      version = ENV[docman_release_var]
    else
      puts "Variable #{docman_release_var} or #{docman_tag_var} not found."
      version = Docman::Taggers::Tagger.create(params, root, self).perform
    end
    File.open(filepath, 'w') {|f| f.write(version) }

    filepath = File.join(root['full_build_path'], 'version.properties')
    File.open(filepath, 'w') {|f| f.write("tag=#{version}") }

    tag = version
  end

  GitUtil.commit(root['full_build_path'], root['full_build_path'], 'Updated version')
  GitUtil.squash_commits(Docman::Application.instance.commit_count, nil, tag)
  GitUtil.push(root['full_build_path'], root.version(type: 'root'))
end