Skip to content

Instantly share code, notes, and snippets.

@drnic
Created January 19, 2009 23:41
Show Gist options
  • Save drnic/49238 to your computer and use it in GitHub Desktop.
Save drnic/49238 to your computer and use it in GitHub Desktop.
module ChocTop::Appcast
def make_build
sh "xcodebuild -configuration Release"
end
def make_dmg
FileUtils.rm_rf pkg
sh "hdiutil create -volname '#{name}' -srcfolder 'build/Release/#{target}' '#{pkg}'"
end
def make_appcast
app_name = File.basename(File.expand_path('.'))
FileUtils.mkdir_p "appcast/build"
appcast = File.open("appcast/build/#{appcast_filename}", 'w')
xml = Builder::XmlMarkup.new(:target => appcast, :indent => 2)
xml.instruct!
xml.rss('xmlns:atom' => "http://www.w3.org/2005/Atom",
'xmlns:sparkle' => "http://www.andymatuschak.org/xml-namespaces/sparkle",
:version => "2.0") do
xml.channel do
xml.title(app_name)
xml.description('#{app_name} updates')
xml.link(base_url)
xml.language('en')
xml.pubDate Time.now.to_s(:rfc822)
# xml.lastBuildDate(Time.now.rfc822)
xml.atom(:link, :href => "#{base_url}/#{appcast_filename}",
:rel => "self", :type => "application/rss+xml")
xml.item do
xml.title("#{name} #{version}")
xml.tag! "sparkle:releaseNotesLink", release_notes_link
xml.pubDate(File.mtime(pkg))
xml.guid("#{name}-#{version}", :isPermaLink => "false")
xml.enclosure(:url => "#{base_url}/#{target}",
:length => "#{File.size(pkg)}",
:type => "application/dmg",
:"sparkle:version" => version)
end
end
end
end
def upload_appcast
_host = host.blank? ? "" : "#{host}:"
sh %{rsync -aCv appcast/build/ #{_host}#{remote_dir}}
end
end
ChocTop.send(:include, ChocTop::Appcast)
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require "fileutils"
require "yaml"
require "rubygems"
require "builder"
require "active_support"
require "osx/cocoa"
class ChocTop
VERSION = '0.9.0'
# The name of the Cocoa application
# Default: info_plist['CFBundleExecutable']
attr_accessor :name
# The version of the Cocoa application
# Default: info_plist['CFBundleVersion']
attr_accessor :version
# The target name of the distributed DMG file
# Default: #{name}.app
attr_accessor :target
# The host name, e.g. some-domain.com
attr_accessor :host
# The url from where the xml + dmg files will be downloaded
# Default: http://#{host}
attr_writer :base_url
def base_url
@base_url ||= "http://#{host}"
end
# The url to display the release notes for the latest release
# Default: base_url
attr_writer :release_notes_link
def release_notes_link
@release_notes_link ||= base_url
end
# The name of the local xml file containing the Sparkle item details
# Default: info_plist['SUFeedURL'] or linker_appcast.xml
attr_accessor :appcast_filename
# The remote directory where the xml + dmg files will be rsync'd
attr_accessor :remote_dir
# The argument flags passed to rsync
# Default: -aCv
attr_accessor :rsync_args
# Generated filename for a distribution, from name, version and .dmg
# e.g. MyApp-1.0.0.dmg
def pkg_name
"#{name}-#{version}.dmg"
end
# Path to generated package file
def pkg
"appcast/build/#{pkg_name}"
end
def info_plist
@info_plist ||= OSX::NSDictionary.dictionaryWithContentsOfFile(File.expand_path('Info.plist'))
end
def initialize
$sparkle = self # define a global variable for this object
# Defaults
@name = info_plist['CFBundleExecutable']
@version = info_plist['CFBundleVersion']
@target = "#{name}.app"
@appcast_filename = info_plist['SUFeedURL'] ? File.basename(info_plist['SUFeedURL']) : 'linker_appcast.xml'
@rsync_args = '-aCv'
yield self if block_given?
define_tasks
end
def define_tasks
namespace :appcast do
desc "Build Xcode Release"
task :build => "build/Release/#{target}/Contents/Info.plist"
task "build/Release/#{target}/Contents/Info.plist" do
make_build
end
desc "Create the dmg file for appcasting"
task :dmg => "appcast/build/#{pkg_name}"
file "appcast/build/#{pkg_name}" => "build/Release/#{target}/Contents/Info.plist" do
make_dmg
end
desc "Create/update the appcast file"
task :feed => "appcast/build/#{appcast_filename}"
file "appcast/build/#{appcast_filename}" => "appcast/build/#{pkg_name}" do
make_appcast
end
desc "Upload the appcast file to the host"
task :upload do
upload_appcast
end
end
desc "Create dmg, update appcast file, and upload to host"
task :appcast => %w[appcast:build appcast:feed appcast:upload]
end
end
require "choctop/appcast"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment