Skip to content

Commit

Permalink
Auto-deploy after commit to master
Browse files Browse the repository at this point in the history
  • Loading branch information
kruczjak committed May 23, 2016
1 parent 1fea3ea commit 9c6774c
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 89 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
language: ruby
cache: bundler
rvm:
- 2.3.0
install:
- bundle install --path vendor/bundle
- eval "$(ssh-agent -s)"
script: bundle exec rake travis:deploy
branches:
only:
- master
90 changes: 1 addition & 89 deletions Rakefile
@@ -1,98 +1,10 @@
directory "vendor"
directory "vendor/bundler" => ["vendor"] do
system "git clone https://github.com/bundler/bundler.git vendor/bundler"
end

task :update_vendor => ["vendor/bundler"] do
Dir.chdir("vendor/bundler") { sh "git fetch" }
end

VERSIONS = Dir.chdir("source") { Dir.glob("v*").sort_by{|x| [x.size, x] } }.freeze
desc "Print the Bundler versions the site documents"
task :versions do
puts VERSIONS.join(' ')
end

desc "Pull in the man pages for the specified gem versions."
task :man => [:update_vendor] do
VERSIONS.each do |version|
next if version == "v0.9"
branch = (version[1..-1].split('.') + %w(stable)).join('-')

rm_rf "source/#{version}/man"
mkdir_p "source/#{version}/man"

Dir.chdir "vendor/bundler" do
sh "git reset --hard HEAD"
sh "git checkout origin/#{branch}"
sh "ronn -5 man/*.ronn"
cp(FileList["man/*.html"], "../../source/#{version}/man")
sh "git clean -fd"
end
end

# Make man pages for the latest version available at the top level, too.
rm_rf "source/man"
cp_r "source/#{VERSIONS.last}/man", "source"
end

desc "Pulls in pages maintained in the bundler repo."
task :repo_pages => [:update_vendor] do
Dir.chdir "vendor/bundler" do
sh "git reset --hard HEAD"
sh "git checkout origin/master"
cp "ISSUES.md", "../../source/issues.md"
cp "CODE_OF_CONDUCT.md", "../../source/conduct.md"
end
end

directory "vendor/bundler.github.io" => ["vendor"] do
system "git clone https://github.com/bundler/bundler.github.io.git vendor/bundler.github.io"
end

task :update_site => ["vendor/bundler.github.io"] do
Dir.chdir "vendor/bundler.github.io" do
sh "git checkout master"
sh "git reset --hard HEAD"
sh "git pull origin master"
end
end
Dir.glob("lib/tasks/**/*.rake").each { |r| load r }

desc "Build the static site"
task :build => [:repo_pages, :man] do
sh "middleman build --clean"
end

desc "Release the current commit to bundler/bundler.github.io"
task :release => [:build, :update_site] do
commit = `git rev-parse HEAD`.chomp

Dir.chdir "vendor/bundler.github.io" do
rm_rf FileList["*"]
cp_r FileList["../../build/*"], "./"
File.write("CNAME", "bundler.io")

sh "git add -A ."
sh "git commit -m 'bundler/bundler-site@#{commit}'"

Bundler.with_clean_env do
puts <<-TWO_FACTOR_WARNING
====================================================================
Please note that if you have two-factor auth enabled for your Github
account, you will need to use a github access token instead of your
account password.
====================================================================
TWO_FACTOR_WARNING
sh "git push origin master"
end
end

Bundler.with_clean_env do
sh "git push origin master"
end
end

# Heroku deploys need to build the non-Middleman pages
namespace :assets do
task :precompile => [:repo_pages, :man]
end
Binary file added deploy_key.enc
Binary file not shown.
22 changes: 22 additions & 0 deletions lib/tasks/man.rake
@@ -0,0 +1,22 @@
desc "Pull in the man pages for the specified gem versions."
task :man => [:update_vendor] do
VERSIONS.each do |version|
next if version == "v0.9"
branch = (version[1..-1].split('.') + %w(stable)).join('-')

rm_rf "source/#{version}/man"
mkdir_p "source/#{version}/man"

Dir.chdir "vendor/bundler" do
sh "git reset --hard HEAD"
sh "git checkout origin/#{branch}"
sh "ronn -5 man/*.ronn"
cp(FileList["man/*.html"], "../../source/#{version}/man")
sh "git clean -fd"
end
end

# Make man pages for the latest version available at the top level, too.
rm_rf "source/man"
cp_r "source/#{VERSIONS.last}/man", "source"
end
28 changes: 28 additions & 0 deletions lib/tasks/release.rake
@@ -0,0 +1,28 @@
desc "Release the current commit to bundler/bundler.github.io"
task :release => [:build, :update_site] do
commit = `git rev-parse HEAD`.chomp

Dir.chdir "vendor/bundler.github.io" do
rm_rf FileList["*"]
cp_r FileList["../../build/*"], "./"
File.write("CNAME", "bundler.io")

sh "git add -A ."
sh "git commit -m 'bundler/bundler-site@#{commit}'"

Bundler.with_clean_env do
puts <<-TWO_FACTOR_WARNING
====================================================================
Please note that if you have two-factor auth enabled for your Github
account, you will need to use a github access token instead of your
account password.
====================================================================
TWO_FACTOR_WARNING
sh "git push origin master"
end
end

Bundler.with_clean_env do
sh "git push origin master"
end
end
42 changes: 42 additions & 0 deletions lib/tasks/travis/deploy.rake
@@ -0,0 +1,42 @@
namespace :travis do
def encrypted_key
ENV["encrypted_#{ENV["ENCRYPTION_LABEL"]}_key"]
end

def encrypted_iv
ENV["encrypted_#{ENV["ENCRYPTION_LABEL"]}_iv"]
end

def commit_author_email
ENV["COMMIT_AUTHOR_EMAIL"]
end

def configure_ssh_deploy_key
sh "openssl aes-256-cbc -K #{encrypted_key} -iv #{encrypted_iv} -in deploy_key.enc -out deploy_key -d"
sh "chmod 600 deploy_key"
sh "ssh-add deploy_key"
sh "rm deploy_key"
end

task :deploy => [:build] do
configure_ssh_deploy_key

Rake::Task["travis:update_ssh_site"].invoke

commit = `git rev-parse HEAD`.chomp

Dir.chdir "vendor/ssh_bundler.github.io" do
rm_rf FileList["*"]
cp_r FileList["../../build/*"], "./"
File.write("CNAME", "bundler.io")

sh "git add -A ."

sh "git config user.name 'Travis CI'"
sh "git config user.email '#{commit_author_email}'"

sh "git commit -m 'bundler/bundler-site@#{commit}'"
sh "git push origin master"
end
end
end
13 changes: 13 additions & 0 deletions lib/tasks/travis/ssh_repo.rake
@@ -0,0 +1,13 @@
directory "vendor/ssh_bundler.github.io" => ["vendor"] do
system "git clone git@github.com:bundler/bundler.github.io vendor/ssh_bundler.github.io"
end

namespace :travis do
task :update_ssh_site => ["vendor/ssh_bundler.github.io"] do
Dir.chdir "vendor/ssh_bundler.github.io" do
sh "git checkout master"
sh "git reset --hard HEAD"
sh "git pull origin master"
end
end
end
30 changes: 30 additions & 0 deletions lib/tasks/vendor_files.rake
@@ -0,0 +1,30 @@
directory "vendor"
directory "vendor/bundler" => ["vendor"] do
system "git clone https://github.com/bundler/bundler.git vendor/bundler"
end

task :update_vendor => ["vendor/bundler"] do
Dir.chdir("vendor/bundler") { sh "git fetch" }
end

desc "Pulls in pages maintained in the bundler repo."
task :repo_pages => [:update_vendor] do
Dir.chdir "vendor/bundler" do
sh "git reset --hard HEAD"
sh "git checkout origin/master"
cp "ISSUES.md", "../../source/issues.md"
cp "CODE_OF_CONDUCT.md", "../../source/conduct.md"
end
end

directory "vendor/bundler.github.io" => ["vendor"] do
system "git clone https://github.com/bundler/bundler.github.io vendor/bundler.github.io"
end

task :update_site => ["vendor/bundler.github.io"] do
Dir.chdir "vendor/bundler.github.io" do
sh "git checkout master"
sh "git reset --hard HEAD"
sh "git pull origin master"
end
end
6 changes: 6 additions & 0 deletions lib/tasks/versions.rake
@@ -0,0 +1,6 @@
VERSIONS = Dir.chdir("source") { Dir.glob("v*").sort_by{|x| [x.size, x] } }.freeze

desc "Print the Bundler versions the site documents"
task :versions do
puts VERSIONS.join(' ')
end

0 comments on commit 9c6774c

Please sign in to comment.