Class: XcodeBuilder::ReleaseStrategies::Git

Inherits:
ReleaseStrategy show all
Defined in:
lib/xcode_builder/release_strategies/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ReleaseStrategy

#configure, #initialize

Constructor Details

This class inherits a constructor from XcodeBuilder::ReleaseStrategies::ReleaseStrategy

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



4
5
6
# File 'lib/xcode_builder/release_strategies/git.rb', line 4

def branch
  @branch
end

#originObject

Returns the value of attribute origin.



4
5
6
# File 'lib/xcode_builder/release_strategies/git.rb', line 4

def origin
  @origin
end

#tag_nameObject

Returns the value of attribute tag_name.



4
5
6
# File 'lib/xcode_builder/release_strategies/git.rb', line 4

def tag_name
  @tag_name
end

Instance Method Details

#commit_and_push_with_message(message) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/xcode_builder/release_strategies/git.rb', line 92

def commit_and_push_with_message message
   # then commit it
  cmd = []
  cmd << "git"
  cmd << "commit"
  cmd << "-m"
  cmd << "'#{message}'"
  cmd << "2>&1 %s git.output" % (@configuration.verbose ? '| tee' : '>')
  system(cmd.join " ")
  puts
  puts "Done"

  # now, push the updated plist
  print "Pushing update to #{@origin}/#{@branch}"
  cmd = []
  cmd << "git"
  cmd << "push"
  cmd << @origin
  cmd << @branch
  cmd << "2>&1 %s git.output" % (@configuration.verbose ? '| tee' : '>')
  
  result = system(cmd.join " ")
  raise "Could not push #{@branch} to #{@origin}" unless result
  puts 
end

#prepareObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/xcode_builder/release_strategies/git.rb', line 6

def prepare
  
  if @origin == nil then
      @origin = "origin"
  end

  if @branch == nil then
      @branch = `git rev-parse --abbrev-ref HEAD`.gsub("\n", "")
  end

  if @tag_name == nil then
      @tag_name = "v#{@configuration.build_number}"
  end
end

#prepare_for_next_pod_releaseObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xcode_builder/release_strategies/git.rb', line 62

def prepare_for_next_pod_release
  build_number = @configuration.build_number
  next_build_number = @configuration.next_build_number

  raise "build number cannot be empty on release" unless  (build_number != nil) && (!build_number.empty?) 

  # increment the build number
  @configuration.increment_pod_number

  # commit
  print "Committing #{@configuration.podspec_file} with version #{build_number}"
  stage_files [@configuration.podspec_file]
  commit_and_push_with_message "Preparing for next pod release #{next_build_number}..."
 
  puts "Done"
end

#stage_files(files) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/xcode_builder/release_strategies/git.rb', line 81

def stage_files files
  cmd = []
  
  cmd << "git"
  cmd << "add"
  files.each do |value|
      cmd <<  value
  end
  system(cmd.join " ")
end

#tag_current_versionObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/xcode_builder/release_strategies/git.rb', line 21

def tag_current_version
  puts "Relasing with Git"
  print "Tagging version #{@tag_name}"
  cmd = []

  #first, tag
  cmd << "git"
  cmd << "tag"
  cmd << @tag_name

  cmd << "2>&1 %s git.output" % (@configuration.verbose ? '| tee' : '>')
  result = system(cmd.join " ")
  raise "Could not tag repository" unless result
  puts
  puts "Done"

  puts
  puts "Pulling from remote repo before pushing..."
  result = system("git pull #{@origin} #{@branch}")
  raise "Couldn't merge from #{@origin} #{@branch} - did somebody push a conflicting commit while I was building?" unless result
  puts
  puts "Done"

  # then push tags to the remote server
  print "Pushing tag to #{@origin} on branch #{@branch}"
  cmd = []

  cmd << "git"
  cmd << "push"
  cmd << "--tags"
  cmd << @origin
  cmd << @branch
  cmd << "2>&1 %s git.output" % (@configuration.verbose ? '| tee' : '>')
  system(cmd.join " ")
  raise "Could not push to #{@origin}" unless result
  
  puts
  puts "Done"

end