#!/usr/bin/env ruby require 'tempfile' require 'open-uri' require 'shellwords' require 'nokogiri' require 'time' feed = ARGV[0] || 'mercury' site_dir = "#{Dir.home}/Source/Repos/kode54-net/cog" appcast = open("#{site_dir}/#{feed}_builds/#{feed}.xml") appcastdoc = Nokogiri::XML(appcast) appcast.close sparkle = appcastdoc.namespaces['xmlns:sparkle'] channel = appcastdoc.xpath('//channel') sortedchannels = channel.search('./item').sort_by{ |i| Time.parse(i.at('pubDate').text) }.reverse #Get the latest revision from the appcast appcast_enclosure = sortedchannels[0].search('./enclosure').first appcast_revision = sortedchannels[0].xpath('.//sparkle:version').text appcast_url = appcast_enclosure.attribute('url'); if !appcast_revision appcast_revision = appcast_enclosure.attribute_with_ns('version', sparkle).to_s end appcast_revision_split = appcast_revision.split( /-/ ) appcast_revision_code = appcast_revision_split[1] appcast_revision_split = appcast_revision_code.split( /g/ ) appcast_revision_code = appcast_revision_split[1] #Remove modified files that may cause conflicts. #%x[hg revert --all] #Update to the latest revision #%x[hg pull -u] # %[xcodebuild -workspace Cog.xcodeproj/project.xcworkspace -scheme Cog archive 2>&1].each_line do |line| # if line.match(/\*\* BUILD FAILD \*\*/) # exit # end # end # archivedir = "~/Library/Developer/Xcode/Archives" # latest_archive = %x[find #{archivedir} -type d -name 'Cog *.xcarchive' -print0 | xargs -0 stat -f "%m %N" -t "%Y" | sort -r | head -n1 | sed -E 's/^[0-9]+ //'].rstrip # app_path = "#{latest_archive}/Products#{ENV['HOME']}/Applications" script_path = File.expand_path(File.dirname(__FILE__)) app_path = "#{Dir.home}/Desktop/Cog" plist = open("#{app_path}/Cog.app/Contents/Info.plist") plistdoc = Nokogiri::XML(plist) plist.close version_element = plistdoc.xpath('//key[.="CFBundleVersion"]/following-sibling::string[1]') latest_revision = version_element.inner_text #latest_revision = %x[/usr/local/bin/hg log -r . --template '{latesttag}-{latesttagdistance}-{node|short}'] revision_split = latest_revision.split( /-/ ) revision_number = revision_split[0] revision_code = revision_split[1] revision_split = revision_code.split( /g/ ) revision_code = revision_split[1] if 1 #appcast_revision < latest_revision #Get the changelog changelog = %x[/usr/bin/git log #{appcast_revision_code}..#{revision_code} --pretty=format:'