diff --git a/README.md b/README.md index 39edcde..08dd888 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Middleman Delpoy -- Deploy a [middleman](http://middlemanapp.com/) built site ov ## QUICK START -Be sure that `rsync` is installed. +If deploying through `rsync`, be sure it is installed. ### Step 1 @@ -27,22 +27,21 @@ Then run: bundle install -### Step 4 +### Step 4a - Rsync setup #### These settings are required. Edit `config.rb`, and add: activate :deploy do |deploy| - deploy.user = "tvaughan" - deploy.host = "www.example.com" - deploy.path = "/srv/www/site" + deploy.method = :rsync + deploy.user = "tvaughan" + deploy.host = "www.example.com" + deploy.path = "/srv/www/site" end Adjust these values accordingly. -### Step 4.1 - #### These settings are optional. To use a particular SSH port, add: @@ -57,6 +56,17 @@ To remove orphaned files or directories on the remote host, add: Default is `false`. +### Step 4b - Github Pages setup + +Edit `config.rb`, and add: + + activate :deploy do |deploy| + deploy.method = :git + end + +The git deploy method assumes your project is in a repository with +github set up as `origin` and a working `gh-pages` branch already in place. + ### Step 5 middleman build diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 4494c4d..5d36e30 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -2,6 +2,8 @@ require "middleman-core/cli" require "middleman-deploy/extension" +require 'git' + module Middleman module Cli @@ -18,18 +20,26 @@ module Middleman true end - desc "deploy", "Copy build directory to a remote host over rsync" + desc "deploy", "Copy build directory to a remote host" method_option "clean", :type => :boolean, :aliases => "-c", :desc => "Remove orphaned files or directories on the remote host" def deploy - shared_inst = ::Middleman::Application.server.inst + send("deploy_#{self.middleman_options.method}") + end - host = shared_inst.options.host - port = shared_inst.options.port - user = shared_inst.options.user - path = shared_inst.options.path + protected + + def middleman_options + ::Middleman::Application.server.inst.options + end + + def deploy_rsync + host = self.middleman_options.host + port = self.middleman_options.port + user = self.middleman_options.user + path = self.middleman_options.path # These only exists when the config.rb sets them! if (!host || !user || !path) @@ -51,6 +61,30 @@ module Middleman run command end + def deploy_git + puts "## Deploying to Github Pages" + Dir.mktmpdir do |tmp| + # clone ./ with branch gh-pages to tmp + repo = Git.clone(ENV['MM_ROOT'], tmp) + repo.checkout('origin/gh-pages', :new_branch => 'gh-pages') + + # copy ./build/* to tmp + FileUtils.cp_r(Dir.glob(File.join(ENV['MM_ROOT'], 'build', '*')), tmp) + + # git add and commit in tmp + repo.add + repo.commit("Automated commit at #{Time.now.utc}") + + # push from tmp to self + repo.push('origin', 'gh-pages') + + # push to github + github_url = Git.open(ENV['MM_ROOT']).remote.url + repo.add_remote('github', github_url) + repo.push('github', 'gh-pages') + end + end + end # Alias "d" to "deploy" diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index f7b05a5..3eee769 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -5,7 +5,7 @@ require "middleman-core" module Middleman module Deploy - class Options < Struct.new(:host, :port, :user, :path, :clean); end + class Options < Struct.new(:method, :host, :port, :user, :path, :clean); end class << self @@ -17,6 +17,7 @@ module Middleman options = Options.new(options_hash) yield options if block_given? + options.method ||= :rsync options.port ||= 22 options.clean ||= false @@ -25,8 +26,9 @@ module Middleman app.send :include, Helpers app.after_configuration do - if (!options.host || !options.user || !options.path) - raise <= 3.0.0"]) # Additional dependencies - # s.add_runtime_dependency("gem-name", "gem-version") + s.add_runtime_dependency("git", "~> 1.2.0") end