Update feed update method.

CQTexperiment
Christopher Snowhill 2017-09-25 19:01:08 -07:00
parent 4fd36e1831
commit 78b69b010d
1 changed files with 25 additions and 73 deletions

View File

@ -11,7 +11,7 @@ signature_file = "#{Dir.home}/.ssh/dsa_priv.pem"
site_dir = "#{Dir.home}/Source/Repos/kode54-net/cog"
appcast = open("#{site_dir}/#{feed}.xml")
appcast = open("#{site_dir}/#{feed}_builds/#{feed}.xml")
appcastdoc = Document.new(appcast)
@ -20,10 +20,13 @@ appcast_enclosure = REXML::XPath.match(appcastdoc, "//channel/item/enclosure")[0
appcast_url = appcast_enclosure.attributes['url'];
appcast_revision = appcast_enclosure.attributes['sparkle:version'];
appcast_revision_split = appcast_revision.split( /-/ )
appcast_revision_number = appcast_revision_split[1]
appcast_revision_code = appcast_revision_split[2]
appcast_revision_split = appcast_revision_code.split( /g/ )
appcast_revision_code = appcast_revision_split[1]
appcast.close()
#Remove modified files that may cause conflicts.
#%x[hg revert --all]
@ -56,22 +59,15 @@ revision_code = revision_split[1]
if appcast_revision < latest_revision
#Get the changelog
changelog = %x[/usr/bin/git shortlog #{appcast_revision_code}..#{revision_code}]
changelog = %x[/usr/bin/git log #{appcast_revision_code}..#{revision_code} --pretty=format:'<li> <a href="https://gitlab.kode54.net/kode54/Cog/commit/%H">view commit</a> &bull; %s</li> ' --reverse]
description = changelog
filename = "Cog-#{revision_code}.zip"
filename_delta = "Cog-#{revision_code}.delta"
filenamedesc = "Cog-#{revision_code}.html"
deltamask = "Cogk54-#{appcast_revision_number}-"
temp_path = "/tmp";
%x[rm -rf '#{temp_path}/Cog.app' '#{temp_path}/Cog.old' '#{temp_path}/Cog.zip']
#Retrieve the current full package
local_file = appcast_url.gsub(/https:\/\/f\.losno\.co\/cog/, "#{site_dir}/#{feed}_builds")
%x[cp '#{local_file}' '#{temp_path}/Cog.zip']
#Unpack and rename
%x[ditto -kx '#{temp_path}/Cog.zip' '#{temp_path}/']
%x[mv '#{temp_path}/Cog.app' '#{temp_path}/Cog.old']
%x[rm -rf '#{temp_path}/Cog.app' '#{temp_path}/Cog.zip']
#Copy the replacement build
%x[cp -R '#{app_path}/Cog.app' '#{temp_path}/Cog.app']
@ -83,74 +79,30 @@ if appcast_revision < latest_revision
%x[rm -f '#{temp_path}/#{feed}.zip']
%x[ditto -c -k --sequesterRsrc --keepParent --zlibCompressionLevel 9 '#{temp_path}/Cog.app' '#{temp_path}/#{feed}.zip']
#Generate delta patch
%x[BinaryDelta create '#{temp_path}/Cog.old' '#{temp_path}/Cog.app' '#{temp_path}/#{feed}.delta']
filesize = File.size("#{temp_path}/#{feed}.zip")
filesize_delta = File.size("#{temp_path}/#{feed}.delta")
openssl = "/usr/bin/openssl"
signature_delta = `#{openssl} dgst -sha1 -binary < "#{temp_path}/#{feed}.delta" | #{openssl} dgst -dss1 -sign "#{signature_file}" | #{openssl} enc -base64`
#Send the new build to the server
#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']
#Send the delta
%x[cp '#{temp_path}/#{feed}.delta' '#{site_dir}/#{feed}_builds/#{filename_delta}']
%x[rm '#{temp_path}/#{feed}.delta']
#Generate the description document
descriptiondoc = Tempfile.new('#{feed}.html')
descriptiondoc.write(description)
descriptiondoc.close()
#Send it to the storage path
%x[cp '#{descriptiondoc.path}' '#{site_dir}/#{feed}_builds/#{filenamedesc}']
%x[rm '#{descriptiondoc.path}']
#Update appcast
%x[generate_appcast '#{signature_file}' '#{site_dir}/#{feed}_builds']
#Upload them to S3
%x[s3cmd put -P -m application/octet-stream '#{site_dir}/#{feed}_builds/#{filename_delta}' '#{site_dir}/#{feed}_builds/#{filename}' s3://balde.losno.co/cog/ --signature-v2]
%x[s3cmd put -P -m application/octet-stream '#{site_dir}/#{feed}_builds/#{deltamask}*.delta' '#{site_dir}/#{feed}_builds/#{filename}' s3://balde.losno.co/cog/ --signature-v2]
#Clean up
%x[rm -rf '#{temp_path}/Cog.old' '#{temp_path}/Cog.app']
#Add new entry to appcast
new_item = Element.new('item')
new_item.add_element('title')
new_item.elements['title'].text = "Version 0.08 (#{latest_revision})"
new_item.add_element('description')
new_item.elements['description'].text = description
new_item.add_element('pubDate')
new_item.elements['pubDate'].text = %x[date -r `stat -f "%m" '#{app_path}'` +'%a, %d %b %Y %T %Z'].rstrip #RFC 822
new_item.add_element('sparkle:minimumSystemVersion')
new_item.elements['sparkle:minimumSystemVersion'].text = '10.7.0'
new_item.add_element('enclosure')
new_item.elements['enclosure'].add_attribute('url', "https://f.losno.co/cog/#{filename}")
new_item.elements['enclosure'].add_attribute('length', filesize)
new_item.elements['enclosure'].add_attribute('type', 'application/octet-stream')
new_item.elements['enclosure'].add_attribute('sparkle:version', "#{latest_revision}")
new_item.add_element('sparkle:deltas')
new_item.elements['sparkle:deltas'].add_element('enclosure')
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('url', "https://f.losno.co/cog/#{filename_delta}")
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('length', filesize_delta)
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('type', 'application/octet-stream')
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('sparkle:version', "#{latest_revision}")
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('sparkle:deltaFrom', "#{appcast_revision}")
new_item.elements['sparkle:deltas'].elements['enclosure'].add_attribute('sparkle:dsaSignature', "#{signature_delta}")
appcastdoc.insert_before('//channel/item', new_item)
#Limit number of entries to 5
appcastdoc.delete_element('//channel/item[position()>5]')
new_xml = Tempfile.new('appcast.xml')
appcastdoc.write(new_xml)
new_xml.close()
appcast.close()
#Send the updated appcast to the server
%x[cp '#{new_xml.path}' '#{site_dir}/#{feed}.xml']
%x[rm -rf '#{temp_path}/Cog.app']
#Upload to S3
%x[s3cmd put -P -m application/xml '#{site_dir}/#{feed}.xml' s3://balde.losno.co/cog/ --signature-v2]
%x[s3cmd put -P -m application/xml '#{site_dir}/#{feed}_builds/#{feed}.xml' s3://balde.losno.co/cog/ --signature-v2]
#Invalidate CDN
%x[aws cloudfront create-invalidation --distribution-id E1WUF11KRNP2VH --paths /cog/mercury.xml]