capistrano-ghostinspector 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cb57e45bdf46b7b97c9eea05c7f759f15ee3c61
4
- data.tar.gz: 208f35347e5574e54ca43dcfe68289cac16cda58
3
+ metadata.gz: 1d0ee7ad612fc7cdd91e7947e3b58c97ebe3f175
4
+ data.tar.gz: 5cb7ae9716135522632335d87cc9caf5b7528851
5
5
  SHA512:
6
- metadata.gz: 3a874e0d9a8347d598f9fe6e48afc3606de07b122482abb1ebb8595dd09cff458cc8ff84b3adce199e450a120b36c6853f66a9fe10661b75c1e3c16772fbb0e5
7
- data.tar.gz: 2885207ca074c23ac60a3086568cf53502834a796658ef9dfb86c419f086daa1869f2e8dd8deaf43a2cae9a1578b2ee933da87219102b840aa087b6711ccccd5
6
+ metadata.gz: a03e909cb704f1c02a0ba1ec22a696a3abde072bed9d90e7fd19358fdd94dde94cdeb14b11033e69076c571671795d8595e0c2d557462652208e8546780d0c70
7
+ data.tar.gz: 74f11642639fe92cab4254e85397169575786867775c13c4bdc6081cdfca6c53731d884a98f5508f0f742bcf566919cc982619a22331c7515d6ca5b6059b97ed
data/README.md CHANGED
@@ -8,7 +8,9 @@
8
8
 
9
9
 
10
10
  #### Features
11
+ - Choose which task to run after
11
12
  - Set individual tests/suites to run from command line
13
+ - Set individual tests/suites to run from configuration on each stage
12
14
  - Exclude individual stages
13
15
  - Auto rollback to previous version on failed tests (can be disabled in config per stage)
14
16
  - Auto configure start URL to reuse tests across multiple stages
@@ -41,6 +43,18 @@ And the add the following to the top of your `deploy.rb` file
41
43
  require 'capistrano/ghostinspector'
42
44
  ```
43
45
 
46
+ Inside your `deploy.rb` file you need to add the following to your run list -
47
+
48
+ ```ruby
49
+ after "deploy", "ghostinspector:setup"
50
+ ```
51
+
52
+ You can change the run order by changing `deploy` for any other task in your deployment run list. For example, you may have a task of `run_scripts` that is executed after deployment for database migration. In this case you would change the above line to -
53
+
54
+ ```ruby
55
+ after "run_scripts", "ghostinspector:setup"
56
+ ```
57
+
44
58
  ## Configuration
45
59
 
46
60
  First thing you need to do is create your `YAML` file (`gi_config.yaml`) in the Capistrano folder with the following format -
@@ -56,6 +70,7 @@ tests:
56
70
  homepage: "XXXXXXXXXXXXXXXXXXX"
57
71
  test2: ""
58
72
  test3: ""
73
+ ga_enabled: true
59
74
  ga_property: "UA-XXXXXXXX-X"
60
75
  ga_custom_1: 1
61
76
  ga_custom_2: 2
@@ -78,11 +93,31 @@ By default the `rollback` feature is enabled, you can disabled this for all stag
78
93
  set :rollback, false
79
94
  ```
80
95
 
96
+ ### Configure Start URL
97
+
98
+ Ghost Inspector has a nice feature that allows you to dynamically alter the start URL for your test. This allows you to reuse the same tests accross multple environments. i.e `staging.mysite.com`, `uat.mysite.com`, `www.mysite.com`. For this feature to work you must have a domain set in your stage. i.e. for staging you might have
99
+
100
+ ```ruby
101
+ set :domain, "staging.mysite.com"
102
+ ```
103
+
104
+ and production might have
105
+
106
+ ```ruby
107
+ set :domain, "www.mysite.com"
108
+ ```
109
+
110
+ _Failure to set the domain in any stage will revert the tests to be only run against the URL you defined in Ghost Inspector_
111
+
81
112
  ## Google Analytics Tracking
