class Cloudspin::Stack::Artefact::Release

Attributes

version[R]

Public Class Methods

new(version) click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 12
def initialize(version)
  @version = version
end

Public Instance Methods

already_tagged?() click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 71
def already_tagged?
  return false unless cmd_sh(%w[git tag]).split(/\n/).include?(version_tag)
  puts "Tag #{version_tag} has already been created."
  true
end
base() click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 34
def base
  '.'
end
chdir(dir, &blk) click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 30
def chdir(dir, &blk)
  Dir.chdir dir, &blk
end
cmd_sh(cmd, &block) click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 38
def cmd_sh(cmd, &block)
  out, status = sh_with_status(cmd, &block)
  unless status.success?
    cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin)
    raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out)
  end
  out
end
git_push(remote = "") click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 57
def git_push(remote = "")
  perform_git_push remote
  perform_git_push "#{remote} --tags"
  puts "Pushed git commits and tags."
end
perform_git_push(options = "") click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 63
def perform_git_push(options = "")
  cmd = "git push #{options}"
  out, status = sh_with_status(cmd)
  return if status.success?
  cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin)
  raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n"
end
sh_with_status(cmd, &block) click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 47
def sh_with_status(cmd, &block)
  puts "cd #{base} && #{cmd}"
  chdir(base) do
    outbuf = IO.popen(cmd, :err => [:child, :out], &:read)
    status = $?
    block.call(outbuf) if status.success? && block
    return [outbuf, status]
  end
end
tag_version() { || ... } click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 16
def tag_version
  cmd_sh %W[git tag -m Version\ #{version} #{version_tag}]
  puts "Tagged #{version_tag}."
  yield if block_given?
rescue RuntimeError
  puts "Untagging #{version_tag} due to error."
  sh_with_status %W[git tag -d #{version_tag}]
  raise
end
version_tag() click to toggle source
# File lib/cloudspin/stack/artefact/release.rb, line 26
def version_tag
  "v#{version}"
end