travis-deploy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  script: rspec
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - jruby
data/lib/travis/deploy.rb CHANGED
@@ -17,9 +17,12 @@ module Travis
17
17
  method_option :env, :aliases => '-e', :type => :string
18
18
  method_option :source, :aliases => '-s', :type => :string
19
19
  method_option :backup, :aliases => '-b', :type => :boolean, :default => false
20
+ method_option :pretend, :type => :boolean, :default => false
21
+ method_option :app, :type => :string
20
22
 
21
23
  def config(remote)
22
- Config.new(shell, remote, options).invoke
24
+ config = Config.new(shell, remote, options)
25
+ options[:pretend] ? config.pretend : config.invoke
23
26
  end
24
27
 
25
28
  desc 'deploy', 'Deploy to the given remote'
@@ -4,6 +4,7 @@ require 'yaml'
4
4
  module Travis
5
5
  class Deploy
6
6
  class Config
7
+ autoload :Builder, 'travis/deploy/config/builder'
7
8
  include Helper
8
9
 
9
10
  attr_reader :shell, :remote, :env, :options
@@ -20,18 +21,23 @@ module Travis
20
21
  push
21
22
  end
22
23
 
24
+ def pretend
25
+ say 'Config to upload:'
26
+ say YAML.dump(config)
27
+ end
28
+
23
29
  protected
24
30
 
25
31
  def app
26
- @app ||= begin
27
- app = File.basename(Dir.pwd).gsub('travis-', '')
28
- app = 'web' if app == 'ci'
29
- app
30
- end
32
+ @app ||= options[:app] || File.basename(Dir.pwd).gsub('travis-', '')
31
33
  end
32
34
 
33
35
  def config
34
- @config ||= source || keychain.fetch
36
+ @config ||= source ? YAML.load(source) : Builder.new(keychain, env).build
37
+ end
38
+
39
+ def yaml_config
40
+ @yaml_config ||= source || keychain.source
35
41
  end
36
42
 
37
43
  def source
@@ -44,13 +50,13 @@ module Travis
44
50
 
45
51
  def store
46
52
  backup if backup?
47
- File.open(filename, 'w+') { |f| f.write(config) }
53
+ File.open(filename, 'w+') { |f| f.write(yaml_config) }
48
54
  end
49
55
 
50
56
  def push
51
57
  say 'Configuring the app ...'
52
- config = Shellwords.escape(YAML.dump(YAML.load(self.config)[env]))
53
- run "heroku config:add travis_config=#{config} -r #{remote}", :echo => "heroku config:add travis_config=... -r #{remote}"
58
+ yaml = Shellwords.escape(YAML.dump(config))
59
+ run "heroku config:add travis_config=#{yaml} -r #{remote}", :echo => "heroku config:add travis_config=... -r #{remote}"
54
60
  end
55
61
 
56
62
  def backup
@@ -0,0 +1,33 @@
1
+ class Travis::Deploy::Config
2
+ class Builder
3
+ attr_reader :config, :env, :keychain
4
+
5
+ def initialize(keychain, env)
6
+ @keychain = keychain
7
+ @config = YAML.load(keychain.source)
8
+ @env = env
9
+ end
10
+
11
+ def build
12
+ includes = []
13
+
14
+ includes << config.delete('includes') if config['includes']
15
+ includes << env_config.delete('includes') if env_config['includes']
16
+
17
+ includes.flatten!
18
+
19
+ result = env_config
20
+ includes.each do |name|
21
+ include_config = keychain.includes(name)
22
+ result.merge! include_config['all'] || {}
23
+ result.merge! include_config[env] || {}
24
+ end
25
+
26
+ result
27
+ end
28
+
29
+ def env_config
30
+ config.fetch env, {}
31
+ end
32
+ end
33
+ end
@@ -15,8 +15,31 @@ module Travis
15
15
  read
16
16
  end
17
17
 
18
+ def source
19
+ @source ||= fetch
20
+ end
21
+
22
+ def includes(name)
23
+ include_files[name]
24
+ end
25
+
18
26
  protected
19
27
 
28
+ def include_files
29
+ @include_files ||= begin
30
+ contents = {}
31
+
32
+ chdir do
33
+ Dir['config/includes/*.yml'].each do |path|
34
+ name = File.basename(path).sub(/\.yml$/, '')
35
+ contents[name] = YAML.load(File.read(path))
36
+ end
37
+ end
38
+
39
+ contents
40
+ end
41
+ end
42
+
20
43
  def pull