82
113
 
83
- The Google Analytics property must be inserted into the `ga_property` in order to log deployments and errors. Simply update your YAML to include this `ga_property: "UA-XXXXXXXX-1"`. To disable the Google Analytics tracking just leave the `ga_property` as empty string i.e. `ga_property: ""` in your YAML.
114
+ The Google Analytics property must be inserted into the `ga_property` in order to log deployments and errors. Simply update your YAML to include this `ga_property: "UA-XXXXXXXX-1"`. The Google Analytics feature also has a `ga_enabled` flag in your YAML file which must be `true` to successfully run. To disable the Google Analytics tracking either set the `ga_enabled` to be false or your can disable Google Analytics in each stage by setting the following -
84
115
 
85
- Since version `0.3.0`, Google Analytics now uses Custom Dimensions as outlined in the [Google Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#cd_ "Google Measurement Protocol") documentation. When you define a new custom dimension in Google Analytics you are given a new dimension index. Default accounts have 20 available indexes where as premium accounts have 200. The `ga_custom_1` property is used to define the custom dimension for the testname and `ga_custom_2` is used to define the Jira tickets*. If you do not set the `ga_custom_1` or `ga_custom_2` properties then the default index of `1` & `2` will be used.
116
+ ```ruby
117
+ set :ga_enabled, false
118
+ ```
119
+
120
+ Google Analytics uses Custom Dimensions as outlined in the [Google Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#cd_ "Google Measurement Protocol") documentation. When you define a new custom dimension in Google Analytics you are given a new dimension index. Default accounts have 20 available indexes where as premium accounts have 200. The `ga_custom_1` property is used to define the custom dimension for the testname and `ga_custom_2` is used to define the Jira tickets*. If you do not set the `ga_custom_1` or `ga_custom_2` properties then the default index of `1` & `2` will be used.
86
121
 
87
122
  \*_Jira tickets are extracted from the git log during the deployment. For this reason it can only track the tickets where you have correctly assigned the ticket number and identifier to the commit message. i.e._
88
123
  ```
@@ -112,7 +147,7 @@ Run a multiple suites when deploying to staging -
112
147
 
113
148
  #### Run Default Tests
114
149
 
115
- Since version `0.4.0`you can now set your default tests/suites to run in each stage. e.g. you might want to run a certain test suite in `production` only but have other tests running in `staging`. You can now set this in your `stage.rb` file using two new flags.
150
+ You can set your default tests/suites to run in each stage. e.g. you might want to run a certain test suite in `production` only but have other tests running in `staging`. You can now set this in your `stage.rb` file using the two flags.
116
151
 
117
152
  i.e `production.rb` might look like this -
118
153
  ```ruby
@@ -122,7 +157,7 @@ and your `staging.rb` file might have the following -
122
157
  ```ruby
123
158
  set :gi_default_test, "blog,checkout"
124
159
  ```
125
- As you can see the two new variables `gi_default_suite` and `gi_default_test` can also take a comma separated list to run.
160
+ As you can see the two variables `gi_default_suite` and `gi_default_test` can also take a comma separated list to run.
126
161
 
127
162
  ## Contributing
128
163
 
@@ -132,6 +167,9 @@ As you can see the two new variables `gi_default_suite` and `gi_default_test` ca
132
167
  4. Push to the branch (`git push origin my-new-feature`)
133
168
  5. Create a new Pull Request
134
169
 
170
+ ## Changelog
171
+ View the changelog [here](https://github.com/richdynamix/capistrano-ghostinspector/wiki/Changelog "Changelog")
172
+
135
173
  ## Credits
136
174
 
137
175
  * Bhalin Ramabhadran - https://twitter.com/BhalinR
@@ -8,7 +8,6 @@ module Capistrano
8
8
  module Ghostinspector
9
9
  def self.load_into(config)
10
10
  config.load do
11
- after "deploy", "ghostinspector:setup"
12
11
  after "ghostinspector:setup", "ghostinspector:run"
13
12
 
14
13
  gi_config = YAML::load(File.read("gi_config.yaml"))
@@ -41,6 +40,14 @@ module Capistrano
41
40
  set :jira_project_code, "GHOST"
42
41
  end
43
42
 
43
+ if gi_config.has_key?("ga_enabled")
44
+ set :ga_enabled, fetch(:ga_enabled, gi_config["ga_enabled"])
45
+ else
46
+ set :ga_enabled, fetch(:ga_enabled, false)
47
+ end
48
+
49
+ set :domain, fetch(:domain, nil)
50
+
44
51
  # Get tests and suites from command line
45
52
  set :gitest, fetch(:gitest, nil)
46
53
  set :gisuite, fetch(:gisuite, nil)
@@ -61,7 +68,7 @@ module Capistrano
61
68
 
62
69
  if (fetch(:gi_enabled) == true)
63
70
 
64
- giApi = Api.new(fetch(:gi_api_key), fetch(:domain), fetch(:rollback), fetch(:ga_property))
71
+ giApi = Api.new(fetch(:gi_api_key), fetch(:domain), fetch(:rollback), fetch(:ga_enabled))
65
72
 
66
73
  @collection = Array.new
67
74
  # run each test
@@ -92,30 +99,34 @@ module Capistrano
92
99
  desc "Send Results to Google Analytics"
93
100
  task :sendGA, :only => { :primary => true } do
94
101
 
95
- puts "* * * Sending Data to Google Analytics * * *"
102
+ if (fetch(:gi_enabled) == true && fetch(:ga_enabled) == true && fetch(:domain) != nil)
96
103
 
97
- jira_project_code = fetch(:jira_project_code)
104
+ puts "* * * Sending Data to Google Analytics * * *"
98
105
 
99
- log = capture(
100
- "cd #{current_path} && git log #{previous_revision[0,7]}..#{current_revision[0,7]} --format=\"%s\" | grep -oh '#{jira_project_code}-[0-9]\\+' | sort | uniq"
101
- )
106
+ jira_project_code = fetch(:jira_project_code)
102
107
 
103
- options = {
104
- :ga_property => fetch(:ga_property),
105
- :ga_custom_1 => fetch(:ga_custom_1),
106
- :ga_custom_2 => fetch(:ga_custom_2),
107
- :domain => fetch(:domain),
108
- :current_revision => fetch(:current_revision),
109
- :previous_revision => fetch(:previous_revision),
110
- :branch => fetch(:branch, "default"),
111
- :stage => fetch(:stage),
112
- :tickets => Capistrano::Ghostinspector.getTickets(log)
113
- }
108
+ log = capture(
109
+ "cd #{current_path} && git log #{previous_revision[0,7]}..#{current_revision[0,7]} --format=\"%s\" | grep -oh '#{jira_project_code}-[0-9]\\+' | sort | uniq"
110
+ )
114
111
 
115
- analytics = Analytics.new(options)
112
+ options = {
113
+ :ga_property => fetch(:ga_property),
114
+ :ga_custom_1 => fetch(:ga_custom_1),
115
+ :ga_custom_2 => fetch(:ga_custom_2),
116
+ :domain => fetch(:domain),
117
+ :current_revision => fetch(:current_revision),
118
+ :previous_revision => fetch(:previous_revision),
119
+ :branch => fetch(:branch, "default"),
120
+ :stage => fetch(:stage),
121
+ :tickets => Capistrano::Ghostinspector.getTickets(log)
122
+ }
123
+
124
+ analytics = Analytics.new(options)
125
+
126
+ @collection.each do |item|
127
+ analytics.pushData(item[:type], item[:results])
128
+ end
116
129
 
117
- @collection.each do |item|
118
- analytics.pushData(item[:type], item[:results])
119
130
  end
120
131
 
121
132
  end
@@ -123,22 +134,25 @@ module Capistrano
123
134
  desc "Finalise Ghost Inspector Run"
124
135
  task :finalise_run, :only => { :primary => true } do
125
136
 
126
- set :passing, true
127
- @collection.each do |item|
128
- if item[:passing] == false
129
- set :passing, false
137
+ if (fetch(:gi_enabled) == true)
138
+ set :passing, true
139
+ @collection.each do |item|
140
+ if item[:passing] == false
141
+ set :passing, false
142
+ end
130
143
  end
131
- end
132
144
 
133
- # If any test fails and the stage allows rollbacks then
134
- # rollback to previous version.
135
- if (fetch(:passing) == false && fetch(:rollback) == true)
136
- puts "* * * Ghost Inspector Failed. Rolling back * * *"
137
- run_locally %{cap #{stage} deploy:rollback}
138
- else
139
- puts "* * * Ghost Inspector Complete. Deployment Complete * * *"
140
- end
145
+ # If any test fails and the stage allows rollbacks then
146
+ # rollback to previous version.
147
+ if (fetch(:passing) == false && fetch(:rollback) == true)
148
+ puts "* * * Ghost Inspector Failed. Rolling back * * *"
149
+ run_locally %{cap #{stage} deploy:rollback}
150
+ else
151
+ puts "* * * Ghost Inspector Complete. Deployment Complete * * *"
152
+ end
141
153
 
154
+ end
155
+
142
156
  end
143
157
 
144
158
  end
@@ -5,11 +5,11 @@ module Capistrano
5
5
  module Ghostinspector
6
6
  class Api
7
7
 
8
- def initialize(gi_api_key, domain, rollback, ga_property)
8
+ def initialize(gi_api_key, domain, rollback, ga_enabled)
9
9
  @apiKey = gi_api_key
10
10
  @domain = domain
11
11
  @rollback = rollback
12
- @ga_property = ga_property
12
+ @ga_enabled = ga_enabled
13
13
 
14
14
  # Determine if we should get results to
15
15
  # check for any failed tests
@@ -23,12 +23,12 @@ module Capistrano
23
23
  passing = true
24
24
 
25
25
  # ------ TESTING ONLY ------
26
- # results = JSON.parse(File.read("gitestresults.json"))
26
+ results = JSON.parse(File.read("gitestresults.json"))
27
27
  # results = JSON.parse(File.read("suiteresults.json"))
28
28
  # ------ TESTING ONLY ------
29
29
 
30
30
  # # Perform the API request and get the results
31
- results = sendRequest(type, test)
31
+ # results = sendRequest(type, test)
32
32
 
33
33
  # Check the data returned for failed tests
34
34
  if (@rollback == true)
@@ -49,7 +49,7 @@ module Capistrano
49
49
 
50
50
  # Determine if we should get results to
51
51
  # check for any failed tests
52
- if (@rollback == false && @ga_property == "")
52
+ if (@rollback == false && @ga_enabled == false)
53
53
  immediate = "&immediate=1"
54
54
  else
55
55
  immediate = ""
@@ -60,8 +60,11 @@ module Capistrano
60
60
  end
61
61
 
62
62
  def sendRequest(type, test)
63
+ uri = URI("https://api.ghostinspector.com/v1/#{type}/#{test}/execute/?apiKey=#{@apiKey}#{@immediate}")
63
64
 
64
- uri = URI("https://api.ghostinspector.com/v1/#{type}/#{test}/execute/?apiKey=#{@apiKey}&startUrl=http://#{@domain}/#{@immediate}")
65
+ if (@domain != nil)
66
+ uri.query = [uri.query, "startUrl=http://#{@domain}/"].compact.join('&')
67
+ end
65
68
 
66
69
  Net::HTTP.start(uri.host, uri.port,
67
70
  :use_ssl => uri.scheme == 'https') do |http|
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Ghostinspector
3
- VERSION = "0.4.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-ghostinspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Richardson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-12 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano