Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created October 23, 2012 21:12
Show Gist options
  • Save duncanmak/3941607 to your computer and use it in GitHub Desktop.
Save duncanmak/3941607 to your computer and use it in GitHub Desktop.
script-helpers
module Helpers
require 'zip/zipfilesystem'
require 'open-uri'
module_function
def log (text)
print "#{'=' * 10} #{text} #{'=' * 10}"
$stdout.flush
end
def download(url, filename)
File.open(filename, "wb") do |output|
open("url") {|input| output.write(input.read)}
end
filename
end
def unzip_bundle(bundle, destination)
Zip::ZipFile.open bundle do |zip_file|
zip_file.each do |f|
path = File.join(destination, f.name)
FileUtils.mkdir_p File.dirname(f_path)
zip_file.extract(f, path) unless File.exist?(path)
end
end
end
def replace_text(filename, original, replacement)
text = File.read(filename).gsub(original, replacement)
File.open(filename, 'w') do |f| f << text end
text
end
def msbuild(*args)
print "Running msbuild #{args.join(' ')}"
cmd = 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe'
`#{cmd} #{args.join(' ')}`
end
def git(*args)
print "Running git #{args.join(' ')}"
cmd = 'C:\\Program Files\\Git\\bin\\git.exe'
`#{cmd} #{args.join(' ')}`
end
def reset_to_commit(repo, branch, commit)
log ("Resetting %s (%s) to %s" % (repo, branch, commit))
curdir = getcwd ()
Dir.chdir(repo) do
# Clean working dir and pull in changes from 'branch'
git ('clean', '-xfd')
git ('submodule', 'foreach', '--recursive', 'git', 'clean', '-xfd')
git ('reset', '--hard', 'HEAD')
git ('submodule', 'foreach', '--recursive', 'git', 'reset', '--hard', 'HEAD')
git ('checkout', '-q', branch)
git ('pull')
# Check that 'branch' contains 'commit'
branch_names = git ("branch", "--contains", commit)
raise "Branch '#{branch}' does not contain commit '#{commit}'" unless branch_names.include?(branch)
git ('checkout', '-q', commit)
git ('submodule', 'update', '--init', '--recursive')
end
end
def extract_hashes(readme)
hashes = readme.match /cd (\S+) && git checkout -b \S+ \S+\/(\S+)\s+\$ cd \S+ && git reset --hard (\S+)/
hashes.inject({}) do |hash, (repo, branch, commit)|
hash[repo] = {:branch => branch, :commit => commit};
hash
end
end
end
module IOSHelpers
module_function
def update_version_strings(android_vs, version_string)
log "update version strings: #{version_string}"
# Setup/MonoTouch/Product.wxs
product_wxs = File.join(android_vs, "Setup", "MonoTouch", "Product.wxs")
replace_text(
product_wxs,
%q{<?define ProductVersion = "1.0.0" ?>},
%Q{<?define ProductVersion = "#{version_string}" ?>},
)
replace_text(
product_wxs,
%q{<?define ProductVersionText = "1.0" ?>},
%Q{<?define ProductVersionText = "#{version_string}" ?>},
)
# Mono.IOS.VisualStudio/MonoAndroidPackage.cs
mono_androidpackage_cs = File.join(android_vs, "Mono.IOS.VisualStudio", "MonoAndroidPackage.cs")
replace_text(
mono_androidpackage_cs,
'\t' + %q{[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]},
'\t' + %Q{[InstalledProductRegistration("#110", "#112", "#{version_string}", IconResourceID = 400)]}
)
# Mono.IOS.VisualStudio/Metadata/source.extension.vsixmanifest
vsixmanifest = File.join(android_vs, "Mono.IOS.VisualStudio", "Metadata", "source.extension.vsixmanifest")
replace_text(
vsixmanifest,
%q{<Version>1.0</Version>},
%Q{<Version>#{version_string}</Version>}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment