improved github configuration raketask

This commit is contained in:
Brandon Mathis 2011-09-22 04:41:40 -05:00
parent 92ff4a9c67
commit 4efb29394f
1 changed files with 38 additions and 9 deletions

View File

@ -274,25 +274,54 @@ task :set_root_dir, :dir do |t, args|
end
end
desc "Setup _deploy folder and deploy branch"
task :config_deploy, :branch do |t, args|
puts "!! Please provide a deploy branch, eg. rake init_deploy[gh-pages] !!" unless args.branch
puts "## Creating a clean #{args.branch} branch in ./#{deploy_dir} for Github pages deployment"
desc "Set up _deploy folder and deploy branch for Github Pages deployment"
task :setup_github do
repo_url = get_stdin("Enter the read/write url for your repository: ")
user = repo_url.match(/:([^\/]+)/)[1]
branch = (repo_url.match(/\/\w+.github.com/).nil?) ? 'gh-pages' : 'master'
project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
unless `git remote -v`.match(/origin.+?octopress.git/).nil?
# If octopress is still the origin remote (from cloning) rename it to octopress
system "git remote rename origin octopress"
if branch == 'master'
# If this is a user/organization pages repository, add the correct origin remote
# and checkout the source branch for committing changes to the blog source.
system "git remote add origin #{repo_url}"
puts "Added remote #{repo_url} as origin"
system "git config branch.master.remote origin"
puts "Set origin as default remote"
system "git branch -m master source"
puts "Master branch renamed to 'source' for committing your blog source files"
else
unless !public_dir.match("#{project}").nil?
system "rake set_root_dir[#{project}]"
end
end
end
url = "http://#{user}.github.com"
url += "/#{project}" unless project == ''
jekyll_config = IO.read('_config.yml')
jekyll_config.sub!(/^url:.*$/, "url: #{url}")
File.open('_config.yml', 'w') do |f|
f.write jekyll_config
end
rm_rf deploy_dir
mkdir deploy_dir
cd "#{deploy_dir}" do
system "git symbolic-ref HEAD refs/heads/#{args.branch}"
system "rm .git/index"
system "git clean -fdx"
system "git init"
system "echo 'My Octopress Page is coming soon …' > index.html"
system "git add ."
system "git commit -m \"Octopress init\""
system "git branch -m gh-pages" unless branch == 'master'
system "git remote add origin #{repo_url}"
rakefile = IO.read(__FILE__)
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{args.branch}\\3")
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3")
File.open(__FILE__, 'w') do |f|
f.write rakefile
end
end
puts "## Deployment configured. Now you can deploy to the #{args.branch} branch with `rake deploy` ##"
puts "\n---\n## Now you can deploy to #{url} with `rake deploy` ##"
end
def ok_failed(condition)