heroploy 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 105eedfe09a02a9d37fa4f51a66a85be998488ab
4
- data.tar.gz: eb15f7c1627dc9cfdef4f6531aaf675f145b7bbe
3
+ metadata.gz: 43d2a2c41a7f6cf4df2a3bd702909a8f3187e86b
4
+ data.tar.gz: d38defbf1034e876710827b2df4f389f4775e614
5
5
  SHA512:
6
- metadata.gz: a3357bd2d6a57371ed2b33609baf2b867debdd1fa3798df6dbd89628f028cb5c8110333e08f4868cb06c464dd034af4d37f03f3f498598a2490944b41849554c
7
- data.tar.gz: 5f8b1062cab707cd0c540810f07c6df7919d6a51ab3eed7fed078ed0627bbde45d6edd19b9dce2372763c9ee520ca4e468763b8d6431b8190a178cf560bcc40f
6
+ metadata.gz: fc5fd21d2bdd1642f9c5c1abc145072b07d7744df3b51d76be6a9d17562bf1e325accadbd4536910f4538d15fa1974b238d543f54387ec74197f9dc05f80bc10
7
+ data.tar.gz: c34743eeda303b04f3865f83f1efdb8951df103b086c0d2dbda6b7280c5e174a0fb2eb97244fed6eb5a2a705b9acd167ee24f6014008de52e94f660163ba692a
data/README.md CHANGED
@@ -35,6 +35,8 @@ If you're running Rails, you can use this generator to add an example config fil
35
35
  Here's an example ```heroploy.yml``` file:
36
36
 
37
37
  ```yaml
38
+ travis_repo: my-travis-user/my-travis-repo
39
+
38
40
  environments:
39
41
  development:
40
42
  app: my-development-app
@@ -52,6 +54,7 @@ environments:
52
54
  pushed: true
53
55
  branch: master
54
56
  staged: true
57
+ travis: true
55
58
  ```
56
59
 
57
60
  This file:
@@ -59,7 +62,7 @@ This file:
59
62
  * Describes ```development```, ```staging``` and ```production``` deployment rules for three Heroku apps (named ```my-development-app```, ```my-staging-app``` and ```my-production-app``` on Heroku).
60
63
  * Allows any branch to be pushed directly to ```development```.
61
64
  * Only allows ```master``` to be pushed to ```staging```, and requires all changes to have first been pushed to ```origin```.
62
- * Only allows deployment to ```production``` if the changes have first been staged on ```staging```.
65
+ * Only allows deployment to ```production``` if the changes have first been staged on ```staging``` and the Travis build is passing.
63
66
 
64
67
  To deploy to one of these environments, run ```rake heroploy:<environment>:deploy```. For example:
65
68
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "bundler", "~> 1.3"
22
+ spec.add_dependency "travis", "~> 1.6"
22
23
  spec.add_development_dependency "rake"
23
24
  spec.add_development_dependency "rails"
24
25
  spec.add_development_dependency "rspec"
@@ -1,3 +1,5 @@
1
+ require 'travis'
2
+
1
3
  module Heroploy
2
4
  module Commands
3
5
  module Checks
@@ -37,6 +39,13 @@ module Heroploy
37
39
  end
38
40
  end
39
41
  end
42
+
43
+ def check_travis(branch_name, travis_repo_name)
44
+ travis_repo = Travis::Repository.find(travis_repo_name)
45
+ unless travis_repo.branch(branch_name).green?
46
+ raise "Failing Travis build for branch #{branch_name}"
47
+ end
48
+ end
40
49
  end
41
50
  end
42
51
  end
@@ -6,6 +6,7 @@ require 'heroploy/config/remote_config'
6
6
  module Heroploy
7
7
  module Config
8
8
  class DeploymentConfig
9
+ attr_accessor :travis_repo
9
10
  attr_accessor :environments
10
11
  attr_accessor :shared_env
11
12
  attr_accessor :remote_configs
@@ -15,6 +16,7 @@ module Heroploy
15
16
  end
16
17
 
17
18
  def initialize(attrs = {})
19
+ @travis_repo = attrs['travis_repo']
18
20
  unless attrs['environments'].nil?
19
21
  @environments = attrs['environments'].map { |name, env_attrs| Environment.new(name, env_attrs) }
20
22
  end
@@ -4,12 +4,14 @@ module Heroploy
4
4
  attr_accessor :pushed
5
5
  attr_accessor :branch
6
6
  attr_accessor :staged
7
+ attr_accessor :travis
7
8
 
8
9
  def initialize(attrs = {})
9
10
  attrs ||= {}
10
11
  @pushed = attrs['pushed']
11
12
  @branch = attrs['branch']
