Class: Cloudspin::Stack::Artefact::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudspin/stack/artefact/release.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Release

Returns a new instance of Release.



12
13
14
# File 'lib/cloudspin/stack/artefact/release.rb', line 12

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/cloudspin/stack/artefact/release.rb', line 10

def version
  @version
end

Instance Method Details

#already_tagged?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# 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

#baseObject



34
35
36
# File 'lib/cloudspin/stack/artefact/release.rb', line 34

def base
  '.'
end

#chdir(dir, &blk) ⇒ Object



30
31
32
# File 'lib/cloudspin/stack/artefact/release.rb', line 30

def chdir(dir, &blk)
  Dir.chdir dir, &blk
end

#cmd_sh(cmd, &block) ⇒ Object



38
39
40
41
42
43
44
45
# 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 = "") ⇒ Object



57
58
59
60
61
# 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 = "") ⇒ Object



63
64
65
66
67
68
69
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
# 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_versionObject



16
17
18
19
20
21
22
23
24
# 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_tagObject



26
27
28
# File 'lib/cloudspin/stack/artefact/release.rb', line 26

def version_tag
  "v#{version}"
end