21
44
  error 'There are unstaged changes in your travis-keychain working directory.' unless clean?
22
45
  say 'Fetching the keychain ...'
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ class Travis::Deploy::Config
4
+ describe Builder do
5
+ let(:env) { 'staging' }
6
+ let(:config) { "staging:\n foo: bar" }
7
+ let(:keychain) { stub(:keychain, source: @config || config) }
8
+ let(:builder) { Builder.new(keychain, env) }
9
+
10
+ it 'loads config for given env' do
11
+ builder.build.should == { 'foo' => 'bar' }
12
+ end
13
+
14
+ it 'includes files specified at a top level' do
15
+ @config = YAML.dump 'includes' => ['pusher'], 'staging' => { 'foo' => 'bar' }
16
+ pusher_config = {
17
+ 'all' => { 'bar' => 'baz', 'baz' => 'should be overwritten' },
18
+ 'staging' => { 'baz' => 'qux' },
19
+ 'development' => { 'no' => 'no' }
20
+ }
21
+ keychain.should_receive(:includes).with('pusher').and_return(pusher_config)
22
+
23
+ builder.build.should == { 'foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux' }
24
+ end
25
+
26
+ it 'includes files specified for an env' do
27
+ @config = YAML.dump 'staging' => { 'foo' => 'bar', 'includes' => ['pusher'] },
28
+ 'production' => { 'includes' => ['encryption'] }
29
+
30
+ pusher_config = {
31
+ 'all' => { 'bar' => 'baz', 'baz' => 'should be overwritten' },
32
+ 'staging' => { 'baz' => 'qux' },
33
+ 'development' => { 'no' => 'no' }
34
+ }
35
+ keychain.should_receive(:includes).with('pusher').and_return(pusher_config)
36
+
37
+ builder.build.should == { 'foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux' }
38
+
39
+ end
40
+ end
41
+ end
@@ -7,14 +7,14 @@ describe Travis::Deploy::Config do
7
7
  before :each do
8
8
  Travis::Deploy::Config.any_instance.stub(:clean? => true)
9
9
  Travis::Deploy::Config.any_instance.stub(:run)
10
- Travis::Keychain.any_instance.stub(:fetch => config)
10
+ Travis::Keychain.any_instance.stub(:source => config)
11
11
  File.stub(:open)
12
12
  end
13
13
 
14
14
  describe 'sync' do
15
15
  it 'fetches the config from the keychain' do
16
16
  command = Travis::Deploy::Config.new(shell, 'staging', {})
17
- command.send(:keychain).should_receive(:fetch).and_return(config)
17
+ command.send(:keychain).should_receive(:source).and_return(config)
18
18
  command.invoke
19
19
  end
20
20
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'travis-deploy'
5
- gem.version = '0.1.0'
5
+ gem.version = '0.2.0'
6
6
 
7
7
  gem.authors = ['Travis Deploy Tool']
8
8
  gem.email = ['contact@travis-ci.org']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -92,12 +92,14 @@ files:
92
92
  - bin/travis-deploy
93
93
  - lib/travis/deploy.rb
94
94
  - lib/travis/deploy/config.rb
95
+ - lib/travis/deploy/config/builder.rb
95
96
  - lib/travis/deploy/deploy.rb
96
97
  - lib/travis/deploy/helper.rb
97
98
  - lib/travis/deploy/secure_key.rb
98
99
  - lib/travis/keychain.rb
99
100
  - lib/travis_cli.rb
100
101
  - spec/spec_helper.rb
102
+ - spec/travis/deploy/config/builder_spec.rb
101
103
  - spec/travis/deploy/config_spec.rb
102
104
  - spec/travis/deploy/deploy_spec.rb
103
105
  - spec/travis/deploy/secure_key_spec.rb
@@ -123,14 +125,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  version: '0'
124
126
  requirements: []
125
127
  rubyforge_project:
126
- rubygems_version: 1.8.23
128
+ rubygems_version: 1.8.24
127
129
  signing_key:
128
130
  specification_version: 3
129
131
  summary: A command-line interface to Travis CI
130
132
  test_files:
131
133
  - spec/spec_helper.rb
134
+ - spec/travis/deploy/config/builder_spec.rb
132
135
  - spec/travis/deploy/config_spec.rb
133
136
  - spec/travis/deploy/deploy_spec.rb
134
137
  - spec/travis/deploy/secure_key_spec.rb
135
138
  - spec/travis/keychain_spec.rb
136
- has_rdoc: