From 21d04f253acbdff7fa5684369db9b7ce56ed5330 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Fri, 21 Nov 2014 18:25:10 +0000 Subject: [PATCH 01/10] latest travis --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f36108..c3e0bfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby +sudo: false cache: bundler bundler_args: --without development rvm: @@ -10,6 +11,7 @@ rvm: - 2.0.0 - 1.9.3 - rbx-2 +before_script: bundle update matrix: fast_finish: true allow_failures: @@ -21,4 +23,4 @@ matrix: notifications: email: false env: - - CODECLIMATE_REPO_TOKEN=5eee8e8624962f963a52a1d2313dc7407e3b8006291e3704346c786642cc073b \ No newline at end of file + - CODECLIMATE_REPO_TOKEN=5eee8e8624962f963a52a1d2313dc7407e3b8006291e3704346c786642cc073b From 4b79845d536a306ccad2afc5d7f875d6454f27e6 Mon Sep 17 00:00:00 2001 From: Pete Nicholls Date: Sun, 18 Jan 2015 14:51:25 +1300 Subject: [PATCH 02/10] Fix Git user.email change in force push strategy --- lib/middleman-deploy/strategies/git/force_push.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/strategies/git/force_push.rb b/lib/middleman-deploy/strategies/git/force_push.rb index 113d385..266cfe5 100644 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ b/lib/middleman-deploy/strategies/git/force_push.rb @@ -20,7 +20,7 @@ module Middleman `git init` `git remote add origin #{url}` `git config user.name "#{self.user_name}"` - `git config user.name "#{self.user_email}"` + `git config user.email "#{self.user_email}"` else # check if the remote repo has changed unless url == `git config --get remote.origin.url`.chop From 9eece01aef5228f938045d317066caf9603f6a0a Mon Sep 17 00:00:00 2001 From: Emilio Forrer Date: Sun, 22 Feb 2015 15:52:52 -0600 Subject: [PATCH 03/10] Fixing compatibility issues with middleman v4.0.0.beta.1 --- CHANGELOG.md | 8 ++++ README.md | 38 ++++++++-------- lib/middleman-deploy.rb | 2 +- lib/middleman-deploy/commands.rb | 63 ++++++++++++++++++++------- lib/middleman-deploy/extension.rb | 42 +++++++++++------- lib/middleman-deploy/methods/base.rb | 4 ++ lib/middleman-deploy/methods/ftp.rb | 2 +- lib/middleman-deploy/methods/git.rb | 2 +- lib/middleman-deploy/methods/rsync.rb | 2 +- lib/middleman-deploy/methods/sftp.rb | 2 +- 10 files changed, 110 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48f652d..5a1bd4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,11 @@ master * Respect user details of git repo. #70 * Prevent bad commits deploying. (git) #77 + +development +=== + +2.0.0 +=== + +* Fixing compatibility issues with middleman v4.0.0.beta.1 diff --git a/README.md b/README.md index 6ddd1e4..17ca28f 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ following to `config.rb`: ```ruby activate :deploy do |deploy| - deploy.method = :rsync - deploy.host = 'www.example.com' - deploy.path = '/srv/www/site' + deploy.deploy_method = :rsync + deploy.host = 'www.example.com' + deploy.path = '/srv/www/site' # Optional Settings # deploy.user = 'tvaughan' # no default # deploy.port = 5309 # ssh port, default: 22 @@ -44,7 +44,7 @@ following to `config.rb`: ```ruby activate :deploy do |deploy| - deploy.method = :git + deploy.deploy_method = :git # Optional Settings # deploy.remote = 'custom-remote' # remote name or git url, default: origin # deploy.branch = 'custom-branch' # default: gh-pages @@ -70,11 +70,11 @@ Activate the extension by adding the following to `config.rb`: ```ruby activate :deploy do |deploy| - deploy.method = :ftp - deploy.host = 'ftp.example.com' - deploy.path = '/srv/www/site' - deploy.user = 'tvaughan' - deploy.password = 'secret' + deploy.deploy_method = :ftp + deploy.host = 'ftp.example.com' + deploy.path = '/srv/www/site' + deploy.user = 'tvaughan' + deploy.password = 'secret' end ``` @@ -84,10 +84,10 @@ Activate the extension by adding the following to `config.rb`: ```ruby activate :deploy do |deploy| - deploy.method = :sftp - deploy.host = 'sftp.example.com' - deploy.port = 22 - deploy.path = '/srv/www/site' + deploy.deploy_method = :sftp + deploy.host = 'sftp.example.com' + deploy.port = 22 + deploy.path = '/srv/www/site' # Optional Settings # deploy.user = 'tvaughan' # no default # deploy.password = 'secret' # no default @@ -115,15 +115,15 @@ Deploy your site to more than one configuration using environment variables. case ENV['TARGET'].to_s.downcase when 'production' activate :deploy do |deploy| - deploy.method = :rsync - deploy.host = 'www.example.com' - deploy.path = '/srv/www/production-site' + deploy.deploy_method = :rsync + deploy.host = 'www.example.com' + deploy.path = '/srv/www/production-site' end else activate :deploy do |deploy| - deploy.method = :rsync - deploy.host = 'staging.example.com' - deploy.path = '/srv/www/staging-site' + deploy.deploy_method = :rsync + deploy.host = 'staging.example.com' + deploy.path = '/srv/www/staging-site' end end ``` diff --git a/lib/middleman-deploy.rb b/lib/middleman-deploy.rb index 796f4ca..124cd48 100644 --- a/lib/middleman-deploy.rb +++ b/lib/middleman-deploy.rb @@ -4,5 +4,5 @@ require 'middleman-deploy/commands' ::Middleman::Extensions.register(:deploy) do require 'middleman-deploy/extension' - ::Middleman::Deploy + ::Middleman::Deploy::Extension end diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 345615a..549caab 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -8,24 +8,53 @@ require 'middleman-deploy/strategies' module Middleman module Cli # This class provides a "deploy" command for the middleman CLI. - class Deploy < Thor + class Deploy < Thor::Group include Thor::Actions check_unknown_options! namespace :deploy + class_option :environment, + aliases: '-e', + default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'production', + desc: 'The environment Middleman will run under' + + class_option :verbose, + type: :boolean, + default: false, + desc: 'Print debug messages' + + class_option :instrument, + type: :string, + default: false, + desc: 'Print instrument messages' + + class_option :build_before, + type: :boolean, + aliases: '-b', + desc: 'Run `middleman build` before the deploy step' + + def self.subcommand_help options + # TODO + end + # Tell Thor to exit with a nonzero exit code on failure def self.exit_on_failure? true end - desc 'deploy [options]', Middleman::Deploy::TAGLINE - method_option 'build_before', - type: :boolean, - aliases: '-b', - desc: 'Run `middleman build` before the deploy step' + def deploy + env = options['environment'] ? :production : options['environment'].to_s.to_sym + verbose = options['verbose'] ? 0 : 1 + instrument = options['instrument'] + + @app = ::Middleman::Application.new do + config[:mode] = :build + config[:environment] = env + ::Middleman::Logger.singleton(verbose, instrument) + end build_before(options) process end @@ -37,18 +66,19 @@ module Middleman if build_enabled # http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension - run('middleman build') || exit(1) + run("middleman build -e #{options['environment']}") || exit(1) end end def print_usage_and_die(message) - raise Error, "ERROR: #{message}\n#{Middleman::Deploy::README}" + raise StandardError, "ERROR: #{message}\n#{Middleman::Deploy::README}" end - def process - server_instance = ::Middleman::Application.server.inst - camelized_method = self.deploy_options.method.to_s.split('_').map { |word| word.capitalize}.join + + def process + server_instance = @app + camelized_method = self.deploy_options.deploy_method.to_s.split('_').map { |word| word.capitalize}.join method_class_name = "Middleman::Deploy::Methods::#{camelized_method}" method_instance = method_class_name.constantize.new(server_instance, self.deploy_options) @@ -59,19 +89,19 @@ module Middleman options = nil begin - options = ::Middleman::Application.server.inst.options + options = ::Middleman::Deploy.options rescue NoMethodError print_usage_and_die 'You need to activate the deploy extension in config.rb.' end - unless options.method + unless options.deploy_method print_usage_and_die 'The deploy extension requires you to set a method.' end - case options.method + case options.deploy_method when :rsync, :sftp unless options.host && options.path - print_usage_and_die "The #{options.method} method requires host and path to be set." + print_usage_and_die "The #{options.deploy_method} method requires host and path to be set." end when :ftp unless options.host && options.user && options.password && options.path @@ -83,6 +113,9 @@ module Middleman end end + # Add to CLI + Base.register(Middleman::Cli::Deploy, 'deploy', 'deploy [options]', Middleman::Deploy::TAGLINE) + # Alias "d" to "deploy" Base.map('d' => 'deploy') end diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 8ad1e16..c10606b 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -4,15 +4,30 @@ require 'middleman-core' # Extension namespace module Middleman module Deploy - class Options < Struct.new(:method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message); end - class << self - def options - @@options - end + cattr_accessor :options + + class Extension < Extension + + option :deploy_method, nil + option :host, nil + option :port, nil + option :user, nil + option :password, nil + option :path, nil + option :clean, nil + option :remote, nil + option :branch, nil + option :strategy, nil + option :build_before, nil + option :flags, nil + option :commit_message, nil + + + + def initialize(app, options_hash = {}, &block) + super - def registered(app, options_hash = {}, &block) - options = Options.new(options_hash) yield options if block_given? # Default options for the rsync method. @@ -27,18 +42,13 @@ module Middleman options.build_before ||= false - @@options = options - - app.send :include, Helpers end - alias_method :included, :registered + def after_configuration + ::Middleman::Deploy.options = options + end + end - module Helpers - def options - ::Middleman::Deploy.options - end - end end end diff --git a/lib/middleman-deploy/methods/base.rb b/lib/middleman-deploy/methods/base.rb index b8e7627..6e33cf3 100644 --- a/lib/middleman-deploy/methods/base.rb +++ b/lib/middleman-deploy/methods/base.rb @@ -9,6 +9,10 @@ module Middleman @server_instance = server_instance end + def build_dir + self.server_instance.config.setting(:build_dir).value + end + def process raise NotImplementedError end diff --git a/lib/middleman-deploy/methods/ftp.rb b/lib/middleman-deploy/methods/ftp.rb index a930e83..fc42d94 100644 --- a/lib/middleman-deploy/methods/ftp.rb +++ b/lib/middleman-deploy/methods/ftp.rb @@ -22,7 +22,7 @@ module Middleman ftp = open_connection - Dir.chdir(self.server_instance.build_dir) do + Dir.chdir(self.build_dir) do filtered_files.each do |filename| if File.directory?(filename) upload_directory(ftp, filename) diff --git a/lib/middleman-deploy/methods/git.rb b/lib/middleman-deploy/methods/git.rb index 990797e..99a0449 100644 --- a/lib/middleman-deploy/methods/git.rb +++ b/lib/middleman-deploy/methods/git.rb @@ -7,7 +7,7 @@ module Middleman camelized_strategy = self.options.strategy.to_s.split('_').map { |word| word.capitalize}.join strategy_class_name = "Middleman::Deploy::Strategies::Git::#{camelized_strategy}" - strategy_instance = strategy_class_name.constantize.new(self.server_instance.build_dir, self.options.remote, self.options.branch, self.options.commit_message) + strategy_instance = strategy_class_name.constantize.new(self.build_dir, self.options.remote, self.options.branch, self.options.commit_message) strategy_instance.process end diff --git a/lib/middleman-deploy/methods/rsync.rb b/lib/middleman-deploy/methods/rsync.rb index 6316b35..770c5a3 100644 --- a/lib/middleman-deploy/methods/rsync.rb +++ b/lib/middleman-deploy/methods/rsync.rb @@ -21,7 +21,7 @@ module Middleman dest_url = "#{user}#{self.host}:#{self.path}" flags = self.flags || '-avz' - command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.server_instance.build_dir}/ #{dest_url}" + command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.build_dir}/ #{dest_url}" if self.clean command += ' --delete' diff --git a/lib/middleman-deploy/methods/sftp.rb b/lib/middleman-deploy/methods/sftp.rb index 2db6522..7ed2afa 100644 --- a/lib/middleman-deploy/methods/sftp.rb +++ b/lib/middleman-deploy/methods/sftp.rb @@ -12,7 +12,7 @@ module Middleman Net::SFTP.start(self.host, self.user, password: self.pass, port: self.port) do |sftp| sftp.mkdir(self.path) - Dir.chdir(self.server_instance.build_dir) do + Dir.chdir(self.build_dir) do filtered_files.each do |filename| if File.directory?(filename) upload_directory(sftp, filename) From a8c6fdafefd9e3f2e02e8a9e8e97421623d6d669 Mon Sep 17 00:00:00 2001 From: Emilio Forrer Date: Sun, 22 Feb 2015 21:18:59 -0600 Subject: [PATCH 04/10] Fixing dependency error while activating asset_hash --- lib/middleman-deploy/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 549caab..7ae34fb 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -1,5 +1,5 @@ require 'middleman-core/cli' - +require 'middleman-core/rack' require 'middleman-deploy/pkg-info' require 'middleman-deploy/extension' require 'middleman-deploy/methods' From 1806c9263b6b22333f4e4d732ec2ad49aec924cc Mon Sep 17 00:00:00 2001 From: Emilio Forrer Date: Sun, 22 Feb 2015 21:56:53 -0600 Subject: [PATCH 05/10] Fixing dependency error while activating asset_hash and validated middleman version --- lib/middleman-deploy/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 7ae34fb..614d164 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -1,5 +1,5 @@ require 'middleman-core/cli' -require 'middleman-core/rack' +require 'middleman-core/rack' if Middleman::VERSION.to_i > 3 require 'middleman-deploy/pkg-info' require 'middleman-deploy/extension' require 'middleman-deploy/methods' From c590d005cf6e259ae829b9456de231da5ee65ec3 Mon Sep 17 00:00:00 2001 From: Emilio Forrer Date: Sun, 22 Feb 2015 22:09:54 -0600 Subject: [PATCH 06/10] Fixing cucumber failed test --- .ruby-gemset | 1 + .ruby-version | 1 + lib/middleman-deploy/extension.rb | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .ruby-gemset create mode 100644 .ruby-version diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..653cc35 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +rails4 diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..76521af --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.2.0 diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index c10606b..563a7bf 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -5,7 +5,19 @@ require 'middleman-core' module Middleman module Deploy - cattr_accessor :options + @options + + class << self + + def options + @options + end + + def options= options + @options = options + end + + end class Extension < Extension From 86f76b2a53b408487eb294c5462c31be0751232a Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Sun, 16 Aug 2015 19:06:10 +0100 Subject: [PATCH 07/10] tidy up --- .rubocop.yml | 23 ++++--------------- lib/middleman-deploy/commands.rb | 13 ++++------- lib/middleman-deploy/extension.rb | 19 +++------------ lib/middleman-deploy/methods/base.rb | 4 ++-- lib/middleman-deploy/methods/ftp.rb | 18 +++++++-------- lib/middleman-deploy/methods/git.rb | 6 ++--- lib/middleman-deploy/methods/rsync.rb | 12 ++++------ lib/middleman-deploy/methods/sftp.rb | 18 +++++++-------- lib/middleman-deploy/strategies/git/base.rb | 17 +++++++------- .../strategies/git/force_push.rb | 10 ++++---- .../strategies/git/submodule.rb | 10 ++++---- 11 files changed, 58 insertions(+), 92 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2ee0120..fb802f8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,24 +1,11 @@ AllCops: Include: - - Rakefile - - Gemfile + - 'Gemfile' Exclude: - - script/**/* - - vendor/**/* - - bin/**/* -LineLength: - Enabled: false -MethodLength: - Enabled: false -ClassLength: - Enabled: false + - 'script/**/*' + - 'vendor/**/*' + - 'bin/**/*' Documentation: Enabled: false -Encoding: +ClassAndModuleChildren: Enabled: false -Blocks: - Enabled: false -AlignParameters: - Enabled: false -HashSyntax: - EnforcedStyle: ruby19 \ No newline at end of file diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 614d164..c781949 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -35,7 +35,7 @@ module Middleman aliases: '-b', desc: 'Run `middleman build` before the deploy step' - def self.subcommand_help options + def self.subcommand_help(_options) # TODO end @@ -44,7 +44,6 @@ module Middleman true end - def deploy env = options['environment'] ? :production : options['environment'].to_s.to_sym verbose = options['verbose'] ? 0 : 1 @@ -62,7 +61,7 @@ module Middleman protected def build_before(options = {}) - build_enabled = options.fetch('build_before', self.deploy_options.build_before) + build_enabled = options.fetch('build_before', deploy_options.build_before) if build_enabled # http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension @@ -71,16 +70,14 @@ module Middleman end def print_usage_and_die(message) - raise StandardError, "ERROR: #{message}\n#{Middleman::Deploy::README}" + fail StandardError, "ERROR: #{message}\n#{Middleman::Deploy::README}" end - - def process server_instance = @app - camelized_method = self.deploy_options.deploy_method.to_s.split('_').map { |word| word.capitalize}.join + camelized_method = deploy_options.deploy_method.to_s.split('_').map(&:capitalize).join method_class_name = "Middleman::Deploy::Methods::#{camelized_method}" - method_instance = method_class_name.constantize.new(server_instance, self.deploy_options) + method_instance = method_class_name.constantize.new(server_instance, deploy_options) method_instance.process end diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 563a7bf..b7f59cb 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -4,23 +4,15 @@ require 'middleman-core' # Extension namespace module Middleman module Deploy - @options class << self + attr_reader :options - def options - @options - end - - def options= options - @options = options - end - + attr_writer :options end class Extension < Extension - option :deploy_method, nil option :host, nil option :port, nil @@ -35,8 +27,6 @@ module Middleman option :flags, nil option :commit_message, nil - - def initialize(app, options_hash = {}, &block) super @@ -50,17 +40,14 @@ module Middleman options.remote ||= 'origin' options.branch ||= 'gh-pages' options.strategy ||= :force_push - options.commit_message ||= nil + options.commit_message ||= nil options.build_before ||= false - end def after_configuration ::Middleman::Deploy.options = options end - end - end end diff --git a/lib/middleman-deploy/methods/base.rb b/lib/middleman-deploy/methods/base.rb index 6e33cf3..e4e2aae 100644 --- a/lib/middleman-deploy/methods/base.rb +++ b/lib/middleman-deploy/methods/base.rb @@ -10,11 +10,11 @@ module Middleman end def build_dir - self.server_instance.config.setting(:build_dir).value + server_instance.config.setting(:build_dir).value end def process - raise NotImplementedError + fail NotImplementedError end end end diff --git a/lib/middleman-deploy/methods/ftp.rb b/lib/middleman-deploy/methods/ftp.rb index fc42d94..619abe2 100644 --- a/lib/middleman-deploy/methods/ftp.rb +++ b/lib/middleman-deploy/methods/ftp.rb @@ -18,11 +18,11 @@ module Middleman end def process - puts "## Deploying via ftp to #{self.user}@#{self.host}:#{self.path}" + puts "## Deploying via ftp to #{user}@#{host}:#{path}" ftp = open_connection - Dir.chdir(self.build_dir) do + Dir.chdir(build_dir) do filtered_files.each do |filename| if File.directory?(filename) upload_directory(ftp, filename) @@ -57,9 +57,9 @@ module Middleman end def open_connection - ftp = Net::FTP.new(self.host) - ftp.login(self.user, self.pass) - ftp.chdir(self.path) + ftp = Net::FTP.new(host) + ftp.login(user, pass) + ftp.chdir(path) ftp.passive = true ftp @@ -76,11 +76,9 @@ module Middleman end def upload_directory(ftp, filename) - begin - ftp.mkdir(filename) - puts "Created directory #{filename}" - rescue - end + ftp.mkdir(filename) + puts "Created directory #{filename}" + rescue end end end diff --git a/lib/middleman-deploy/methods/git.rb b/lib/middleman-deploy/methods/git.rb index 99a0449..82bc2cc 100644 --- a/lib/middleman-deploy/methods/git.rb +++ b/lib/middleman-deploy/methods/git.rb @@ -3,11 +3,11 @@ module Middleman module Methods class Git < Base def process - puts "## Deploying via git to remote=\"#{self.options.remote}\" and branch=\"#{self.options.branch}\"" + puts "## Deploying via git to remote=\"#{options.remote}\" and branch=\"#{options.branch}\"" - camelized_strategy = self.options.strategy.to_s.split('_').map { |word| word.capitalize}.join + camelized_strategy = options.strategy.to_s.split('_').map(&:capitalize).join strategy_class_name = "Middleman::Deploy::Strategies::Git::#{camelized_strategy}" - strategy_instance = strategy_class_name.constantize.new(self.build_dir, self.options.remote, self.options.branch, self.options.commit_message) + strategy_instance = strategy_class_name.constantize.new(build_dir, options.remote, options.branch, options.commit_message) strategy_instance.process end diff --git a/lib/middleman-deploy/methods/rsync.rb b/lib/middleman-deploy/methods/rsync.rb index 770c5a3..dcc8abb 100644 --- a/lib/middleman-deploy/methods/rsync.rb +++ b/lib/middleman-deploy/methods/rsync.rb @@ -17,17 +17,15 @@ module Middleman def process # Append "@" to user if provided. - user = "#{self.user}@" if self.user && !self.user.empty? + user = "#{self.user}@" if user && !user.empty? - dest_url = "#{user}#{self.host}:#{self.path}" + dest_url = "#{user}#{host}:#{path}" flags = self.flags || '-avz' - command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.build_dir}/ #{dest_url}" + command = "rsync #{flags} '-e ssh -p #{port}' #{build_dir}/ #{dest_url}" - if self.clean - command += ' --delete' - end + command += ' --delete' if clean - puts "## Deploying via rsync to #{dest_url} port=#{self.port}" + puts "## Deploying via rsync to #{dest_url} port=#{port}" exec command end end diff --git a/lib/middleman-deploy/methods/sftp.rb b/lib/middleman-deploy/methods/sftp.rb index 7ed2afa..572c402 100644 --- a/lib/middleman-deploy/methods/sftp.rb +++ b/lib/middleman-deploy/methods/sftp.rb @@ -6,13 +6,13 @@ module Middleman module Methods class Sftp < Ftp def process - puts "## Deploying via sftp to #{self.user}@#{self.host}:#{path}" + puts "## Deploying via sftp to #{user}@#{host}:#{path}" # `nil` is a valid value for user and/or pass. - Net::SFTP.start(self.host, self.user, password: self.pass, port: self.port) do |sftp| - sftp.mkdir(self.path) + Net::SFTP.start(host, user, password: pass, port: port) do |sftp| + sftp.mkdir(path) - Dir.chdir(self.build_dir) do + Dir.chdir(build_dir) do filtered_files.each do |filename| if File.directory?(filename) upload_directory(sftp, filename) @@ -26,17 +26,15 @@ module Middleman protected - def handle_exception(exception,filename, file_path) + def handle_exception(exception, filename, file_path) reply = exception.message err_code = reply[0, 3].to_i - if err_code == 550 - sftp.upload(filename, file_path) - end + sftp.upload(filename, file_path) if err_code == 550 end def upload_directory(sftp, filename) - file_path = "#{self.path}/#{filename}" + file_path = "#{path}/#{filename}" begin sftp.mkdir(file_path) @@ -46,7 +44,7 @@ module Middleman end def upload_file(sftp, filename) - file_path = "#{self.path}/#{filename}" + file_path = "#{path}/#{filename}" begin sftp.upload(filename, file_path) diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb index 08a6d91..f0a667b 100644 --- a/lib/middleman-deploy/strategies/git/base.rb +++ b/lib/middleman-deploy/strategies/git/base.rb @@ -15,7 +15,7 @@ module Middleman end def process - raise NotImplementedError + fail NotImplementedError end protected @@ -29,24 +29,25 @@ module Middleman def checkout_branch # if there is a branch with that name, switch to it, otherwise create a new one and switch to it - if `git branch`.split("\n").any? { |b| b =~ /#{self.branch}/i } - `git checkout #{self.branch}` + if `git branch`.split("\n").any? { |b| b =~ /#{branch}/i } + `git checkout #{branch}` else - `git checkout -b #{self.branch}` + `git checkout -b #{branch}` end end def commit_branch(options = '') - message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit') + message = commit_message ? commit_message : add_signature_to_commit_message('Automated commit') - run_or_fail("git add -A") + run_or_fail('git add -A') run_or_fail("git commit --allow-empty -am \"#{message}\"") - run_or_fail("git push #{options} origin #{self.branch}") + run_or_fail("git push #{options} origin #{branch}") end private + def run_or_fail(command) - system(command) || raise("ERROR running: #{command}") + system(command) || fail("ERROR running: #{command}") end end end diff --git a/lib/middleman-deploy/strategies/git/force_push.rb b/lib/middleman-deploy/strategies/git/force_push.rb index 266cfe5..5c1348c 100644 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ b/lib/middleman-deploy/strategies/git/force_push.rb @@ -4,7 +4,7 @@ module Middleman module Git class ForcePush < Base def process - Dir.chdir(self.build_dir) do + Dir.chdir(build_dir) do add_remote_url checkout_branch commit_branch('-f') @@ -19,8 +19,8 @@ module Middleman unless File.exist?('.git') `git init` `git remote add origin #{url}` - `git config user.name "#{self.user_name}"` - `git config user.email "#{self.user_email}"` + `git config user.name "#{user_name}"` + `git config user.email "#{user_email}"` else # check if the remote repo has changed unless url == `git config --get remote.origin.url`.chop @@ -28,9 +28,9 @@ module Middleman `git remote add origin #{url}` end # check if the user name has changed - `git config user.name "#{self.user_name}"` unless self.user_name == `git config --get user.name` + `git config user.name "#{user_name}"` unless user_name == `git config --get user.name` # check if the user email has changed - `git config user.email "#{self.user_email}"` unless self.user_email == `git config --get user.email` + `git config user.email "#{user_email}"` unless user_email == `git config --get user.email` end end diff --git a/lib/middleman-deploy/strategies/git/submodule.rb b/lib/middleman-deploy/strategies/git/submodule.rb index 0b91712..e974226 100644 --- a/lib/middleman-deploy/strategies/git/submodule.rb +++ b/lib/middleman-deploy/strategies/git/submodule.rb @@ -4,7 +4,7 @@ module Middleman module Git class Submodule < Base def process - Dir.chdir(self.build_dir) do + Dir.chdir(build_dir) do checkout_branch pull_submodule commit_branch @@ -19,7 +19,7 @@ module Middleman current_branch = `git rev-parse --abbrev-ref HEAD` message = add_signature_to_commit_message('Deployed') - `git add #{self.build_dir}` + `git add #{build_dir}` `git commit --allow-empty -m "#{message}"` `git push origin #{current_branch}` end @@ -27,11 +27,11 @@ module Middleman def pull_submodule `git fetch` `git stash` - `git rebase #{self.remote}/#{self.branch}` + `git rebase #{remote}/#{branch}` `git stash pop` - if $?.exitstatus == 1 - puts "Can't deploy! Please resolve conflicts. Then process to manual commit and push on #{self.branch} branch." + if $CHILD_STATUS.exitstatus == 1 + puts "Can't deploy! Please resolve conflicts. Then process to manual commit and push on #{branch} branch." exit end end From 9cd8988a66829550fcbfbb90e306593d6ee9307d Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Sun, 16 Aug 2015 19:08:07 +0100 Subject: [PATCH 08/10] not needed --- .ruby-gemset | 1 - .ruby-version | 1 - 2 files changed, 2 deletions(-) delete mode 100644 .ruby-gemset delete mode 100644 .ruby-version diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 653cc35..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -rails4 diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 76521af..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-2.2.0 From 32d7897b6692f89c400e08a94427d6382afac324 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Sun, 16 Aug 2015 19:09:26 +0100 Subject: [PATCH 09/10] 2.0.0-alpha closes #93 --- lib/middleman-deploy/pkg-info.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index 528565f..bde3750 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,9 +1,9 @@ module Middleman module Deploy PACKAGE = 'middleman-deploy' - VERSION = '1.0.0' + VERSION = '2.0.0-alpha' TAGLINE = 'Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).' - README = %Q{ + README = %{ You should follow one of the four examples below to setup the deploy extension in config.rb. From 243ab38b08896cd5a37d6845a01a5761b934a898 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Sun, 16 Aug 2015 19:27:24 +0100 Subject: [PATCH 10/10] tidy up changelog [ci skip] --- CHANGELOG.md | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1bd4a..3ac195b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,12 @@ -master -=== +Next Release +============ +* Your contribution here. -1.0.0 -=== +2.0.0-alpha (02/08/2015) +================== +* [Fixing compatibility issues with middleman v4.0.0.beta.1](https://github.com/middleman-contrib/middleman-deploy/pull/87) - [@emilioforrer](https://github.com/emilioforrer). -* Respect user details of git repo. #70 -* Prevent bad commits deploying. (git) #77 - -development -=== - -2.0.0 -=== - -* Fixing compatibility issues with middleman v4.0.0.beta.1 +1.0.0 (16/07/2014) +================== +* [Respect user details of git repo](https://github.com/middleman-contrib/middleman-deploy/pull/70) - [@Gee-Bee](https://github.com/gee-bee). +* [Prevent bad commits deploying](https://github.com/middleman-contrib/middleman-deploy/pull/77) - [@karlfreeman](https://github.com/mconnell).