2013-10-22 01:29:13 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'tempfile'
|
|
|
|
require 'open-uri'
|
2017-10-02 01:37:11 +00:00
|
|
|
require 'shellwords'
|
2017-12-17 07:57:19 +00:00
|
|
|
require 'nokogiri'
|
|
|
|
require 'time'
|
2022-08-01 04:50:05 +00:00
|
|
|
require 'uri'
|
2013-10-22 01:29:13 +00:00
|
|
|
|
|
|
|
feed = ARGV[0] || 'mercury'
|
|
|
|
|
2014-04-08 00:41:03 +00:00
|
|
|
site_dir = "#{Dir.home}/Source/Repos/kode54-net/cog"
|
|
|
|
|
2017-09-26 02:01:08 +00:00
|
|
|
appcast = open("#{site_dir}/#{feed}_builds/#{feed}.xml")
|
2013-10-22 01:29:13 +00:00
|
|
|
|
2017-12-17 07:57:19 +00:00
|
|
|
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
|
2013-10-22 01:29:13 +00:00
|
|
|
|
|
|
|
#Get the latest revision from the appcast
|
2017-12-17 07:57:19 +00:00
|
|
|
appcast_enclosure = sortedchannels[0].search('./enclosure').first
|
2022-06-22 08:17:02 +00:00
|
|
|
appcast_url = appcast_enclosure.attribute('url').to_s;
|
|
|
|
|
|
|
|
appcast_filename = appcast_url.split( '/' )[-1]
|
|
|
|
appcast_filename_split = appcast_filename.split( '.' )
|
|
|
|
appcast_filename_base = appcast_filename_split[0]
|
|
|
|
appcast_filename_split = appcast_filename_base.split( '-' )
|
|
|
|
|
|
|
|
appcast_revision_code = appcast_filename_split[1]
|
2013-10-22 01:29:13 +00:00
|
|
|
|
|
|
|
#Remove modified files that may cause conflicts.
|
|
|
|
#%x[hg revert --all]
|
|
|
|
|
|
|
|
#Update to the latest revision
|
|
|
|
#%x[hg pull -u]
|
2013-10-22 17:02:28 +00:00
|
|
|
|
|
|
|
# %[xcodebuild -workspace Cog.xcodeproj/project.xcworkspace -scheme Cog archive 2>&1].each_line do |line|
|
|
|
|
# if line.match(/\*\* BUILD FAILD \*\*/)
|
|
|
|
# exit
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2017-04-04 00:52:17 +00:00
|
|
|
# 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__))
|
2019-10-15 22:03:03 +00:00
|
|
|
app_path = "#{Dir.home}/Desktop/Cog"
|
2013-10-22 17:02:28 +00:00
|
|
|
|
|
|
|
plist = open("#{app_path}/Cog.app/Contents/Info.plist")
|
2017-12-17 07:57:19 +00:00
|
|
|
plistdoc = Nokogiri::XML(plist)
|
|
|
|
plist.close
|
|
|
|
|
|
|
|
version_element = plistdoc.xpath('//key[.="CFBundleVersion"]/following-sibling::string[1]')
|
2013-10-22 17:02:28 +00:00
|
|
|
|
2017-12-17 07:57:19 +00:00
|
|
|
latest_revision = version_element.inner_text
|
2013-10-22 01:29:13 +00:00
|
|
|
|
2022-06-22 08:17:02 +00:00
|
|
|
if latest_revision.split( /-/ ).count < 2
|
|
|
|
version_element = plistdoc.xpath('//key[.="GitVersion"]/following-sibling::string[1]')
|
|
|
|
latest_revision = version_element.inner_text
|
|
|
|
end
|
|
|
|
|
2013-10-22 17:12:55 +00:00
|
|
|
#latest_revision = %x[/usr/local/bin/hg log -r . --template '{latesttag}-{latesttagdistance}-{node|short}']
|
|
|
|
revision_split = latest_revision.split( /-/ )
|
2020-03-02 01:59:23 +00:00
|
|
|
revision_number = revision_split[0]
|
|
|
|
revision_code = revision_split[1]
|
2015-08-01 08:04:48 +00:00
|
|
|
revision_split = revision_code.split( /g/ )
|
|
|
|
revision_code = revision_split[1]
|
2013-10-22 17:12:55 +00:00
|
|
|
|
2020-03-02 01:59:23 +00:00
|
|
|
if 1 #appcast_revision < latest_revision
|
2013-10-22 01:29:13 +00:00
|
|
|
#Get the changelog
|
2021-02-18 23:11:58 +00:00
|
|
|
changelog = %x[/usr/bin/git log #{appcast_revision_code}..#{revision_code} --pretty=format:'<li> <a href="https://github.com/losnoco/Cog/commit/%H">view commit</a> • %s</li> ' --reverse]
|
2015-08-01 08:04:48 +00:00
|
|
|
|
|
|
|
description = changelog
|
2013-10-22 11:18:58 +00:00
|
|
|
|
2014-03-13 02:19:55 +00:00
|
|
|
filename = "Cog-#{revision_code}.zip"
|
2017-09-26 02:01:08 +00:00
|
|
|
filenamedesc = "Cog-#{revision_code}.html"
|
2020-03-02 01:59:23 +00:00
|
|
|
deltamask = "Cog#{revision_number}-"
|
2014-03-25 03:24:52 +00:00
|
|
|
temp_path = "/tmp";
|
2017-09-26 02:01:08 +00:00
|
|
|
%x[rm -rf '#{temp_path}/Cog.app' '#{temp_path}/Cog.zip']
|
2014-03-25 03:24:52 +00:00
|
|
|
|
|
|
|
#Copy the replacement build
|
|
|
|
%x[cp -R '#{app_path}/Cog.app' '#{temp_path}/Cog.app']
|
2013-10-22 01:29:13 +00:00
|
|
|
|
|
|
|
#Zip the app!
|
2014-03-25 03:24:52 +00:00
|
|
|
%x[rm -f '#{temp_path}/#{feed}.zip']
|
2014-03-26 04:00:12 +00:00
|
|
|
%x[ditto -c -k --sequesterRsrc --keepParent --zlibCompressionLevel 9 '#{temp_path}/Cog.app' '#{temp_path}/#{feed}.zip']
|
2014-03-25 03:24:52 +00:00
|
|
|
|
2017-09-26 02:01:08 +00:00
|
|
|
#Send the new build to the storage path
|
|
|
|
%x[cp '#{temp_path}/#{feed}.zip' '#{site_dir}/#{feed}_builds/#{filename}']
|
|
|
|
%x[rm '#{temp_path}/#{feed}.zip']
|
2014-03-25 03:24:52 +00:00
|
|
|
|
2017-09-26 02:01:08 +00:00
|
|
|
#Generate the description document
|
|
|
|
descriptiondoc = Tempfile.new('#{feed}.html')
|
|
|
|
descriptiondoc.write(description)
|
|
|
|
descriptiondoc.close()
|
2013-10-22 01:29:13 +00:00
|
|
|
|
2017-09-26 02:01:08 +00:00
|
|
|
#Send it to the storage path
|
|
|
|
%x[cp '#{descriptiondoc.path}' '#{site_dir}/#{feed}_builds/#{filenamedesc}']
|
|
|
|
%x[rm '#{descriptiondoc.path}']
|
|
|
|
|
|
|
|
#Update appcast
|
2021-09-27 21:33:06 +00:00
|
|
|
%x[generate_appcast '#{site_dir}/#{feed}_builds']
|
2013-10-22 01:29:13 +00:00
|
|
|
|
2017-10-02 01:37:11 +00:00
|
|
|
#List out the deltas
|
2022-11-07 07:58:59 +00:00
|
|
|
deltas = Dir.entries("#{site_dir}/#{feed}_builds").select { |f| f =~ /\A#{Regexp.escape(deltamask)}.+\.delta\z/ }
|
2017-10-02 01:37:11 +00:00
|
|
|
|
2023-06-01 07:14:48 +00:00
|
|
|
#Upload them to R2
|
|
|
|
%x[rclone copy '#{site_dir}/#{feed}_builds/#{filename}' r2:cog/ --progress]
|
2022-11-07 07:58:59 +00:00
|
|
|
deltas.each do |f|
|
2023-06-01 07:14:48 +00:00
|
|
|
%x[rclone copy '#{site_dir}/#{feed}_builds/#{f}' r2:cog/ --progress]
|
2022-11-07 07:58:59 +00:00
|
|
|
end
|
2019-06-21 06:34:52 +00:00
|
|
|
|
|
|
|
#Upload the changelog that Sparkle will display
|
2023-06-01 07:14:48 +00:00
|
|
|
%x[rclone copy '#{site_dir}/#{feed}_builds/#{filenamedesc}' r2:cog/ --progress]
|
2016-07-16 05:06:37 +00:00
|
|
|
|
2014-03-25 03:24:52 +00:00
|
|
|
#Clean up
|
2017-09-26 02:01:08 +00:00
|
|
|
%x[rm -rf '#{temp_path}/Cog.app']
|
2016-07-16 05:06:37 +00:00
|
|
|
|
2022-08-04 04:18:09 +00:00
|
|
|
#Convert to JSON
|
|
|
|
%x[pushd '#{site_dir}/#{feed}_builds' && '#{__dir__}/sparkleToJSON' '#{site_dir}/#{feed}_builds/#{feed}.xml' && popd]
|
|
|
|
|
2023-06-01 07:14:48 +00:00
|
|
|
#Upload to R2
|
|
|
|
%x[rclone copy '#{site_dir}/#{feed}_builds/#{feed}.xml' r2:cog/ --progress]
|
|
|
|
%x[rclone copy '#{site_dir}/#{feed}_builds/#{feed}.json' r2:cog/ --progress]
|
2022-12-06 07:16:50 +00:00
|
|
|
|
2021-08-23 02:25:24 +00:00
|
|
|
#Send web hook to update site
|
2022-08-01 06:38:07 +00:00
|
|
|
update_uri = %x[security find-generic-password -w -a #{ENV['LOGNAME']} -s cogupdateurl].chop
|
2022-08-01 04:50:05 +00:00
|
|
|
update_parameter = URI.escape(latest_revision)
|
2022-08-01 06:38:07 +00:00
|
|
|
%x[curl -X POST '#{update_uri}?trigger_title=#{update_parameter}']
|
2013-10-22 01:29:13 +00:00
|
|
|
end
|