Skip to content

Commit

Permalink
Much improved Xcode 4 archive support.
Browse files Browse the repository at this point in the history
Archives are now stored in the correct location for Xcode 4, and include an Info.plist
just like the ones generated by Xcode itself. Your release notes will also be added
and will appear as a comment in Xcode organiser.
  • Loading branch information
lukeredpath committed Jul 22, 2011
1 parent cc4eacb commit 5c205ee
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion betabuilder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.date = %q{2011-07-22}
s.email = %q{luke@lukeredpath.co.uk}
s.extra_rdoc_files = ["README.md", "LICENSE", "CHANGES.md"]
s.files = ["CHANGES.md", "LICENSE", "README.md", "lib/beta_builder", "lib/beta_builder/archived_build.rb", "lib/beta_builder/deployment_strategies", "lib/beta_builder/deployment_strategies/testflight.rb", "lib/beta_builder/deployment_strategies/web.rb", "lib/beta_builder/deployment_strategies.rb", "lib/beta_builder.rb", "lib/betabuilder.rb"]
s.files = ["CHANGES.md", "LICENSE", "README.md", "lib/beta_builder/archived_build.rb", "lib/beta_builder/deployment_strategies/testflight.rb", "lib/beta_builder/deployment_strategies/web.rb", "lib/beta_builder/deployment_strategies.rb", "lib/beta_builder.rb", "lib/betabuilder.rb"]
s.homepage = %q{http://github.com/lukeredpath/betabuilder}
s.rdoc_options = ["--main", "README.md"]
s.require_paths = ["lib"]
Expand Down
10 changes: 8 additions & 2 deletions lib/beta_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(namespace = :beta, &block)
:configuration => "Adhoc",
:build_dir => "build",
:auto_archive => false,
:archive_path => File.expand_path("~/Library/Application Support/Developer/Shared/Archived Applications"),
:archive_path => File.expand_path("~/Library/Developer/Xcode/Archives"),
:xcodebuild_path => "xcodebuild",
:project_file_path => nil,
:workspace_path => nil,
Expand Down Expand Up @@ -43,6 +43,10 @@ def build_arguments
end
end

def archive_name
app_name || target
end

def app_file_name
if app_name
"#{app_name}.app"
Expand Down Expand Up @@ -149,8 +153,10 @@ def define

desc "Build and archive the app"
task :archive => :build do
puts "Archiving build..."
archive = BetaBuilder.archive(@configuration)
archive.save_to(@configuration.archive_path)
output_path = archive.save_to(@configuration.archive_path)
puts "Archive saved to #{output_path}."
end
end
end
Expand Down
71 changes: 65 additions & 6 deletions lib/beta_builder/archived_build.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'uuid'
require 'fileutils'
require 'CFPropertyList'

module BetaBuilder
def self.archive(configuration)
Expand All @@ -21,6 +22,7 @@ def save_to(path)
FileUtils.mkdir(archive_path)
FileUtils.cp_r(@configuration.built_app_path, archive_path)
FileUtils.cp_r(@configuration.built_app_dsym_path, archive_path)
archive_path
end
end

Expand All @@ -29,13 +31,70 @@ def initialize(configuration)
@configuration = configuration
end

def archive_file_name
"#{@configuration.archive_name} #{Time.now.strftime('%Y-%m-%d %H.%M')}.xcarchive"
end

def archive_path_within(path)
File.join(path, "#{Time.now.strftime('%Y-%m-%d')}", archive_file_name)
end

def applications_path
File.join("Products", "Applications")
end

def dsyms_path
"dSYMs"
end

def plist_info_path
File.join(@configuration.built_app_path, "Info.plist")
end

def save_to(path)
date_path = File.join(path, "#{Time.now.strftime('%Y-%m-%d')}")
FileUtils.mkdir_p(date_path)
archive_path = File.join(date_path, "#{@configuration.target}.xcarchive")
FileUtils.mkdir(archive_path)
FileUtils.cp_r(@configuration.built_app_path, archive_path)
FileUtils.cp_r(@configuration.built_app_dsym_path, archive_path)
archive_path = archive_path_within(path)
FileUtils.mkdir_p(archive_path)

application_path = File.join(archive_path, applications_path)
FileUtils.mkdir_p(application_path)
FileUtils.cp_r(@configuration.built_app_path, application_path)

dsym_path = File.join(archive_path, dsyms_path)
FileUtils.mkdir_p(dsym_path)
FileUtils.cp_r(@configuration.built_app_dsym_path, dsym_path)

write_plist_to(archive_path)
archive_path
end

private

def write_plist_to(path)
plist = {
"ApplicationProperties" => {
"ApplicationPath" => File.join("Applications", "#{@configuration.app_file_name}.app"),
"CFBundleIdentifier" => metadata["CFBundleIdentifier"],
"CFBundleShortVersionString" => metadata["CFBundleShortVersionString"],
"IconPaths" => metadata["CFBundleIconFiles"].map { |file| File.join("Applications", @configuration.app_file_name, file) }
},
"ArchiveVersion" => 1.0,
"Comment" => @configuration.release_notes,
"CreationDate" => Time.now,
"Name" => @configuration.archive_name,
"SchemeName" => @configuration.scheme
}
File.open(File.join(path, "Info.plist"), "w") do |io|
io.write plist.to_plist
end
end

def metadata
@metadata ||= load_property_list(plist_info_path)
end

def load_property_list(path)
plist = CFPropertyList::List.new(:file => path)
CFPropertyList.native_types(plist.value)
end
end
end
4 changes: 2 additions & 2 deletions lib/beta_builder/deployment_strategies/testflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def get_notes_using_editor
begin
filepath = "#{dir}/release_notes"
system("#{editor} #{filepath}")
notes = File.read(filepath)
@configuration.release_notes = File.read(filepath)
ensure
rm_rf(dir)
end
end

def get_notes_using_prompt
puts "Enter the release notes for this build (hit enter twice when done):\n"
gets_until_match(/\n{2}$/).strip
@configuration.release_notes = gets_until_match(/\n{2}$/).strip
end

def gets_until_match(pattern, string = "")
Expand Down

0 comments on commit 5c205ee

Please sign in to comment.