Class: TripAdvisor::AbstractBuild

Inherits:
Object
  • Object
show all
Defined in:
lib/trip_advisor/build.rb

Direct Known Subclasses

AdHocBuild, ReleaseBuild

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AbstractBuild

Returns a new instance of AbstractBuild.



50
51
52
53
54
55
56
57
# File 'lib/trip_advisor/build.rb', line 50

def initialize(path)
  @path = path
  @repo = Rugged::Repository.new(path)
  @info = BuildInfo.new(repo)
  @pod_repo = 'tripadvisor-mobile-ta-specs'
  @reporter = ConsoleReporter.new
  @version_prefix = 'v'
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



47
48
49
# File 'lib/trip_advisor/build.rb', line 47

def info
  @info
end

#pathObject (readonly)

Returns the value of attribute path.



47
48
49
# File 'lib/trip_advisor/build.rb', line 47

def path
  @path
end

#pod_repoObject

Returns the value of attribute pod_repo.



48
49
50
# File 'lib/trip_advisor/build.rb', line 48

def pod_repo
  @pod_repo
end

#remotesObject

Returns the value of attribute remotes.



48
49
50
# File 'lib/trip_advisor/build.rb', line 48

def remotes
  @remotes
end

#repoObject (readonly)

Returns the value of attribute repo.



47
48
49
# File 'lib/trip_advisor/build.rb', line 47

def repo
  @repo
end

#reporterObject

Returns the value of attribute reporter.



48
49
50
# File 'lib/trip_advisor/build.rb', line 48

def reporter
  @reporter
end

#version_prefixObject

Returns the value of attribute version_prefix.



48
49
50
# File 'lib/trip_advisor/build.rb', line 48

def version_prefix
  @version_prefix
end

Instance Method Details

#authorObject



89
90
91
# File 'lib/trip_advisor/build.rb', line 89

def author
  @author ||= { name: repo.config['user.name'], email: repo.config['user.email'], time: Time.now }
end

#build!Object



59
60
61
# File 'lib/trip_advisor/build.rb', line 59

def build!
  raise "Cannot build a TripAdvisor::AbstractBuild: Only concrete subclasses are buildable."
end

#commit!(files) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/trip_advisor/build.rb', line 106

def commit!(files)
  say "Committing to #{path}"
  index = repo.index
  files.each { |f| index.add f }

  options = {}
  options[:tree] = index.write_tree(repo)

  options[:author] = author
  options[:committer] = author
  options[:message] = "Creating build #{version}"
  options[:parents] = [ repo.head.target ]
  options[:update_ref] = 'HEAD'

  Rugged::Commit.create(repo, options)
end

#pod_update!Object



81
82
83
# File 'lib/trip_advisor/build.rb', line 81

def pod_update!
  run("bundle exec pod update")
end

#podspec_fileObject



63
64
65
# File 'lib/trip_advisor/build.rb', line 63

def podspec_file
  @podspec_file ||= Dir.entries(path).detect { |f| f =~ /.podspec$/ }
end

#push!Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/trip_advisor/build.rb', line 131

def push!
  branch = info.branch
  remotes.each do |remote_name|
    say "Pushing to remote '#{remote_name}'"
    # NOTE: Rugged apparently cannot push to the repositories we need
    # remote = Rugged::Remote.lookup(@repo, remote_name)
    # remote.push ["refs/heads/#{info.branch}", "refs/tags/#{tag_name}"]
    run("git push #{remote_name} #{branch}:#{branch} --tags")
  end
end

#push_podspec!Object



142
143
144
# File 'lib/trip_advisor/build.rb', line 142

def push_podspec!
  run("bundle exec pod repo push --use-libraries --allow-warnings #{pod_repo} #{podspec_file}")
end

#release_versionObject



85
86
87
# File 'lib/trip_advisor/build.rb', line 85

def release_version
  File.read(File.join(path, 'VERSION')).chomp
end

#run(command) ⇒ Object



75
76
77
78
79
# File 'lib/trip_advisor/build.rb', line 75

def run(command)
  unless system(command)
    raise "Build failed: Non-zero exit status returned while executing `#{command}`"
  end
end

#tag!(target) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/trip_advisor/build.rb', line 123

def tag!(target)
  Rugged::Tag.create(repo,
    :name    => tag_name,
    :message => "Tagging build #{version}",
    :target  => target,
    :tagger => author)
end

#update_build_assetsObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/trip_advisor/build.rb', line 93

def update_build_assets
  info.version = version
  File.open('BUILD.json', 'w') { |f| f << Oj.dump(info.to_hash) }
  podspec_content = File.read(podspec_file)
  unless podspec_content.gsub!(/(\.version\s+=\s+)['"](.+)['"]$/, "\\1'#{version}'")
    raise "Unable to update version of Podspec: version attribute not matched."
  end
  unless podspec_content.gsub!(/(\:tag\s+=>\s+)['"](.+)['"]/, "\\1'#{tag_name}'")
    raise "Unable to update version of Podspec: version attribute not matched."
  end
  File.open(podspec_file, 'w') { |f| f << podspec_content }
end

#update_staging_area(files) ⇒ Object



146
147
148
# File 'lib/trip_advisor/build.rb', line 146

def update_staging_area(files)
  run("git add #{files.join(' ')}")
end