conditional_capistrano 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc3085020b2ca58897de31421534673847407529
4
+ data.tar.gz: 3378e5a30a4ff7a10b718ccb1c376112723de2e5
5
+ SHA512:
6
+ metadata.gz: 5a3d6e3884fff3858ab52779902fcf86645cdf06c518f780d8953c7b8820953a701e54689d369928a767c5b5f0809a886f5a49810825dfd38f64bd808cc3a08d
7
+ data.tar.gz: 2fa696d924c08c19f5d77cbe250ea0007be2dbe619413b141074cb2a6ddc2d56fef20d95b9228ab30d3e40a8afa9a9cbf477a3b695b2e9a770c9125fb8463632
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in conditional_capistrano.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tom
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # ConditionalCapistrano
2
+
3
+ Conditionally schedule and execute capistrano tasks based on changes to
4
+ specified paths.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'conditional_capistrano', require: false
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install conditional_capistrano
19
+
20
+ ## Usage
21
+
22
+ Simply require the capistrano module in your `config/deploy.rb` file:
23
+
24
+ require 'conditional_capistrano/capistrano'
25
+
26
+ Then add some options to the task scheduling:
27
+
28
+ after "key_vault:symlink", "key_vault:check", when_changed: "config/key_vault.yml"
29
+ after "deploy:symlink_configs", "assets:compile", when_changed: %w[app/assets Gemfile Gemfile.lock config/application.rb]
30
+
31
+ You can either mention single files or whole folders, which will be checked for any
32
+ changes within.
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'conditional_capistrano/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "conditional_capistrano"
8
+ spec.version = ConditionalCapistrano::VERSION
9
+ spec.authors = ["redbubble"]
10
+ spec.email = ["developers@redbubble.com"]
11
+ spec.description = %q{Conditionally schedule and execute capistrano tasks based on changes to specified paths}
12
+ spec.summary = %q{Execute capistrano task's only when certain path's have changed since the last deploy}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,49 @@
1
+ module ConditionalCapistrano
2
+ module Capistrano
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include InstanceMethods
6
+
7
+ alias_method :applies_to_without_file_check?, :applies_to?
8
+ alias_method :applies_to?, :applies_to_with_file_check?
9
+ end
10
+ end
11
+
12
+ module InstanceMethods
13
+ def applies_to_with_file_check?(task)
14
+ return false if check_for_changes? && !trigger?(*paths_to_check)
15
+
16
+ applies_to_without_file_check?(task)
17
+ end
18
+
19
+ private
20
+
21
+ def check_for_changes?
22
+ options.has_key?(:when_changed)
23
+ end
24
+
25
+ def paths_to_check
26
+ Array(options[:when_changed])
27
+ end
28
+
29
+ def trigger?(*paths)
30
+ paths.find { |path| changed_files.find { |p| p[0, path.length] == path } }
31
+ rescue IndexError
32
+ false
33
+ end
34
+
35
+ def changed_files
36
+ @changed_files ||=
37
+ config.capture(
38
+ "cd #{fetch(:repository_cache)} && git diff --name-only #{fetch(:current_git_tag)} HEAD | cat"
39
+ ).strip.split
40
+ end
41
+
42
+ def fetch(key)
43
+ config.fetch key
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ Capistrano::Callback.send :include, ConditionalCapistrano::Capistrano
@@ -0,0 +1,3 @@
1
+ module ConditionalCapistrano
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "conditional_capistrano/version"
2
+
3
+ module ConditionalCapistrano
4
+ end
@@ -0,0 +1,53 @@
1
+ module Capistrano; end
2
+ class Capistrano::Callback
3
+ attr_reader :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def applies_to?(task)
10
+ "original"
11
+ end
12
+ end
13
+
14
+ require 'conditional_capistrano/capistrano'
15
+
16
+ describe Capistrano::Callback do
17
+
18
+ describe "#applies_to_with_file_check?" do
19
+ it "falls back to the original 'applies_to?' if no 'when_changed' options were found" do
20
+ Capistrano::Callback.new({}).applies_to?("test").should == "original"
21
+ end
22
+
23
+ it "returns false if files have been specified, but haven't changed" do
24
+ callback = Capistrano::Callback.new(when_changed: "file")
25
+ callback.stub :trigger? => false
26
+
27
+ callback.applies_to?("test").should_not be
28
+ end
29
+
30
+ it "falls back to the original if files have been specified, and have changed" do
31
+ callback = Capistrano::Callback.new(when_changed: "file")
32
+ callback.stub :trigger? => true
33
+
34
+ callback.applies_to?("test").should == "original"
35
+ end
36
+
37
+ context "possible file options" do
38
+ it "allows a single file" do
39
+ callback = Capistrano::Callback.new(when_changed: "file")
40
+
41
+ callback.should_receive(:trigger?).with "file"
42
+ callback.applies_to? "test"
43
+ end
44
+
45
+ it "allows an array of files" do
46
+ callback = Capistrano::Callback.new(when_changed: %w[file1 file2])
47
+
48
+ callback.should_receive(:trigger?).with "file1", "file2"
49
+ callback.applies_to? "test"
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conditional_capistrano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - redbubble
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Conditionally schedule and execute capistrano tasks based on changes
56
+ to specified paths
57
+ email:
58
+ - developers@redbubble.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - conditional_capistrano.gemspec
69
+ - lib/conditional_capistrano.rb
70
+ - lib/conditional_capistrano/capistrano.rb
71
+ - lib/conditional_capistrano/version.rb
72
+ - spec/conditional_capistrano/capistrano_spec.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.1.11
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Execute capistrano task's only when certain path's have changed since the
97
+ last deploy
98
+ test_files:
99
+ - spec/conditional_capistrano/capistrano_spec.rb