12
13
  @staged = attrs['staged'] == true ? 'staging' : attrs['staged']
14
+ @travis = attrs['travis']
13
15
  end
14
16
  end
15
17
  end
@@ -30,6 +30,7 @@ module Heroploy
30
30
  define_branch_check
31
31
  define_staged_check
32
32
  define_config_check
33
+ define_travis_check
33
34
  define_all_check
34
35
  end
35
36
 
@@ -82,6 +83,16 @@ module Heroploy
82
83
  end
83
84
  @defined_tasks << :config
84
85
  end
86
+
87
+ def define_travis_check
88
+ if env_config.checks.travis then
89
+ desc "check the travis build for the current branch"
90
+ task :travis do
91
+ check_travis(current_branch, deploy_config.travis_repo)
92
+ end
93
+ @defined_tasks << :travis
94
+ end
95
+ end
85
96
 
86
97
  def define_all_check
87
98
  desc "do all the checks for #{env_config.name}"
@@ -1,3 +1,3 @@
1
1
  module Heroploy
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,23 +3,27 @@ FactoryGirl.define do
3
3
  pushed false
4
4
  staged false
5
5
  branch nil
6
+ travis false
6
7
 
7
8
  trait :development do
8
9
  pushed false
9
10
  staged false
10
11
  branch nil
12
+ travis false
11
13
  end
12
14
 
13
15
  trait :staging do
14
16
  pushed true
15
17
  staged false
16
18
  branch 'master'
19
+ travis true
17
20
  end
18
21
 
19
22
  trait :production do
20
23
  pushed true
21
24
  staged true
22
25
  branch 'master'
26
+ travis true
23
27
  end
24
28
  end
25
29
 
@@ -36,6 +40,8 @@ FactoryGirl.define do
36
40
  end
37
41
 
38
42
  factory :deployment_config, :class => Heroploy::Config::DeploymentConfig do
43
+ travis_repo "my-travis-user/my-travis-repo"
44
+
39
45
  environments {
40
46
  [
41
47
  build(:environment, :development),
@@ -44,4 +50,20 @@ FactoryGirl.define do
44
50
  ]
45
51
  }
46
52
  end
53
+
54
+ factory :travis_build, :class => Travis::Client::Build do
55
+ [:passed, :failed].each do |t|
56
+ trait t do
57
+ after(:build) do |build|
58
+ build.state = t.to_s
59
+ end
60
+ end
61
+ end
62
+
63
+ initialize_with { Travis::Client::Build.new(Travis::Client::Session.new, 123) }
64
+ end
65
+
66
+ factory :travis_repo, :class => Travis::Client::Repository do
67
+ initialize_with { Travis::Client::Repository.new(Travis::Client::Session.new, 123) }
68
+ end
47
69
  end
@@ -136,4 +136,31 @@ describe Heroploy::Commands::Checks do
136
136
  end
137
137
  end
138
138
  end
139
+
140
+ describe "#check_travis" do
141
+ let(:travis_repo_name) { 'travis/repo' }
142
+ let(:travis_repo) { build(:travis_repo) }
143
+
144
+ before { Travis::Repository.stub(:find).and_return(travis_repo) }
145
+
146
+ context "if the build is failing for the given branch" do
147
+ let(:failed_build) { build(:travis_build, :failed) }
148
+ before { expect(travis_repo).to receive(:branch).and_return(failed_build) }
149
+
150
+ it "raises an error" do
151
+ expect{
152
+ commands.check_travis('my-branch', 'travis/repo')
153
+ }.to raise_error("Failing Travis build for branch my-branch")
154
+ end
155
+ end
156
+
157
+ context "if the build is passing for the given branch" do
158
+ let(:passed_build) { build(:travis_build, :passed) }
159
+ before { expect(travis_repo).to receive(:branch).and_return(passed_build) }
160
+
161
+ it "executes successfully" do
162
+ commands.check_travis('my-branch', 'travis/repo')
163
+ end
164
+ end
165
+ end
139
166
  end
@@ -5,6 +5,7 @@ describe Heroploy::Config::DeploymentConfig do
5
5
 
6
6
  let(:attrs) do
7
7
  {
8
+ 'travis_repo' => 'travis/my-repo',
8
9
  'environments' => {
9
10
  'staging' => {},
10
11
  'production' => {
@@ -30,6 +31,10 @@ describe Heroploy::Config::DeploymentConfig do
30
31
  its('shared_env.required') { should eq(['my-var']) }
31
32
  its('shared_env.variables') { should eq({'my-var' => 'some-value'}) }
32
33
  end
34
+
35
+ context "it initializes the travis repo" do
36
+ its(:travis_repo) { should eq('travis/my-repo') }
37
+ end
33
38
  end
34
39
 
35
40
  describe "#[]" do
@@ -6,19 +6,21 @@ describe Heroploy::Config::EnvironmentChecks do
6
6
  let(:pushed) { true }
7
7
  let(:branch_name) { 'my-branch' }
8
8
  let(:staging_env_name) { 'my-staging-environment' }
9
- let(:attrs) { {'pushed' => pushed, 'branch' => branch_name, 'staged' => staging_env_name} }
9
+ let(:travis) { true }
10
+ let(:attrs) { {'pushed' => pushed, 'branch' => branch_name, 'staged' => staging_env_name, 'travis' => travis} }
10
11
 
11
12
  subject(:environment_checks) { Heroploy::Config::EnvironmentChecks.new(attrs) }
12
13
 
13
14
  its(:pushed) { should eq(pushed) }
14
15
  its(:branch) { should eq(branch_name) }
15
16
  its(:staged) { should eq(staging_env_name) }
17
+ its(:travis) { should eq(travis) }
16
18
  end
17
19
 
18
20
  context "if no staging environment name is given" do
19
21
  subject(:environment_checks) { Heroploy::Config::EnvironmentChecks.new({'staged' => true}) }
20
22
 
21
- it "assumed the staging environment is called 'staging'" do
23
+ it "assumes the staging environment is called 'staging'" do
22
24
  expect(environment_checks.staged).to eq('staging')
23
25
  end
24
26
  end
@@ -41,10 +41,24 @@ describe "check:all" do
41
41
  its(:prerequisites) { should include('branch') }
42
42
  end
43
43
 
44
- context "if checks.staged is not set" do
44
+ context "if checks.branch is not set" do
45
45
  before { environment.checks.branch = nil }
46
46
  include_context "rake"
47
47
 
48
48
  its(:prerequisites) { should_not include('branch') }
49
49
  end
50
+
51
+ context "if checks.travis is set" do
52
+ before { environment.checks.travis = true }
53
+ include_context "rake"
54
+
55
+ its(:prerequisites) { should include('travis') }
56
+ end
57
+
58
+ context "if checks.travis is not set" do
59
+ before { environment.checks.travis = nil }
60
+ include_context "rake"
61
+
62
+ its(:prerequisites) { should_not include('travis') }
63
+ end
50
64
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "check:config" do
4
+ it "should have a spec" do
5
+ pending 'need to tidy up shared context for rake tasks and add specs for this'
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "check:travis" do
4
+ let(:environment) { build(:environment, :production) }
5
+ include_context "rake"
6
+
7
+ it "invokes :check_travis" do
8
+ Heroploy::Tasks::CheckTaskLib.any_instance.stub(:current_branch).and_return("my-branch")
9
+
10
+ expect_any_instance_of(Heroploy::Tasks::CheckTaskLib).to receive(:check_travis)
11
+ .with("my-branch", "my-travis-user/my-travis-repo")
12
+
13
+ task.invoke
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Brunton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: travis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -157,9 +171,11 @@ files:
157
171
  - spec/lib/heroploy/config/shared_env_spec.rb
158
172
  - spec/lib/heroploy/tasks/check_all_spec.rb
159
173
  - spec/lib/heroploy/tasks/check_branch_spec.rb
174
+ - spec/lib/heroploy/tasks/check_config_spec.rb
160
175
  - spec/lib/heroploy/tasks/check_pushed_spec.rb
161
176
  - spec/lib/heroploy/tasks/check_remote_spec.rb
162
177
  - spec/lib/heroploy/tasks/check_staged_spec.rb
178
+ - spec/lib/heroploy/tasks/check_travis_spec.rb
163
179
  - spec/spec_helper.rb
164
180
  - spec/support/customer_matchers/environment_matcher.rb
165
181
  - spec/support/helpers/deploy_config_helper.rb
@@ -204,9 +220,11 @@ test_files:
204
220
  - spec/lib/heroploy/config/shared_env_spec.rb
205
221
  - spec/lib/heroploy/tasks/check_all_spec.rb
206
222
  - spec/lib/heroploy/tasks/check_branch_spec.rb
223
+ - spec/lib/heroploy/tasks/check_config_spec.rb
207
224
  - spec/lib/heroploy/tasks/check_pushed_spec.rb
208
225
  - spec/lib/heroploy/tasks/check_remote_spec.rb
209
226
  - spec/lib/heroploy/tasks/check_staged_spec.rb
227
+ - spec/lib/heroploy/tasks/check_travis_spec.rb
210
228
  - spec/spec_helper.rb
211
229
  - spec/support/customer_matchers/environment_matcher.rb
212
230
  - spec/support/helpers/deploy_config_helper.rb