Class: TripAdvisor::AbstractBuild
- Inherits:
-
Object
- Object
- TripAdvisor::AbstractBuild
- Defined in:
- lib/trip_advisor/build.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pod_repo ⇒ Object
Returns the value of attribute pod_repo.
-
#remotes ⇒ Object
Returns the value of attribute remotes.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#reporter ⇒ Object
Returns the value of attribute reporter.
-
#version_prefix ⇒ Object
Returns the value of attribute version_prefix.
Instance Method Summary collapse
- #author ⇒ Object
- #build! ⇒ Object
- #commit!(files) ⇒ Object
-
#initialize(path) ⇒ AbstractBuild
constructor
A new instance of AbstractBuild.
- #pod_update! ⇒ Object
- #podspec_file ⇒ Object
- #push! ⇒ Object
- #push_podspec! ⇒ Object
- #release_version ⇒ Object
- #run(command) ⇒ Object
- #tag!(target) ⇒ Object
- #update_build_assets ⇒ Object
- #update_staging_area(files) ⇒ Object
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
#info ⇒ Object (readonly)
Returns the value of attribute info.
47 48 49 |
# File 'lib/trip_advisor/build.rb', line 47 def info @info end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
47 48 49 |
# File 'lib/trip_advisor/build.rb', line 47 def path @path end |
#pod_repo ⇒ Object
Returns the value of attribute pod_repo.
48 49 50 |
# File 'lib/trip_advisor/build.rb', line 48 def pod_repo @pod_repo end |
#remotes ⇒ Object
Returns the value of attribute remotes.
48 49 50 |
# File 'lib/trip_advisor/build.rb', line 48 def remotes @remotes end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
47 48 49 |
# File 'lib/trip_advisor/build.rb', line 47 def repo @repo end |
#reporter ⇒ Object
Returns the value of attribute reporter.
48 49 50 |
# File 'lib/trip_advisor/build.rb', line 48 def reporter @reporter end |
#version_prefix ⇒ Object
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
#author ⇒ Object
89 90 91 |
# File 'lib/trip_advisor/build.rb', line 89 def @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 } = {} [:tree] = index.write_tree(repo) [:author] = [:committer] = [:message] = "Creating build #{version}" [:parents] = [ repo.head.target ] [:update_ref] = 'HEAD' Rugged::Commit.create(repo, ) 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_file ⇒ Object
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_version ⇒ Object
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 => ) end |
#update_build_assets ⇒ Object
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 |