mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 06:05:00 -05:00
Improvements to hosting with Github Pages:
1. Push deployment task pulls first, avoiding a --force push 2. Improvements to rake task setup_github_pages: - Now only rewrites _config.yml if in default state - Attempts a pull from deploy repo before setting up as a new project - Detects conflicts between CNAME and _config.yml url - Links to GitHub's help documentation for CNAME setup Fixes #561
This commit is contained in:
parent
7025a1a90a
commit
654a2937b8
106
Rakefile
106
Rakefile
@ -221,7 +221,6 @@ task :deploy do
|
|||||||
File.delete(".preview-mode")
|
File.delete(".preview-mode")
|
||||||
Rake::Task[:generate].execute
|
Rake::Task[:generate].execute
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::Task[:copydot].invoke(source_dir, public_dir)
|
Rake::Task[:copydot].invoke(source_dir, public_dir)
|
||||||
Rake::Task["#{deploy_default}"].execute
|
Rake::Task["#{deploy_default}"].execute
|
||||||
end
|
end
|
||||||
@ -249,20 +248,28 @@ end
|
|||||||
|
|
||||||
desc "deploy public directory to github pages"
|
desc "deploy public directory to github pages"
|
||||||
multitask :push do
|
multitask :push do
|
||||||
puts "## Deploying branch to Github Pages "
|
if File.directory?(deploy_dir)
|
||||||
(Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
|
puts "## Deploying branch to Github Pages "
|
||||||
Rake::Task[:copydot].invoke(public_dir, deploy_dir)
|
(Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
|
||||||
puts "\n## copying #{public_dir} to #{deploy_dir}"
|
Rake::Task[:copydot].invoke(public_dir, deploy_dir)
|
||||||
cp_r "#{public_dir}/.", deploy_dir
|
puts "Attempting pull, to sync local deployment repository"
|
||||||
cd "#{deploy_dir}" do
|
cd "#{deploy_dir}" do
|
||||||
system "git add ."
|
system "git pull origin #{deploy_branch}"
|
||||||
system "git add -u"
|
end
|
||||||
puts "\n## Commiting: Site updated at #{Time.now.utc}"
|
puts "\n## copying #{public_dir} to #{deploy_dir}"
|
||||||
message = "Site updated at #{Time.now.utc}"
|
cp_r "#{public_dir}/.", deploy_dir
|
||||||
system "git commit -m \"#{message}\""
|
cd "#{deploy_dir}" do
|
||||||
puts "\n## Pushing generated #{deploy_dir} website"
|
system "git add ."
|
||||||
system "git push origin #{deploy_branch} --force"
|
system "git add -u"
|
||||||
puts "\n## Github Pages deploy complete"
|
message = "Site updated at #{Time.now.utc}"
|
||||||
|
puts "\n## Commiting: #{message}"
|
||||||
|
system "git commit -m \"#{message}\""
|
||||||
|
puts "\n## Pushing generated #{deploy_dir} website"
|
||||||
|
system "git push origin #{deploy_branch}"
|
||||||
|
puts "\n## Github Pages deploy complete"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "This project isn't configured for deploying to Github Pages\nPlease run `rake setup_github_pages[your-deployment-repo-url]`."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -311,6 +318,8 @@ task :setup_github_pages, :repo do |t, args|
|
|||||||
user = repo_url.match(/:([^\/]+)/)[1]
|
user = repo_url.match(/:([^\/]+)/)[1]
|
||||||
branch = (repo_url.match(/\/[\w-]+.github.com/).nil?) ? 'gh-pages' : 'master'
|
branch = (repo_url.match(/\/[\w-]+.github.com/).nil?) ? 'gh-pages' : 'master'
|
||||||
project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
|
project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
|
||||||
|
url = "http://#{user}.github.com"
|
||||||
|
url += "/#{project}" unless project == ''
|
||||||
unless `git remote -v`.match(/origin.+?octopress.git/).nil?
|
unless `git remote -v`.match(/origin.+?octopress.git/).nil?
|
||||||
# If octopress is still the origin remote (from cloning) rename it to octopress
|
# If octopress is still the origin remote (from cloning) rename it to octopress
|
||||||
system "git remote rename origin octopress"
|
system "git remote rename origin octopress"
|
||||||
@ -325,34 +334,65 @@ task :setup_github_pages, :repo do |t, args|
|
|||||||
puts "Master branch renamed to 'source' for committing your blog source files"
|
puts "Master branch renamed to 'source' for committing your blog source files"
|
||||||
else
|
else
|
||||||
unless !public_dir.match("#{project}").nil?
|
unless !public_dir.match("#{project}").nil?
|
||||||
system "rake set_root_dir[#{project}]"
|
Rake::Task[:set_root_dir].invoke(project)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
url = "http://#{user}.github.com"
|
|
||||||
url += "/#{project}" unless project == ''
|
# Configure deployment repository
|
||||||
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
|
rm_rf deploy_dir
|
||||||
mkdir deploy_dir
|
mkdir deploy_dir
|
||||||
cd "#{deploy_dir}" do
|
cd "#{deploy_dir}" do
|
||||||
system "git init"
|
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}"
|
system "git remote add origin #{repo_url}"
|
||||||
rakefile = IO.read(__FILE__)
|
puts "Attempting to pull from repository"
|
||||||
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
|
system "git pull origin #{branch}"
|
||||||
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3")
|
unless File.exist?('index.html')
|
||||||
File.open(__FILE__, 'w') do |f|
|
system "echo 'My Octopress Page is coming soon …' > index.html"
|
||||||
f.write rakefile
|
system "git add ."
|
||||||
|
system "git commit -m \"Octopress init\""
|
||||||
|
system "git branch -m gh-pages" unless branch == 'master'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "\n---\n## Now you can deploy to #{url} with `rake deploy` ##"
|
|
||||||
|
# Configure deployment setup in Rakefile
|
||||||
|
rakefile = IO.read(__FILE__)
|
||||||
|
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
|
||||||
|
|
||||||
|
# Configure published url
|
||||||
|
jekyll_config = IO.read('_config.yml')
|
||||||
|
current_url = /^url:\s?(.*$)/.match(jekyll_config)[1]
|
||||||
|
has_cname = File.exists?("#{source_dir}/CNAME")
|
||||||
|
if current_url == 'http://yoursite.com'
|
||||||
|
jekyll_config.sub!(/^url:.*$/, "url: #{url}")
|
||||||
|
File.open('_config.yml', 'w') do |f|
|
||||||
|
f.write jekyll_config
|
||||||
|
end
|
||||||
|
current_url = url
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "\n========================================================"
|
||||||
|
if has_cname
|
||||||
|
cname = IO.read("#{source_dir}/CNAME").chomp
|
||||||
|
current_short_url = /\/{2}(.*$)/.match(current_url)[1]
|
||||||
|
if cname != current_short_url
|
||||||
|
puts "!! WARNING: Your CNAME points to #{cname} but your _config.yml url is set to #{current_short_url} !!"
|
||||||
|
puts "For help with setting up a CNAME follow the guide at http://help.github.com/pages/#custom_domains"
|
||||||
|
else
|
||||||
|
puts "Github Pages will host your site at http://#{cname}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "Github Pages will host your site at #{url}."
|
||||||
|
puts "To host at \"your-site.com\", configure a CNAME: `echo \"your-domain.com\" > #{source_dir}/CNAME`"
|
||||||
|
puts "Then change the url in _config.yml from #{current_url} to http://your-domain.com"
|
||||||
|
puts "Finally, follow the guide at http://help.github.com/pages/#custom_domains for help pointing your domain to Github Pages"
|
||||||
|
end
|
||||||
|
puts "Deploy to #{repo_url} with `rake deploy`"
|
||||||
|
puts "========================================================"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ok_failed(condition)
|
def ok_failed(condition)
|
||||||
|
Loading…
Reference in New Issue
Block a user