Skip to content

Instantly share code, notes, and snippets.

@mps
Created September 24, 2013 14:16
Show Gist options
  • Save mps/6685438 to your computer and use it in GitHub Desktop.
Save mps/6685438 to your computer and use it in GitHub Desktop.
Some rakefile fun for uploading a config json file, supports branching / pr
require 'aws-sdk'
require 'hub'
######################
#### CONFIG STUFF ####
######################
desc 'Update Config Files'
task :config do
puts 'Updating config files...'
s3 = AWS::S3.new(
:access_key_id => '',
:secret_access_key => '')
bucket = s3.buckets['vertigo.work']
tablet_config_name = config_file_name(false)
tablet_config_name = "gngps/#{tablet_config_name}"
handset_config_name = config_file_name(true)
handset_config_name = "gngps/#{handset_config_name}"
tablet_config = bucket.objects[tablet_config_name]
handset_config = bucket.objects[handset_config_name]
puts 'Saving Tablet Config...'
tablet_config.write(Pathname.new('./BirdE/App/Supporting Files/Staging/config.ios.tablet.json'), :acl => :public_read, :content_type => 'application/json')
puts 'Saving Handset Config...'
handset_config.write(Pathname.new('./BirdE/App/Supporting Files/Staging/config.ios.handset.json'), :acl => :public_read, :content_type => 'application/json')
end
def config_file_name(isHandset)
config = 'config.ios.tablet.json'
if isHandset
config = 'config.ios.handset.json'
end
current_branch = get_current_branch
new_config = config
if current_branch != 'master'
new_config = "#{current_branch}#{config}"
end
new_config
end
def get_current_branch
b = `git branch`.split("\n").delete_if { |i| i[0] != "*" }
b.first.gsub("* ","")
end
desc 'creates a branch, updates config and pushes to origin'
task :branch do
branch_name = ARGV[1]
if branch_name == nil
puts "*****ERROR**** Invalid branch name"
exit
end
branch_command = "git checkout -b #{branch_name}"
sh branch_command
config_prefix(branch_name, true)
# update configs
sh "rake config"
# commit changes
sh "git commit -am \"set new branch\""
# push changes to github
sh "git push origin #{branch_name}"
exit
end
desc 'updates config, pushes to origin, creates a pull request on GH'
task :pr do
current_branch = get_current_branch
config_prefix(current_branch, false)
# commit changes
sh "git commit -am \"remove config prefix\""
# push changes to github
sh "git push origin #{current_branch}"
sh "hub pull-request -b vertigo:master -h vertigo:#{current_branch}"
end
def config_prefix(branch_name, add)
filename = "./BirdE/App/Supporting Files/AppDefines.h"
if add
outdata = File.read(filename).gsub('CONFIG_PREFIX @""', "CONFIG_PREFIX @\"#{branch_name}\"")
else
outdata = File.read(filename).gsub("CONFIG_PREFIX @\"#{branch_name}\"", 'CONFIG_PREFIX @""')
end
File.open(filename, 'w') do |out|
out << outdata
end
end
desc 'updates from origin and updates config'
task :sync do
current_branch = get_current_branch
# pull changes from github
sh "git pull origin #{current_branch}"
# update config
sh "rake config"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment