diff --git a/.document b/.document deleted file mode 100644 index c79f1f2..0000000 --- a/.document +++ /dev/null @@ -1,3 +0,0 @@ -LICENSE.md -README.md -lib/**/*.rb \ No newline at end of file diff --git a/.gitignore b/.gitignore index 47c308e..b844b14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1 @@ -*.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 deleted file mode 100644 index fb802f8..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,11 +0,0 @@ -AllCops: - Include: - - 'Gemfile' - Exclude: - - 'script/**/*' - - 'vendor/**/*' - - 'bin/**/*' -Documentation: - Enabled: false -ClassAndModuleChildren: - Enabled: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c3e0bfc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: ruby -sudo: false -cache: bundler -bundler_args: --without development -rvm: - - ruby-head - - ruby - - jruby-head - - jruby - - 2.1.0 - - 2.0.0 - - 1.9.3 - - rbx-2 -before_script: bundle update -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 diff --git a/.yardopts b/.yardopts deleted file mode 100644 index b95bfb1..0000000 --- a/.yardopts +++ /dev/null @@ -1,6 +0,0 @@ ---markup markdown -- -CHANGELOG.md -CONTRIBUTING.md -LICENSE.md -README.md \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3ac195b..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -Next Release -============ -* Your contribution here. - -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). - -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). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 41890ea..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,44 +0,0 @@ -## 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/LICENSE.md b/COPYING similarity index 52% rename from LICENSE.md rename to COPYING index cdef21c..3f6427a 100644 --- a/LICENSE.md +++ b/COPYING @@ -1,6 +1,4 @@ -Copyright (c) 2012-2014 Tom Vaughan, Karl Freeman - -MIT License +Copyright (c) 2012 Tom Vaughan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -10,13 +8,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. \ No newline at end of file +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. diff --git a/Gemfile b/Gemfile index 21791c5..90280d4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,19 @@ -source 'https://rubygems.org' +source :rubygems + +# Specify your gem's dependencies in middleman-deploy.gemspec +gemspec gemspec -group :test do - gem 'rake', '~> 10.0' - gem 'cucumber', '~> 1.3' - gem 'aruba', '~> 0.5' - gem 'fivemat' - gem 'codeclimate-test-reporter' +group :development do + gem "rake", "~> 0.9.2" + gem "rdoc", "~> 3.9" + gem "yard", "~> 0.8.0" +end + +group :test do + gem "cucumber", "~> 1.2.0" + gem "fivemat" + gem "aruba", "~> 0.4.11" + gem "rspec", "~> 2.7" end diff --git a/README.md b/README.md index 17ca28f..36ff998 100644 --- a/README.md +++ b/README.md @@ -1,186 +1,67 @@ -# Middleman Deploy +Middleman Delpoy -- Deploy a [middleman](http://middlemanapp.com/) built site over rsync. -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)). +[![Build Status](https://secure.travis-ci.org/tvaughan/middleman-deploy.png)](http://travis-ci.org/tvaughan/middleman-deploy) -## Installation +=== -```ruby -gem 'middleman-deploy', '~> 1.0' -``` +## QUICK START -## Usage +Be sure that `rsync` is installed. -``` -$ middleman build [--clean] -$ middleman deploy [--build-before] -``` +### Step 1 -## Possible Configurations + gem install middleman-deploy -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. +### Step 2 -### Rsync + middleman init example-site + cd example-site -Make sure that `rsync` is installed, and activate the extension by adding the -following to `config.rb`: +### Step 3 -```ruby -activate :deploy do |deploy| - 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 - # deploy.clean = true # remove orphaned files on remote host, default: false - # deploy.flags = '-rltgoDvzO --no-p --del' # add custom flags, default: -avz -end -``` +Edit `Gemfile`, and add: -### Git (e.g. GitHub Pages) + gem "middleman-deploy" -Make sure that `git` is installed, and activate the extension by adding the -following to `config.rb`: +Then run: -```ruby -activate :deploy do |deploy| - 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.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 -``` + bundle install -If you use a remote name, you must first add it using `git remote add`. Run -`git remote -v` to see a list of possible remote names. If you use a git url, -it must end with '.git'. +### Step 4 -Afterwards, the `build` directory will become a git repo. +#### These settings are required. -If you use the force push strategy, this branch will be created on the remote if -it doesn't already exist. -But if you use the submodule strategy, you must first initialize build folder as -a submodule. See `git submodule add` documentation. +Edit `config.ru`, and add: -### FTP + activate :deploy do |deploy| + deploy.user = "tvaughan" + deploy.host = "www.example.com" + deploy.path = "/srv/www/site" + end -Activate the extension by adding the following to `config.rb`: +Adjust these values accordingly. -```ruby -activate :deploy do |deploy| - deploy.deploy_method = :ftp - deploy.host = 'ftp.example.com' - deploy.path = '/srv/www/site' - deploy.user = 'tvaughan' - deploy.password = 'secret' -end -``` +### Step 4.1 -### SFTP +#### These settings are optional. -Activate the extension by adding the following to `config.rb`: +To use a particular SSH port, add: -```ruby -activate :deploy do |deploy| - 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 -end -``` + deploy.port = 5309 -### Run Automatically +Default is `22`. -To automatically run `middleman build` during `middleman deploy`, turn on the -`build_before` option while activating the deploy extension: +To remove orphaned files or directories on the remote host, add: -```ruby -activate :deploy do |deploy| - # ... - deploy.build_before = true # default: false -end -``` + deploy.clean = true -### Multiple Environments +Default is `false`. -Deploy your site to more than one configuration using environment variables. +### Step 5 -```ruby -# config.rb -case ENV['TARGET'].to_s.downcase -when 'production' - activate :deploy do |deploy| - deploy.deploy_method = :rsync - deploy.host = 'www.example.com' - deploy.path = '/srv/www/production-site' - end -else - activate :deploy do |deploy| - deploy.deploy_method = :rsync - deploy.host = 'staging.example.com' - deploy.path = '/srv/www/staging-site' - end -end -``` + middleman build + middleman deploy -```ruby -# Rakefile -namespace :deploy do - def deploy(env) - puts "Deploying to #{env}" - system "TARGET=#{env} bundle exec middleman deploy" - end +### NOTES - task :staging do - deploy :staging - end - - task :production do - deploy :production - end -end -``` - -``` -$ rake deploy:staging -$ rake deploy:production -``` - -## 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] - -# 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) - -[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 +Inspired by the rsync task in [Octopress](https://github.com/imathis/octopress). diff --git a/Rakefile b/Rakefile index bd08477..76021e8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,25 +1,35 @@ require 'bundler' -Bundler.setup Bundler::GemHelper.install_tasks require 'cucumber/rake/task' + Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| - exempt_tags = ['--tags ~@wip'] - t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" + t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" end -begin - require 'yard' - YARD::Rake::YardocTask.new -rescue LoadError +require 'rake/clean' + +task :test => ["cucumber"] + +require "middleman-deploy/pkg-info" + +PACKAGE = "#{Middleman::Deploy::PACKAGE}" +VERSION = "#{Middleman::Deploy::VERSION}" + +task :package do + system "gem build #{PACKAGE}.gemspec" end -begin - require 'rubocop/rake_task' - desc 'Run rubocop' - RuboCop::RakeTask.new(:rubocop) -rescue LoadError +task :install => :package do + Dir.chdir("pkg") do + system "gem install #{PACKAGE}-#{VERSION}" + end end -task default: :cucumber -task test: :cucumber +task :release => :package do + Dir.chdir("pkg") do + system "gem push #{PACKAGE}-#{VERSION}" + end +end + +task :default => :test diff --git a/features/support/env.rb b/features/support/env.rb index 41f7c3f..089772c 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,8 +1,4 @@ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__))) -require 'middleman-core' -require 'middleman-core/step_definitions' - -require 'codeclimate-test-reporter' -CodeClimate::TestReporter.start - -require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-deploy') +require "middleman-core" +require "middleman-core/step_definitions" +require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-deploy') \ No newline at end of file diff --git a/features/test.feature b/features/test.feature deleted file mode 100644 index 77daad0..0000000 --- a/features/test.feature +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index e69de29..0000000 diff --git a/fixtures/test-app/source/index.html.erb b/fixtures/test-app/source/index.html.erb deleted file mode 100644 index d87d360..0000000 --- a/fixtures/test-app/source/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -

Test

\ No newline at end of file diff --git a/lib/middleman-deploy.rb b/lib/middleman-deploy.rb index 124cd48..78b96d4 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' - ::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 c781949..85e4e1f 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -1,119 +1,60 @@ -require 'middleman-core/cli' -require 'middleman-core/rack' if Middleman::VERSION.to_i > 3 -require 'middleman-deploy/pkg-info' -require 'middleman-deploy/extension' -require 'middleman-deploy/methods' -require 'middleman-deploy/strategies' +require "middleman-core/cli" + +require "middleman-deploy/extension" module Middleman module Cli + # This class provides a "deploy" command for the middleman CLI. - class Deploy < Thor::Group + class Deploy < Thor 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", "Deploy to a remote host over rsync" + method_option "clean", + :type => :boolean, + :aliases => "-c", + :desc => "Remove orphaned files or directories on the remote host" def deploy - env = options['environment'] ? :production : options['environment'].to_s.to_sym - verbose = options['verbose'] ? 0 : 1 - instrument = options['instrument'] + shared_inst = ::Middleman::Application.server.inst - @app = ::Middleman::Application.new do - config[:mode] = :build - config[:environment] = env - ::Middleman::Logger.singleton(verbose, instrument) - end - build_before(options) - process - end + host = shared_inst.options.host + port = shared_inst.options.port + user = shared_inst.options.user + path = shared_inst.options.path - protected - - def build_before(options = {}) - 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 - run("middleman build -e #{options['environment']}") || exit(1) - end - end - - def print_usage_and_die(message) - fail StandardError, "ERROR: #{message}\n#{Middleman::Deploy::README}" - end - - def process - server_instance = @app - 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, deploy_options) - - method_instance.process - end - - def deploy_options - options = nil - - begin - options = ::Middleman::Deploy.options - rescue NoMethodError - print_usage_and_die 'You need to activate the deploy extension in config.rb.' + # These only exists when the config.rb sets them! + if (!host || !user || !path) + raise Thor::Error.new "You need to activate the deploy extension in config.rb" end - unless options.deploy_method - print_usage_and_die 'The deploy extension requires you to set a method.' + command = "rsync -avze '" + "ssh -p #{port}" + "' build/ #{user}@#{host}:#{path}" + + if options.has_key? "clean" + clean = options.clean + else + clean = shared_inst.options.clean end - case options.deploy_method - when :rsync, :sftp - unless options.host && options.path - 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 - print_usage_and_die 'The ftp deploy method requires host, path, user, and password to be set.' - end + if clean + command += " --delete" end - options + run command end + end - # Add to CLI - Base.register(Middleman::Cli::Deploy, 'deploy', 'deploy [options]', Middleman::Deploy::TAGLINE) - # 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 b7f59cb..f7b05a5 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -1,53 +1,57 @@ # Require core library -require 'middleman-core' +require "middleman-core" # Extension namespace module Middleman module Deploy - @options + + class Options < Struct.new(:host, :port, :user, :path, :clean); end class << self - attr_reader :options - attr_writer :options - end - - 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 options + @@options + end + def registered(app, options_hash={}, &block) + options = Options.new(options_hash) yield options if block_given? - # Default options for the rsync method. options.port ||= 22 options.clean ||= false - # Default options for the git method. - options.remote ||= 'origin' - options.branch ||= 'gh-pages' - options.strategy ||= :force_push - options.commit_message ||= nil + @@options = options - options.build_before ||= false + app.send :include, Helpers + + app.after_configuration do + if (!options.host || !options.user || !options.path) + raise < exception - handle_exception(exception, ftp, filename) - end - - puts "Copied #{filename}" - end - - def upload_directory(ftp, filename) - ftp.mkdir(filename) - puts "Created directory #{filename}" - rescue - end - end - end - end -end diff --git a/lib/middleman-deploy/methods/git.rb b/lib/middleman-deploy/methods/git.rb deleted file mode 100644 index 82bc2cc..0000000 --- a/lib/middleman-deploy/methods/git.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Middleman - module Deploy - module Methods - class Git < Base - def process - puts "## Deploying via git to remote=\"#{options.remote}\" and branch=\"#{options.branch}\"" - - 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(build_dir, options.remote, options.branch, options.commit_message) - - strategy_instance.process - end - end - end - end -end diff --git a/lib/middleman-deploy/methods/rsync.rb b/lib/middleman-deploy/methods/rsync.rb deleted file mode 100644 index dcc8abb..0000000 --- a/lib/middleman-deploy/methods/rsync.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Middleman - module Deploy - module Methods - class Rsync < Base - attr_reader :clean, :flags, :host, :path, :port, :user - - def initialize(server_instance, options = {}) - super(server_instance, options) - - @clean = self.options.clean - @flags = self.options.flags - @host = self.options.host - @path = self.options.path - @port = self.options.port - @user = self.options.user - end - - def process - # Append "@" to user if provided. - user = "#{self.user}@" if user && !user.empty? - - dest_url = "#{user}#{host}:#{path}" - flags = self.flags || '-avz' - command = "rsync #{flags} '-e ssh -p #{port}' #{build_dir}/ #{dest_url}" - - command += ' --delete' if clean - - puts "## Deploying via rsync to #{dest_url} port=#{port}" - exec command - end - end - end - end -end diff --git a/lib/middleman-deploy/methods/sftp.rb b/lib/middleman-deploy/methods/sftp.rb deleted file mode 100644 index 572c402..0000000 --- a/lib/middleman-deploy/methods/sftp.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'net/sftp' -require 'ptools' - -module Middleman - module Deploy - module Methods - class Sftp < Ftp - def process - puts "## Deploying via sftp to #{user}@#{host}:#{path}" - - # `nil` is a valid value for user and/or pass. - Net::SFTP.start(host, user, password: pass, port: port) do |sftp| - sftp.mkdir(path) - - Dir.chdir(build_dir) do - filtered_files.each do |filename| - if File.directory?(filename) - upload_directory(sftp, filename) - else - upload_file(sftp, filename) - end - end - end - end - end - - protected - - def handle_exception(exception, filename, file_path) - reply = exception.message - err_code = reply[0, 3].to_i - - sftp.upload(filename, file_path) if err_code == 550 - end - - def upload_directory(sftp, filename) - file_path = "#{path}/#{filename}" - - begin - sftp.mkdir(file_path) - puts "Created directory #{filename}" - rescue - end - end - - def upload_file(sftp, filename) - file_path = "#{path}/#{filename}" - - begin - sftp.upload(filename, file_path) - rescue Exception => exception - handle_exception(exception, filename, file_path) - end - - 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 bde3750..7d4256f 100644 --- a/lib/middleman-deploy/pkg-info.rb +++ b/lib/middleman-deploy/pkg-info.rb @@ -1,64 +1,6 @@ module Middleman module Deploy - PACKAGE = 'middleman-deploy' - VERSION = '2.0.0-alpha' - TAGLINE = 'Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).' - README = %{ -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} + PACKAGE = "middleman-deploy" + VERSION = "0.0.2" end end diff --git a/lib/middleman-deploy/strategies.rb b/lib/middleman-deploy/strategies.rb deleted file mode 100644 index b2160a1..0000000 --- a/lib/middleman-deploy/strategies.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'middleman-deploy/strategies/git/base' -require 'middleman-deploy/strategies/git/force_push' -require 'middleman-deploy/strategies/git/submodule' diff --git a/lib/middleman-deploy/strategies/git/base.rb b/lib/middleman-deploy/strategies/git/base.rb deleted file mode 100644 index f0a667b..0000000 --- a/lib/middleman-deploy/strategies/git/base.rb +++ /dev/null @@ -1,56 +0,0 @@ -module Middleman - module Deploy - module Strategies - module Git - class Base - 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 - fail NotImplementedError - end - - protected - - def add_signature_to_commit_message(base_message) - signature = "#{Middleman::Deploy::PACKAGE} #{Middleman::Deploy::VERSION}" - time = "#{Time.now.utc}" - - "#{base_message} at #{time} by #{signature}" - end - - 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 =~ /#{branch}/i } - `git checkout #{branch}` - else - `git checkout -b #{branch}` - end - end - - def commit_branch(options = '') - message = commit_message ? commit_message : add_signature_to_commit_message('Automated commit') - - run_or_fail('git add -A') - run_or_fail("git commit --allow-empty -am \"#{message}\"") - run_or_fail("git push #{options} origin #{branch}") - end - - private - - def run_or_fail(command) - system(command) || fail("ERROR running: #{command}") - end - end - end - end - end -end diff --git a/lib/middleman-deploy/strategies/git/force_push.rb b/lib/middleman-deploy/strategies/git/force_push.rb deleted file mode 100644 index 5c1348c..0000000 --- a/lib/middleman-deploy/strategies/git/force_push.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Middleman - module Deploy - module Strategies - module Git - class ForcePush < Base - def process - Dir.chdir(build_dir) do - add_remote_url - checkout_branch - commit_branch('-f') - end - end - - private - - def add_remote_url - url = get_remote_url - - unless File.exist?('.git') - `git init` - `git remote add origin #{url}` - `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 - `git remote rm origin` - `git remote add origin #{url}` - end - # check if the user name has changed - `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 "#{user_email}"` unless user_email == `git config --get user.email` - end - end - - def get_remote_url - remote = self.remote - url = remote - - # check if remote is not a git url - unless remote =~ /\.git$/ - url = `git config --get remote.#{url}.url`.chop - end - - # if the remote name doesn't exist in the main repo - if url == '' - puts "Can't deploy! Please add a remote with the name '#{remote}' to your repo." - exit - end - - url - end - end - end - end - end -end diff --git a/lib/middleman-deploy/strategies/git/submodule.rb b/lib/middleman-deploy/strategies/git/submodule.rb deleted file mode 100644 index e974226..0000000 --- a/lib/middleman-deploy/strategies/git/submodule.rb +++ /dev/null @@ -1,42 +0,0 @@ -module Middleman - module Deploy - module Strategies - module Git - class Submodule < Base - def process - Dir.chdir(build_dir) do - checkout_branch - pull_submodule - commit_branch - end - - commit_submodule - end - - private - - def commit_submodule - current_branch = `git rev-parse --abbrev-ref HEAD` - message = add_signature_to_commit_message('Deployed') - - `git add #{build_dir}` - `git commit --allow-empty -m "#{message}"` - `git push origin #{current_branch}` - end - - def pull_submodule - `git fetch` - `git stash` - `git rebase #{remote}/#{branch}` - `git stash pop` - - 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 - end - end - end - end -end diff --git a/lib/middleman_extension.rb b/lib/middleman_extension.rb index c810845..233dc74 100644 --- a/lib/middleman_extension.rb +++ b/lib/middleman_extension.rb @@ -1 +1 @@ -require 'middleman-deploy' +require "middleman-deploy" \ No newline at end of file diff --git a/middleman-deploy.gemspec b/middleman-deploy.gemspec index 1c50a7c..3229618 100644 --- a/middleman-deploy.gemspec +++ b/middleman-deploy.gemspec @@ -1,32 +1,25 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'middleman-deploy/pkg-info' +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "middleman-deploy/pkg-info" -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' +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://flavors.me/tvaughan" + s.summary = %q{Deploy a middleman built site over rsync.} + s.description = %q{Deploy a middleman built site over rsync.} - 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' - - spec.add_dependency 'middleman-core', '>= 3.2' - spec.add_dependency 'ptools' - spec.add_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' + 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"] + + # The version of middleman-core your extension depends on + s.add_runtime_dependency("middleman-core", [">= 3.0.0"]) + + # Additional dependencies + # s.add_runtime_dependency("gem-name", "gem-version") end