Class: Cloudspin::Stack::Artefact::Release
- Inherits:
-
Object
- Object
- Cloudspin::Stack::Artefact::Release
- Defined in:
- lib/cloudspin/stack/artefact/release.rb
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #already_tagged? ⇒ Boolean
- #base ⇒ Object
- #chdir(dir, &blk) ⇒ Object
- #cmd_sh(cmd, &block) ⇒ Object
- #git_push(remote = "") ⇒ Object
-
#initialize(version) ⇒ Release
constructor
A new instance of Release.
- #perform_git_push(options = "") ⇒ Object
- #sh_with_status(cmd, &block) ⇒ Object
- #tag_version ⇒ Object
- #version_tag ⇒ Object
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
#version ⇒ Object (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
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 |
#base ⇒ Object
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( = "") 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_version ⇒ Object
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_tag ⇒ Object
26 27 28 |
# File 'lib/cloudspin/stack/artefact/release.rb', line 26 def version_tag "v#{version}" end |