From da584981025cf3f9cbf6ce29c451e7041a4d4f81 Mon Sep 17 00:00:00 2001 From: Andrew Lum Date: Wed, 26 Feb 2014 19:04:08 +0800 Subject: [PATCH 01/28] Update rsync.rb --- lib/middleman-deploy/methods/rsync.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/methods/rsync.rb b/lib/middleman-deploy/methods/rsync.rb index c65454a..0704acd 100644 --- a/lib/middleman-deploy/methods/rsync.rb +++ b/lib/middleman-deploy/methods/rsync.rb @@ -29,7 +29,7 @@ module Middleman end puts "## Deploying via rsync to #{dest_url} port=#{self.port}" - run command + exec command end end From 6c426c0ef3e27405d36ea29885ec9c485e7ea2cd Mon Sep 17 00:00:00 2001 From: Tom Vaughan Date: Wed, 26 Feb 2014 08:39:50 -0300 Subject: [PATCH 02/28] bump --- lib/middleman-deploy/pkg-info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index 92babf5..c7440d0 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,7 +1,7 @@ module Middleman module Deploy PACKAGE = "middleman-deploy" - VERSION = "0.2.2" + VERSION = "0.2.3" TAGLINE = "Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github)." end end From 4fe452680711b2148f219ffbc8145ea1348d51f2 Mon Sep 17 00:00:00 2001 From: Jack Casey Date: Thu, 20 Mar 2014 23:10:03 +0800 Subject: [PATCH 03/28] Tiny change to README to suggest using 'system' over 'exec' Reason being, 'exec' will run the shell command and then exit the ruby process. While 'system will run the shell command and then continue execution. I feel this is a better example as the first thing I did was write a rake task that chains multiple tasks together and the way 'exec' was ending the process cost me a bit of time trouble shooting why. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d4c794..042691c 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ end namespace :deploy do def deploy(env) puts "Deploying to #{env}" - exec "TARGET=#{env} bundle exec middleman deploy" + system "TARGET=#{env} bundle exec middleman deploy" end task :staging do From efd66e7fcab1c9c3c0ddb09558f19811f05b2cae Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Sat, 24 May 2014 23:35:14 +0500 Subject: [PATCH 04/28] add ability to set custom commit message for git deploys issue #64 --- README.md | 1 + lib/middleman-deploy/extension.rb | 3 ++- lib/middleman-deploy/methods/git.rb | 2 +- lib/middleman-deploy/strategies/git/base.rb | 13 +++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 042691c..319b486 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ activate :deploy do |deploy| # deploy.remote = "custom-remote" # remote name or git url, default: origin # deploy.branch = "custom-branch" # default: gh-pages # deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule, default: :force_push + # deploy.commit_message = "custom-message" # commit message (can be empty), default: Automated commit at `timestamp` by middleman-deploy `version` end ``` diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 9882b06..58eaf3b 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(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags); end + class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message); end class << self @@ -25,6 +25,7 @@ module Middleman options.remote ||= "origin" options.branch ||= "gh-pages" options.strategy ||= :force_push + options.commit_message ||= nil options.build_before ||= false diff --git a/lib/middleman-deploy/methods/git.rb b/lib/middleman-deploy/methods/git.rb index b23627f..d772013 100644 --- a/lib/middleman-deploy/methods/git.rb +++ b/lib/middleman-deploy/methods/git.rb @@ -8,7 +8,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) + strategy_instance = strategy_class_name.constantize.new(self.server_instance.build_dir, self.options.remote, self.options.branch, self.options.commit_message) strategy_instance.process end diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb index 5304a92..cafce65 100644 --- a/lib/middleman-deploy/strategies/git/base.rb +++ b/lib/middleman-deploy/strategies/git/base.rb @@ -3,12 +3,13 @@ module Middleman module Strategies module Git class Base - attr_accessor :branch, :build_dir, :remote + attr_accessor :branch, :build_dir, :remote, :commit_message - def initialize(build_dir, remote, branch) - self.branch = branch - self.build_dir = build_dir - self.remote = remote + def initialize(build_dir, remote, branch, commit_message) + self.branch = branch + self.build_dir = build_dir + self.remote = remote + self.commit_message = commit_message end def process @@ -34,7 +35,7 @@ module Middleman end def commit_branch(options='') - message = add_signature_to_commit_message('Automated commit') + message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit') `git add -A` `git commit --allow-empty -am "#{message}"` From fa339eba4fd8dbcce9b9b33a8a32a966152432ec Mon Sep 17 00:00:00 2001 From: Tom Vaughan Date: Sat, 24 May 2014 15:19:25 -0400 Subject: [PATCH 05/28] Help! I need somebody! --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 319b486..e5bf216 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # middleman-deploy [![Gem Version](https://badge.fury.io/rb/middleman-deploy.png)](http://badge.fury.io/rb/middleman-deploy) +## Help! middleman-deploy needs a new maintainer. Please [create a GitHub issue](https://github.com/tvaughan/middleman-deploy/issues) if you're interested. Thanks! + Deploys a [middleman](http://middlemanapp.com/) built site via **rsync**, **ftp**, **sftp**, or **git** (e.g. gh-pages on github). From b8069d314450b21a2075607d0591679925027e00 Mon Sep 17 00:00:00 2001 From: Tom Vaughan Date: Sat, 24 May 2014 15:22:05 -0400 Subject: [PATCH 06/28] Help! I still need somebody! --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5bf216..5a1c397 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # middleman-deploy [![Gem Version](https://badge.fury.io/rb/middleman-deploy.png)](http://badge.fury.io/rb/middleman-deploy) -## Help! middleman-deploy needs a new maintainer. Please [create a GitHub issue](https://github.com/tvaughan/middleman-deploy/issues) if you're interested. Thanks! - Deploys a [middleman](http://middlemanapp.com/) built site via **rsync**, **ftp**, **sftp**, or **git** (e.g. gh-pages on github). +## Help! + +middleman-deploy needs a new maintainer. Please [create a GitHub issue](https://github.com/tvaughan/middleman-deploy/issues/new) if you're interested. Thanks! + ## Installation Add this to the Gemfile of the repository of your middleman site: From 71c4e6339b0141c5cee749e700d91b391c99d632 Mon Sep 17 00:00:00 2001 From: Tom Vaughan Date: Sun, 25 May 2014 02:07:26 -0400 Subject: [PATCH 07/28] Bump. --- lib/middleman-deploy/pkg-info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index c7440d0..2efbaa9 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,7 +1,7 @@ module Middleman module Deploy PACKAGE = "middleman-deploy" - VERSION = "0.2.3" + VERSION = "0.2.4" TAGLINE = "Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github)." end end From 84b3cb0121179bb13390bd17e9c70dd97f5dd6bf Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Wed, 28 May 2014 11:11:59 +0100 Subject: [PATCH 08/28] no longer needed :+1: --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 5a1c397..319b486 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,6 @@ Deploys a [middleman](http://middlemanapp.com/) built site via **rsync**, **ftp**, **sftp**, or **git** (e.g. gh-pages on github). -## Help! - -middleman-deploy needs a new maintainer. Please [create a GitHub issue](https://github.com/tvaughan/middleman-deploy/issues/new) if you're interested. Thanks! - ## Installation Add this to the Gemfile of the repository of your middleman site: From 4f9d4879d7d54c442c6cc02c5386adec1ed9e0f9 Mon Sep 17 00:00:00 2001 From: Gee-Bee Date: Wed, 16 Jul 2014 10:56:58 +0200 Subject: [PATCH 09/28] Respect user details of git repo. Branch with compiled pages respects repo's user details settings. --- lib/middleman-deploy/strategies/git/base.rb | 4 +++- lib/middleman-deploy/strategies/git/force_push.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb index cafce65..6e8dce8 100644 --- a/lib/middleman-deploy/strategies/git/base.rb +++ b/lib/middleman-deploy/strategies/git/base.rb @@ -3,13 +3,15 @@ module Middleman module Strategies module Git class Base - attr_accessor :branch, :build_dir, :remote, :commit_message + attr_accessor :branch, :build_dir, :remote, :commit_message, :user_name, :user_email def initialize(build_dir, remote, branch, commit_message) self.branch = branch self.build_dir = build_dir self.remote = remote self.commit_message = commit_message + self.user_name = `git config --get user.name` + self.user_email = `git config --get user.email` end def process diff --git a/lib/middleman-deploy/strategies/git/force_push.rb b/lib/middleman-deploy/strategies/git/force_push.rb index 786dacb..b74c061 100644 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ b/lib/middleman-deploy/strategies/git/force_push.rb @@ -20,12 +20,18 @@ module Middleman unless File.exists?('.git') `git init` `git remote add origin #{url}` + `git config user.name "#{self.user_name}"` + `git config user.name "#{self.user_email}"` else # check if the remote repo has changed unless url == `git config --get remote.origin.url`.chop `git remote rm origin` `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` + # check if the remote repo has changed + `git config user.email "#{self.user_email}"` unless self.user_email == `git config --get user.email` end end From bfe647300080ab341984012a1c9d72f03bcbcb29 Mon Sep 17 00:00:00 2001 From: Gee-Bee Date: Fri, 18 Jul 2014 09:35:27 +0200 Subject: [PATCH 10/28] Fix comment. --- 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 b74c061..286ee48 100644 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ b/lib/middleman-deploy/strategies/git/force_push.rb @@ -30,7 +30,7 @@ module Middleman end # check if the user name has changed `git config user.name "#{self.user_name}"` unless self.user_name == `git config --get user.name` - # check if the remote repo has changed + # check if the user email has changed `git config user.email "#{self.user_email}"` unless self.user_email == `git config --get user.email` end end From 2aba441a3093a658b4663e599b10b56d085bc6e0 Mon Sep 17 00:00:00 2001 From: "Larry Staton Jr." Date: Sun, 20 Jul 2014 18:11:30 -0400 Subject: [PATCH 11/28] Update sftp.rb Fix ArgumentError on exception. Line 55 had 2 arguments, but the `handle_exception` method in line 30 only required 1 argument. --- lib/middleman-deploy/methods/sftp.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/middleman-deploy/methods/sftp.rb b/lib/middleman-deploy/methods/sftp.rb index 1783e4a..1809c77 100644 --- a/lib/middleman-deploy/methods/sftp.rb +++ b/lib/middleman-deploy/methods/sftp.rb @@ -27,7 +27,7 @@ module Middleman protected - def handle_exception(exception) + def handle_exception(exception,filename, file_path) reply = exception.message err_code = reply[0,3].to_i @@ -52,7 +52,7 @@ module Middleman begin sftp.upload(filename, file_path) rescue Exception => exception - handle_exception(exception, file_path) + handle_exception(exception, filename, file_path) end puts "Copied #{filename}" From e14f90fe1df41437065e75195a2ac7481b0b15f6 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Thu, 29 May 2014 10:57:30 +0100 Subject: [PATCH 12/28] cleanup --- .document | 3 + .gitignore | 26 ++-- .rubocop.yml | 24 ++++ .travis.yml | 24 ++++ .yardopts | 6 + CONTRIBUTING.md | 44 +++++++ Gemfile | 18 +-- COPYING => LICENSE.md | 18 +-- README.md | 118 ++++++++++-------- Rakefile | 21 +++- USAGE | 56 --------- features/support/env.rb | 10 +- features/test.feature | 6 + fixtures/test-app/config.rb | 0 fixtures/test-app/source/index.html.erb | 1 + lib/middleman-deploy.rb | 6 +- lib/middleman-deploy/commands.rb | 36 +++--- lib/middleman-deploy/extension.rb | 18 ++- lib/middleman-deploy/methods/base.rb | 3 +- lib/middleman-deploy/methods/ftp.rb | 11 +- lib/middleman-deploy/methods/git.rb | 2 - lib/middleman-deploy/methods/rsync.rb | 6 +- lib/middleman-deploy/methods/sftp.rb | 9 +- lib/middleman-deploy/pkg-info.rb | 65 +++++++++- lib/middleman-deploy/strategies/git/base.rb | 5 +- .../strategies/git/force_push.rb | 6 +- .../strategies/git/submodule.rb | 4 +- lib/middleman_extension.rb | 2 +- middleman-deploy.gemspec | 49 ++++---- 29 files changed, 360 insertions(+), 237 deletions(-) create mode 100644 .document create mode 100644 .rubocop.yml create mode 100644 .travis.yml create mode 100644 .yardopts create mode 100644 CONTRIBUTING.md rename COPYING => LICENSE.md (52%) delete mode 100644 USAGE create mode 100644 features/test.feature create mode 100644 fixtures/test-app/config.rb create mode 100644 fixtures/test-app/source/index.html.erb diff --git a/.document b/.document new file mode 100644 index 0000000..c79f1f2 --- /dev/null +++ b/.document @@ -0,0 +1,3 @@ +LICENSE.md +README.md +lib/**/*.rb \ No newline at end of file diff --git a/.gitignore b/.gitignore index cedb34b..47c308e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,18 @@ -# Ignore bundler lock file -/Gemfile.lock - -# Ignore pkg folder -/pkg - -# Ignore coverage folder -/coverage +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp +bin \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..2ee0120 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,24 @@ +AllCops: + Include: + - Rakefile + - Gemfile + Exclude: + - script/**/* + - vendor/**/* + - bin/**/* +LineLength: + Enabled: false +MethodLength: + Enabled: false +ClassLength: + Enabled: false +Documentation: + Enabled: false +Encoding: + Enabled: false +Blocks: + Enabled: false +AlignParameters: + Enabled: false +HashSyntax: + EnforcedStyle: ruby19 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5f36108 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: ruby +cache: bundler +bundler_args: --without development +rvm: + - ruby-head + - ruby + - jruby-head + - jruby + - 2.1.0 + - 2.0.0 + - 1.9.3 + - rbx-2 +matrix: + fast_finish: true + allow_failures: + - rvm: ruby-head + - rvm: ruby + - rvm: jruby-head + - rvm: jruby + - rvm: rbx-2 +notifications: + email: false +env: + - CODECLIMATE_REPO_TOKEN=5eee8e8624962f963a52a1d2313dc7407e3b8006291e3704346c786642cc073b \ No newline at end of file diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..b95bfb1 --- /dev/null +++ b/.yardopts @@ -0,0 +1,6 @@ +--markup markdown +- +CHANGELOG.md +CONTRIBUTING.md +LICENSE.md +README.md \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..41890ea --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,44 @@ +## Contributing +In the spirit of [free software][free-sw], **everyone** is encouraged to help +improve this project. + +[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html + +Here are some ways *you* can contribute: + +* by using alpha, beta, and prerelease versions +* by reporting bugs +* by suggesting new features +* by writing or editing documentation +* by writing specifications +* by writing code (**no patch is too small**: fix typos, add comments, clean up + inconsistent whitespace) +* by refactoring code +* by closing [issues][] +* by reviewing patches + +[issues]: https://github.com/karlfreeman/middleman-deploy/issues + +## Submitting an Issue +We use the [GitHub issue tracker][issues] to track bugs and features. Before +submitting a bug report or feature request, check to make sure it hasn't +already been submitted. When submitting a bug report, please include a [Gist][] +that includes a stack trace and any details that may be necessary to reproduce +the bug, including your gem version, Ruby version, and operating system. +Ideally, a bug report should include a pull request with failing specs. + +[gist]: https://gist.github.com/ + +## Submitting a Pull Request +1. [Fork the repository.][fork] +2. [Create a topic branch.][branch] +3. Add specs for your unimplemented feature or bug fix. +4. Run `bundle exec rake cucumber`. If your specs pass, return to step 3. +5. Implement your feature or bug fix. +6. Run `bundle exec rake cucumber`. If your specs fail, return to step 5. +7. Add, commit, and push your changes. +9. [Submit a pull request.][pr] + +[fork]: http://help.github.com/fork-a-repo/ +[branch]: http://learn.github.com/p/branching.html +[pr]: http://help.github.com/send-pull-requests/ diff --git a/Gemfile b/Gemfile index ab9ed9d..21791c5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,11 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in middleman-deploy.gemspec gemspec -group :development do - gem "rake" - gem "rdoc" - gem "yard" -end - group :test do - gem "compass" - gem "cucumber" - gem "fivemat" - gem "aruba" - gem "rspec" - gem "simplecov" + gem 'rake', '~> 10.0' + gem 'cucumber', '~> 1.3' + gem 'aruba', '~> 0.5' + gem 'fivemat' + gem 'codeclimate-test-reporter' end diff --git a/COPYING b/LICENSE.md similarity index 52% rename from COPYING rename to LICENSE.md index 3f6427a..cdef21c 100644 --- a/COPYING +++ b/LICENSE.md @@ -1,4 +1,6 @@ -Copyright (c) 2012 Tom Vaughan +Copyright (c) 2012-2014 Tom Vaughan, Karl Freeman + +MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -8,13 +10,13 @@ distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 5a1c397..3783b7a 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,13 @@ -# middleman-deploy [![Gem Version](https://badge.fury.io/rb/middleman-deploy.png)](http://badge.fury.io/rb/middleman-deploy) +# Middleman Deploy -Deploys a [middleman](http://middlemanapp.com/) built site via **rsync**, -**ftp**, **sftp**, or **git** (e.g. gh-pages on github). - -## Help! - -middleman-deploy needs a new maintainer. Please [create a GitHub issue](https://github.com/tvaughan/middleman-deploy/issues/new) if you're interested. Thanks! +Deploy your [Middleman](http://middlemanapp.com/) build via **rsync**, **ftp**, **sftp**, or **git** (e.g. [gh-pages on github](https://help.github.com/articles/creating-project-pages-manually)). ## Installation -Add this to the Gemfile of the repository of your middleman site: - ```ruby -gem "middleman-deploy" +gem 'middleman-deploy', '~> 2.5' ``` -and run `bundle install`. - ## Usage ``` @@ -24,23 +15,11 @@ $ middleman build [--clean] $ middleman deploy [--build-before] ``` -To automatically run `middleman build` during `middleman deploy`, turn on the -`build_before` option while activating the deploy extension: - -```ruby -activate :deploy do |deploy| - # ... - deploy.build_before = true # default: false -end -``` - ## Possible Configurations -Middleman-deploy can deploy a site via rsync, ftp, sftp, or git. +Middleman-deploy can deploy a site via rsync, ftp, sftp, or git. Checkout [the wiki](https://github.com/tvaughan/middleman-deploy/wiki/_pages) for advanced set-up options. -Checkout [the wiki](https://github.com/tvaughan/middleman-deploy/wiki/_pages) for advanced set-up options. - -### rsync +### Rsync Make sure that `rsync` is installed, and activate the extension by adding the following to `config.rb`: @@ -48,13 +27,13 @@ following to `config.rb`: ```ruby activate :deploy do |deploy| deploy.method = :rsync - deploy.host = "www.example.com" - deploy.path = "/srv/www/site" + deploy.host = 'www.example.com' + deploy.path = '/srv/www/site' # Optional Settings - # deploy.user = "tvaughan" # no default + # deploy.user = 'tvaughan' # no default # deploy.port = 5309 # ssh port, default: 22 # deploy.clean = true # remove orphaned files on remote host, default: false - # deploy.flags = "-rltgoDvzO --no-p --del" # add custom flags, default: -avz + # deploy.flags = '-rltgoDvzO --no-p --del' # add custom flags, default: -avz end ``` @@ -67,10 +46,10 @@ following to `config.rb`: activate :deploy do |deploy| deploy.method = :git # Optional Settings - # deploy.remote = "custom-remote" # remote name or git url, default: origin - # deploy.branch = "custom-branch" # default: gh-pages + # deploy.remote = 'custom-remote' # remote name or git url, default: origin + # deploy.branch = 'custom-branch' # default: gh-pages # deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule, default: :force_push - # deploy.commit_message = "custom-message" # commit message (can be empty), default: Automated commit at `timestamp` by middleman-deploy `version` + # deploy.commit_message = 'custom-message' # commit message (can be empty), default: Automated commit at `timestamp` by middleman-deploy `version` end ``` @@ -92,10 +71,10 @@ 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.host = 'ftp.example.com' + deploy.path = '/srv/www/site' + deploy.user = 'tvaughan' + deploy.password = 'secret' end ``` @@ -106,12 +85,24 @@ Activate the extension by adding the following to `config.rb`: ```ruby activate :deploy do |deploy| deploy.method = :sftp - deploy.host = "sftp.example.com" + deploy.host = 'sftp.example.com' deploy.port = 22 - deploy.path = "/srv/www/site" + deploy.path = '/srv/www/site' # Optional Settings - # deploy.user = "tvaughan" # no default - # deploy.password = "secret" # no default + # deploy.user = 'tvaughan' # no default + # deploy.password = 'secret' # no default +end +``` + +### Run Automatically + +To automatically run `middleman build` during `middleman deploy`, turn on the +`build_before` option while activating the deploy extension: + +```ruby +activate :deploy do |deploy| + # ... + deploy.build_before = true # default: false end ``` @@ -125,14 +116,14 @@ 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.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.host = 'staging.example.com' + deploy.path = '/srv/www/staging-site' end end ``` @@ -170,13 +161,38 @@ end sense. `deploy` was added to the `after_build` hook simply because it was available. +## Badges + +[![Gem Version](http://img.shields.io/gem/v/middleman-deploy.svg)][gem] +[![Build Status](http://img.shields.io/travis/karlfreeman/middleman-deploy.svg)][travis] +[![Code Quality](http://img.shields.io/codeclimate/github/karlfreeman/middleman-deploy.svg)][codeclimate] +[![Code Coverage](http://img.shields.io/codeclimate/coverage/github/karlfreeman/middleman-deploy.svg)][codeclimate] +[![Gittip](http://img.shields.io/gittip/karlfreeman.svg)][gittip] + +## Supported Ruby Versions + +This library aims to support and is [tested against][travis] the following Ruby +implementations: + +- Ruby 2.1.0 +- Ruby 2.0.0 +- Ruby 1.9.3 +- [JRuby][jruby] +- [Rubinius][rubinius] + ## Thanks! -A **BIG** thanks to -[everyone who has contributed](https://github.com/tvaughan/middleman-deploy/graphs/contributors)! -Almost all pull requests are accepted. +A **BIG** thanks to [everyone who has contributed](https://github.com/tvaughan/middleman-deploy/graphs/contributors)! Almost all pull requests are accepted. -## Other +# Credits -Inspired by the rsync task in -[Octopress](https://github.com/imathis/octopress). +Inspiration: + +- The rsync task in [Octopress](https://github.com/imathis/octopress) + +[gem]: https://rubygems.org/gems/middleman-deploy +[travis]: http://travis-ci.org/karlfreeman/middleman-deploy +[codeclimate]: https://codeclimate.com/github/karlfreeman/middleman-deploy +[gittip]: https://www.gittip.com/karlfreeman +[jruby]: http://www.jruby.org +[rubinius]: http://rubini.us diff --git a/Rakefile b/Rakefile index a211efa..2079321 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,25 @@ require 'bundler' +Bundler.setup Bundler::GemHelper.install_tasks require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| - t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" + exempt_tags = ['--tags ~@wip'] + t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" end -require 'rake/clean' +begin + require 'yard' + YARD::Rake::YardocTask.new +rescue LoadError +end -task :test => ["cucumber"] +begin + require 'rubocop/rake_task' + desc 'Run rubocop' + Rubocop::RakeTask.new(:rubocop) +rescue LoadError +end -task :default => :test \ No newline at end of file +task default: :cucumber +task test: :cucumber diff --git a/USAGE b/USAGE deleted file mode 100644 index c2f49ab..0000000 --- a/USAGE +++ /dev/null @@ -1,56 +0,0 @@ -You should follow one of the four examples below to setup the deploy -extension in config.rb. - -# To deploy the build directory to a remote host via rsync: -activate :deploy do |deploy| - deploy.method = :rsync - # host and path *must* be set - deploy.host = "www.example.com" - deploy.path = "/srv/www/site" - # user is optional (no default) - deploy.user = "tvaughan" - # port is optional (default is 22) - deploy.port = 5309 - # clean is optional (default is false) - deploy.clean = true - # flags is optional (default is -avze) - deploy.flags = "-rltgoDvzO --no-p --del -e" -end - -# To deploy to a remote branch via git (e.g. gh-pages on github): -activate :deploy do |deploy| - deploy.method = :git - # remote is optional (default is "origin") - # run `git remote -v` to see a list of possible remotes - deploy.remote = "some-other-remote-name" - - # branch is optional (default is "gh-pages") - # run `git branch -a` to see a list of possible branches - deploy.branch = "some-other-branch-name" - - # strategy is optional (default is :force_push) - deploy.strategy = :submodule -end - -# To deploy the build directory to a remote host via ftp: -activate :deploy do |deploy| - deploy.method = :ftp - # host, user, passwword and path *must* be set - deploy.host = "ftp.example.com" - deploy.path = "/srv/www/site" - deploy.user = "tvaughan" - deploy.password = "secret" -end - -# To deploy the build directory to a remote host via sftp: -activate :deploy do |deploy| - deploy.method = :sftp - # host, user, passwword and path *must* be set - deploy.host = "sftp.example.com" - deploy.port = 22 - deploy.path = "/srv/www/site" - # user is optional (no default) - deploy.user = "tvaughan" - # password is optional (no default) - deploy.password = "secret" -end diff --git a/features/support/env.rb b/features/support/env.rb index 3352ebf..41f7c3f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,6 +1,8 @@ -require "simplecov" -SimpleCov.start PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__))) -require "middleman-core" -require "middleman-core/step_definitions" +require 'middleman-core' +require 'middleman-core/step_definitions' + +require 'codeclimate-test-reporter' +CodeClimate::TestReporter.start + require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-deploy') diff --git a/features/test.feature b/features/test.feature new file mode 100644 index 0000000..77daad0 --- /dev/null +++ b/features/test.feature @@ -0,0 +1,6 @@ +Feature: test + + Scenario: whilst testing + Given the Server is running at "test-app" + When I go to "/index.html" + Then I should see "

Test

" \ No newline at end of file diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb new file mode 100644 index 0000000..e69de29 diff --git a/fixtures/test-app/source/index.html.erb b/fixtures/test-app/source/index.html.erb new file mode 100644 index 0000000..d87d360 --- /dev/null +++ b/fixtures/test-app/source/index.html.erb @@ -0,0 +1 @@ +

Test

\ No newline at end of file diff --git a/lib/middleman-deploy.rb b/lib/middleman-deploy.rb index 78b96d4..796f4ca 100644 --- a/lib/middleman-deploy.rb +++ b/lib/middleman-deploy.rb @@ -1,8 +1,8 @@ -require "middleman-core" +require 'middleman-core' -require "middleman-deploy/commands" +require 'middleman-deploy/commands' ::Middleman::Extensions.register(:deploy) do - require "middleman-deploy/extension" + require 'middleman-deploy/extension' ::Middleman::Deploy end diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 4f274a3..345615a 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -1,13 +1,12 @@ -require "middleman-core/cli" +require 'middleman-core/cli' -require "middleman-deploy/extension" -require "middleman-deploy/methods" -require "middleman-deploy/strategies" -require "middleman-deploy/pkg-info" +require 'middleman-deploy/pkg-info' +require 'middleman-deploy/extension' +require 'middleman-deploy/methods' +require 'middleman-deploy/strategies' module Middleman module Cli - # This class provides a "deploy" command for the middleman CLI. class Deploy < Thor include Thor::Actions @@ -21,11 +20,11 @@ module Middleman true end - desc "deploy [options]", Middleman::Deploy::TAGLINE - method_option "build_before", - :type => :boolean, - :aliases => "-b", - :desc => "Run `middleman build` before the deploy step" + desc 'deploy [options]', Middleman::Deploy::TAGLINE + method_option 'build_before', + type: :boolean, + aliases: '-b', + desc: 'Run `middleman build` before the deploy step' def deploy build_before(options) process @@ -33,7 +32,7 @@ module Middleman protected - def build_before(options={}) + def build_before(options = {}) build_enabled = options.fetch('build_before', self.deploy_options.build_before) if build_enabled @@ -43,10 +42,7 @@ module Middleman end def print_usage_and_die(message) - usage_path = File.join(File.dirname(__FILE__), '..', '..', 'USAGE') - usage_message = File.read(usage_path) - - raise Error, "ERROR: #{message}\n#{usage_message}" + raise Error, "ERROR: #{message}\n#{Middleman::Deploy::README}" end def process @@ -65,11 +61,11 @@ module Middleman begin options = ::Middleman::Application.server.inst.options rescue NoMethodError - print_usage_and_die "You need to activate the deploy extension in config.rb." + print_usage_and_die 'You need to activate the deploy extension in config.rb.' end unless options.method - print_usage_and_die "The deploy extension requires you to set a method." + print_usage_and_die 'The deploy extension requires you to set a method.' end case options.method @@ -79,7 +75,7 @@ module Middleman end when :ftp unless options.host && options.user && options.password && options.path - print_usage_and_die "The ftp deploy method requires host, path, user, and password to be set." + print_usage_and_die 'The ftp deploy method requires host, path, user, and password to be set.' end end @@ -88,6 +84,6 @@ module Middleman end # Alias "d" to "deploy" - Base.map({ "d" => "deploy" }) + Base.map('d' => 'deploy') end end diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 58eaf3b..8ad1e16 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -1,19 +1,17 @@ # Require core library -require "middleman-core" +require 'middleman-core' # Extension namespace module Middleman module Deploy - - class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message); end + 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 - def registered(app, options_hash={}, &block) + def registered(app, options_hash = {}, &block) options = Options.new(options_hash) yield options if block_given? @@ -22,9 +20,9 @@ module Middleman options.clean ||= false # Default options for the git method. - options.remote ||= "origin" - options.branch ||= "gh-pages" - options.strategy ||= :force_push + options.remote ||= 'origin' + options.branch ||= 'gh-pages' + options.strategy ||= :force_push options.commit_message ||= nil options.build_before ||= false @@ -34,8 +32,7 @@ module Middleman app.send :include, Helpers end - alias :included :registered - + alias_method :included, :registered end module Helpers @@ -43,6 +40,5 @@ module Middleman ::Middleman::Deploy.options end end - end end diff --git a/lib/middleman-deploy/methods/base.rb b/lib/middleman-deploy/methods/base.rb index 982d5f2..b8e7627 100644 --- a/lib/middleman-deploy/methods/base.rb +++ b/lib/middleman-deploy/methods/base.rb @@ -4,7 +4,7 @@ module Middleman class Base attr_reader :options, :server_instance - def initialize(server_instance, options={}) + def initialize(server_instance, options = {}) @options = options @server_instance = server_instance end @@ -12,7 +12,6 @@ module Middleman def process raise NotImplementedError end - end end end diff --git a/lib/middleman-deploy/methods/ftp.rb b/lib/middleman-deploy/methods/ftp.rb index e2bba10..a930e83 100644 --- a/lib/middleman-deploy/methods/ftp.rb +++ b/lib/middleman-deploy/methods/ftp.rb @@ -5,10 +5,9 @@ module Middleman module Deploy module Methods class Ftp < Base - attr_reader :host, :port, :pass, :path, :user - def initialize(server_instance, options={}) + def initialize(server_instance, options = {}) super(server_instance, options) @host = self.options.host @@ -27,7 +26,7 @@ module Middleman filtered_files.each do |filename| if File.directory?(filename) upload_directory(ftp, filename) - else + else upload_binary(ftp, filename) end end @@ -36,7 +35,7 @@ module Middleman ftp.close end - protected + protected def filtered_files files = Dir.glob('**/*', File::FNM_DOTMATCH) @@ -46,7 +45,7 @@ module Middleman def handle_exception(exception, ftp, filename) reply = exception.message - err_code = reply[0,3].to_i + err_code = reply[0, 3].to_i if err_code == 550 if File.binary?(filename) @@ -83,8 +82,6 @@ module Middleman rescue end end - - end end end diff --git a/lib/middleman-deploy/methods/git.rb b/lib/middleman-deploy/methods/git.rb index d772013..990797e 100644 --- a/lib/middleman-deploy/methods/git.rb +++ b/lib/middleman-deploy/methods/git.rb @@ -2,7 +2,6 @@ module Middleman module Deploy module Methods class Git < Base - def process puts "## Deploying via git to remote=\"#{self.options.remote}\" and branch=\"#{self.options.branch}\"" @@ -12,7 +11,6 @@ module Middleman strategy_instance.process end - end end end diff --git a/lib/middleman-deploy/methods/rsync.rb b/lib/middleman-deploy/methods/rsync.rb index 0704acd..6316b35 100644 --- a/lib/middleman-deploy/methods/rsync.rb +++ b/lib/middleman-deploy/methods/rsync.rb @@ -2,10 +2,9 @@ module Middleman module Deploy module Methods class Rsync < Base - attr_reader :clean, :flags, :host, :path, :port, :user - def initialize(server_instance, options={}) + def initialize(server_instance, options = {}) super(server_instance, options) @clean = self.options.clean @@ -25,13 +24,12 @@ module Middleman command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.server_instance.build_dir}/ #{dest_url}" if self.clean - command += " --delete" + command += ' --delete' end puts "## Deploying via rsync to #{dest_url} port=#{self.port}" exec command end - end end end diff --git a/lib/middleman-deploy/methods/sftp.rb b/lib/middleman-deploy/methods/sftp.rb index 1783e4a..50b219e 100644 --- a/lib/middleman-deploy/methods/sftp.rb +++ b/lib/middleman-deploy/methods/sftp.rb @@ -5,12 +5,11 @@ module Middleman module Deploy module Methods class Sftp < Ftp - def process puts "## Deploying via sftp to #{self.user}@#{self.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| + 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 @@ -25,11 +24,11 @@ module Middleman end end - protected + protected def handle_exception(exception) reply = exception.message - err_code = reply[0,3].to_i + err_code = reply[0, 3].to_i if err_code == 550 sftp.upload(filename, file_path) @@ -57,9 +56,7 @@ module Middleman puts "Copied #{filename}" end - end end end end - diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index 2efbaa9..f78e2c7 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,7 +1,64 @@ module Middleman module Deploy - PACKAGE = "middleman-deploy" - VERSION = "0.2.4" - TAGLINE = "Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github)." - end + PACKAGE = 'middleman-deploy' + VERSION = '0.2.5' + TAGLINE = 'Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).' + README = %Q{ +You should follow one of the four examples below to setup the deploy +extension in config.rb. + +# To deploy the build directory to a remote host via rsync: +activate :deploy do |deploy| + deploy.method = :rsync + # host and path *must* be set + deploy.host = "www.example.com" + deploy.path = "/srv/www/site" + # user is optional (no default) + deploy.user = "tvaughan" + # port is optional (default is 22) + deploy.port = 5309 + # clean is optional (default is false) + deploy.clean = true + # flags is optional (default is -avze) + deploy.flags = "-rltgoDvzO --no-p --del -e" end + +# To deploy to a remote branch via git (e.g. gh-pages on github): +activate :deploy do |deploy| + deploy.method = :git + # remote is optional (default is "origin") + # run `git remote -v` to see a list of possible remotes + deploy.remote = "some-other-remote-name" + + # branch is optional (default is "gh-pages") + # run `git branch -a` to see a list of possible branches + deploy.branch = "some-other-branch-name" + + # strategy is optional (default is :force_push) + deploy.strategy = :submodule +end + +# To deploy the build directory to a remote host via ftp: +activate :deploy do |deploy| + deploy.method = :ftp + # host, user, passwword and path *must* be set + deploy.host = "ftp.example.com" + deploy.path = "/srv/www/site" + deploy.user = "tvaughan" + deploy.password = "secret" +end + +# To deploy the build directory to a remote host via sftp: +activate :deploy do |deploy| + deploy.method = :sftp + # host, user, passwword and path *must* be set + deploy.host = "sftp.example.com" + deploy.port = 22 + deploy.path = "/srv/www/site" + # user is optional (no default) + deploy.user = "tvaughan" + # password is optional (no default) + deploy.password = "secret" +end} + end +end \ No newline at end of file diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb index cafce65..2073969 100644 --- a/lib/middleman-deploy/strategies/git/base.rb +++ b/lib/middleman-deploy/strategies/git/base.rb @@ -16,7 +16,7 @@ module Middleman raise NotImplementedError end - protected + protected def add_signature_to_commit_message(base_message) signature = "#{Middleman::Deploy::PACKAGE} #{Middleman::Deploy::VERSION}" @@ -34,14 +34,13 @@ module Middleman end end - def commit_branch(options='') + def commit_branch(options = '') message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit') `git add -A` `git commit --allow-empty -am "#{message}"` `git push #{options} origin #{self.branch}` end - end end end diff --git a/lib/middleman-deploy/strategies/git/force_push.rb b/lib/middleman-deploy/strategies/git/force_push.rb index 786dacb..d8488b9 100644 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ b/lib/middleman-deploy/strategies/git/force_push.rb @@ -3,7 +3,6 @@ module Middleman module Strategies module Git class ForcePush < Base - def process Dir.chdir(self.build_dir) do add_remote_url @@ -12,12 +11,12 @@ module Middleman end end - private + private def add_remote_url url = get_remote_url - unless File.exists?('.git') + unless File.exist?('.git') `git init` `git remote add origin #{url}` else @@ -46,7 +45,6 @@ module Middleman url end - end end end diff --git a/lib/middleman-deploy/strategies/git/submodule.rb b/lib/middleman-deploy/strategies/git/submodule.rb index 39ee75f..0b91712 100644 --- a/lib/middleman-deploy/strategies/git/submodule.rb +++ b/lib/middleman-deploy/strategies/git/submodule.rb @@ -3,7 +3,6 @@ module Middleman module Strategies module Git class Submodule < Base - def process Dir.chdir(self.build_dir) do checkout_branch @@ -14,7 +13,7 @@ module Middleman commit_submodule end - private + private def commit_submodule current_branch = `git rev-parse --abbrev-ref HEAD` @@ -36,7 +35,6 @@ module Middleman exit end end - end end end diff --git a/lib/middleman_extension.rb b/lib/middleman_extension.rb index 233dc74..c810845 100644 --- a/lib/middleman_extension.rb +++ b/lib/middleman_extension.rb @@ -1 +1 @@ -require "middleman-deploy" \ No newline at end of file +require 'middleman-deploy' diff --git a/middleman-deploy.gemspec b/middleman-deploy.gemspec index 6695512..1c50a7c 100644 --- a/middleman-deploy.gemspec +++ b/middleman-deploy.gemspec @@ -1,27 +1,32 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "middleman-deploy/pkg-info" +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'middleman-deploy/pkg-info' -Gem::Specification.new do |s| - s.name = Middleman::Deploy::PACKAGE - s.version = Middleman::Deploy::VERSION - s.platform = Gem::Platform::RUBY - s.authors = ["Tom Vaughan"] - s.email = ["thomas.david.vaughan@gmail.com"] - s.homepage = "http://github.com/tvaughan/middleman-deploy" - s.summary = Middleman::Deploy::TAGLINE - s.description = Middleman::Deploy::TAGLINE - s.license = "MIT" +Gem::Specification.new do |spec| + spec.name = Middleman::Deploy::PACKAGE + spec.version = Middleman::Deploy::VERSION + spec.authors = ['Tom Vaughan', 'Karl Freeman'] + spec.email = ['thomas.david.vaughan@gmail.com', 'karlfreeman@gmail.com'] + spec.summary = Middleman::Deploy::TAGLINE + spec.description = Middleman::Deploy::TAGLINE + spec.homepage = 'https://github.com/karlfreeman/middleman-deploy' + spec.license = 'MIT' - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + spec.files = `git ls-files -z`.split("\x0") + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ['lib'] + spec.required_ruby_version = '>= 1.9.3' - # The version of middleman-core your extension depends on - s.add_runtime_dependency("middleman-core", [">= 3.0.0"]) + spec.add_dependency 'middleman-core', '>= 3.2' + spec.add_dependency 'ptools' + spec.add_dependency 'net-sftp' - # Additional dependencies - s.add_runtime_dependency("ptools") - s.add_runtime_dependency("net-sftp") + spec.add_development_dependency 'bundler', '~> 1.5' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'kramdown', '>= 0.14' + spec.add_development_dependency 'rubocop', '~> 0.19' + spec.add_development_dependency 'pry' + spec.add_development_dependency 'yard' end From 70863dc3122808505545abca614976865a36d78c Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Thu, 14 Aug 2014 11:34:48 +0100 Subject: [PATCH 13/28] bump --- README.md | 2 +- lib/middleman-deploy/pkg-info.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3783b7a..365b30b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Deploy your [Middleman](http://middlemanapp.com/) build via **rsync**, **ftp**, ## Installation ```ruby -gem 'middleman-deploy', '~> 2.5' +gem 'middleman-deploy', '~> 3.0' ``` ## Usage diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index f78e2c7..fc3e857 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,7 +1,7 @@ module Middleman module Deploy PACKAGE = 'middleman-deploy' - VERSION = '0.2.5' + VERSION = '0.3.0' TAGLINE = 'Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).' README = %Q{ You should follow one of the four examples below to setup the deploy From 546542032f0a982e3b360fc6287bf074d4d74c1d Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Thu, 14 Aug 2014 11:38:48 +0100 Subject: [PATCH 14/28] changelog --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 365b30b..124f1e0 100644 --- a/README.md +++ b/README.md @@ -146,11 +146,15 @@ namespace :deploy do end ``` - $ rake deploy:staging - $ rake deploy:production +``` +$ rake deploy:staging +$ rake deploy:production +``` ## Breaking Changes +* `v0.3.0` + - Ruby 1.9.3+ support only * `v0.1.0` - Removed the `--clean` command-line option. This option only applied to the rsync deploy method. The idea going forward is that command-line From c4667462664fac2bd2684178fcb3c943520b6814 Mon Sep 17 00:00:00 2001 From: Philipp Bosch Date: Tue, 19 Aug 2014 16:12:24 +0200 Subject: [PATCH 15/28] Fix version number in installation instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 124f1e0..fcbb7ba 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Deploy your [Middleman](http://middlemanapp.com/) build via **rsync**, **ftp**, ## Installation ```ruby -gem 'middleman-deploy', '~> 3.0' +gem 'middleman-deploy', '~> 0.3.0' ``` ## Usage From 79d86af7be42995f32c59657696022e27a81e0dc Mon Sep 17 00:00:00 2001 From: Mark Connell Date: Thu, 4 Sep 2014 11:25:57 +0100 Subject: [PATCH 16/28] Prevent bad commits deploying. In the event of a fatal error occuring when trying to add content to git for commit, you end up pushing a blank commit to the git respository. This is a change which halts the push to a git repository so you don't accidentally take down your website. --- lib/middleman-deploy/strategies/git/base.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb index 2073969..f1151c1 100644 --- a/lib/middleman-deploy/strategies/git/base.rb +++ b/lib/middleman-deploy/strategies/git/base.rb @@ -37,9 +37,14 @@ module Middleman def commit_branch(options = '') message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit') - `git add -A` - `git commit --allow-empty -am "#{message}"` - `git push #{options} origin #{self.branch}` + run_or_fail("git add -A") + run_or_fail("git commit --allow-empty -am \"#{message}\"") + run_or_fail("git push #{options} origin #{self.branch}") + end + + private + def run_or_fail(command) + system(command) || raise("ERROR running: #{command}") end end end From 8a0bfaec2bc1da93f18ddc4803440b4e68a2baf4 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Fri, 21 Nov 2014 17:00:23 +0000 Subject: [PATCH 17/28] RuboCop --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 2079321..bd08477 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ end begin require 'rubocop/rake_task' desc 'Run rubocop' - Rubocop::RakeTask.new(:rubocop) + RuboCop::RakeTask.new(:rubocop) rescue LoadError end From 7360fcadc4b5ec36b9e6032e232544aa94e7fc30 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Fri, 21 Nov 2014 17:25:01 +0000 Subject: [PATCH 18/28] 1.0 --- CHANGELOG.md | 8 ++++++++ README.md | 22 +++------------------- lib/middleman-deploy/pkg-info.rb | 4 ++-- 3 files changed, 13 insertions(+), 21 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..48f652d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +master +=== + +1.0.0 +=== + +* Respect user details of git repo. #70 +* Prevent bad commits deploying. (git) #77 diff --git a/README.md b/README.md index fcbb7ba..6ddd1e4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Deploy your [Middleman](http://middlemanapp.com/) build via **rsync**, **ftp**, ## Installation ```ruby -gem 'middleman-deploy', '~> 0.3.0' +gem 'middleman-deploy', '~> 1.0' ``` ## Usage @@ -151,20 +151,6 @@ $ rake deploy:staging $ rake deploy:production ``` -## Breaking Changes - -* `v0.3.0` - - Ruby 1.9.3+ support only -* `v0.1.0` - - Removed the `--clean` command-line option. This option only applied to - the rsync deploy method. The idea going forward is that command-line - options must apply to all deploy methods. Options that are specific to a - deploy method will only be available in `config.rb`. - - Removed `deploy` from the `after_build` hook. This caused a `deploy` to - be run each time `build` was called. This workflow never made - sense. `deploy` was added to the `after_build` hook simply because it - was available. - ## Badges [![Gem Version](http://img.shields.io/gem/v/middleman-deploy.svg)][gem] @@ -184,12 +170,10 @@ implementations: - [JRuby][jruby] - [Rubinius][rubinius] -## Thanks! - -A **BIG** thanks to [everyone who has contributed](https://github.com/tvaughan/middleman-deploy/graphs/contributors)! Almost all pull requests are accepted. - # Credits +A **BIG** thanks to [everyone who has contributed](https://github.com/karlfreeman/middleman-deploy/graphs/contributors)! Almost all pull requests are accepted. + Inspiration: - The rsync task in [Octopress](https://github.com/imathis/octopress) diff --git a/lib/middleman-deploy/pkg-info.rb b/lib/middleman-deploy/pkg-info.rb index fc3e857..528565f 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,7 +1,7 @@ module Middleman module Deploy PACKAGE = 'middleman-deploy' - VERSION = '0.3.0' + VERSION = '1.0.0' TAGLINE = 'Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).' README = %Q{ You should follow one of the four examples below to setup the deploy @@ -61,4 +61,4 @@ activate :deploy do |deploy| deploy.password = "secret" end} end -end \ No newline at end of file +end From 21d04f253acbdff7fa5684369db9b7ce56ed5330 Mon Sep 17 00:00:00 2001 From: Karl Freeman Date: Fri, 21 Nov 2014 18:25:10 +0000 Subject: [PATCH 19/28] 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 20/28] 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 21/28] 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 22/28] 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 23/28] 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 24/28] 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 25/28] 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 26/28] 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 27/28] 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 28/28] 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).