percy-client 0.9.0 → 0.10.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: bc578e0917f5911a1aa66074c6b3df2cfd29f13b
4
- data.tar.gz: e8018bcffe5f1023331a360f6e3c1137409e15e9
3
+ metadata.gz: 5cb1162a266bd022d172fd7f3480434d70a32c64
4
+ data.tar.gz: fd764e8b3a6a1474ffa6f59e1bb54765c6e20ae6
5
5
  SHA512:
6
- metadata.gz: f2fd7787234164b43c0ba7b9cc65a5414f374b7515f7ae397cbcb2de889020f1bb55678876433ab166c4be29418b00b4260ed8e55141deff7da6383c2ec820a6
7
- data.tar.gz: e6b211360bd8650475918f344f9f810349407e0f1a961d97fdd5f56e9214062de4e95390128d9d60aaf2350a518ad511ee591687a01b4d95d74b35e975ced155
6
+ metadata.gz: 16d2abf05c798b824d7e3387b1404df556596fa4c52652571075572a69d34e6cd7f9a18f533ffe79c262dbd28068a150593eb41fe761de04b41038f9fa29a61a
7
+ data.tar.gz: a2d8c8e124c448f6fd99da12d85b1b26e9fba3b295ec20a9022df370dea539d06ea528064ccc949841823971a74c7e7cf476da19d0198990a0cb668f07b78a8a
@@ -10,8 +10,12 @@ module Percy
10
10
  parallel_total_shards = options[:parallel_total_shards] \
11
11
  || Percy::Client::Environment.parallel_total_shards
12
12
 
13
- if (parallel_nonce && !parallel_total_shards) || (!parallel_nonce && parallel_total_shards)
14
- raise ArgumentError.new('If parallel_nonce is given, parallel_total_shards is required.')
13
+ # Only pass parallelism data if it all exists and there is more than 1 shard.
14
+ in_parallel_environment = parallel_nonce && \
15
+ parallel_total_shards && parallel_total_shards > 1
16
+ if !in_parallel_environment
17
+ parallel_nonce = nil
18
+ parallel_total_shards = nil
15
19
  end
16
20
 
17
21
  data = {
@@ -156,12 +156,24 @@ module Percy
156
156
  end
157
157
  end
158
158
 
159
+ # A nonce which will be the same for all nodes of a parallel build, used to identify shards
160
+ # of the same CI build. This is usually just the CI environment build ID.
159
161
  def self.parallel_nonce
160
162
  return ENV['PERCY_PARALLEL_NONCE'] if ENV['PERCY_PARALLEL_NONCE']
163
+
164
+ case current_ci
165
+ when :circle
166
+ ENV['CIRCLE_BUILD_NUM']
167
+ end
161
168
  end
162
169
 
163
170
  def self.parallel_total_shards
164
171
  return Integer(ENV['PERCY_PARALLEL_TOTAL']) if ENV['PERCY_PARALLEL_TOTAL']
172
+
173
+ case current_ci
174
+ when :circle
175
+ Integer(ENV['CIRCLE_NODE_TOTAL']) if !ENV['CIRCLE_NODE_TOTAL'].empty?
176
+ end
165
177
  end
166
178
 
167
179
  # @private
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '0.9.0'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
  end
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/api/v1/repos/fotinakis/percy-examples/builds/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"data":{"type":"builds","attributes":{"commit-sha":"fc4d2c2e6b55d995a005dba2d071e2f2fca5e04b","commit-branch":"master","commit-committed-at":"2015-06-09
9
+ 23:22:31 -0700","commit-author-name":"<COMMIT_AUTHOR_NAME>","commit-author-email":"<COMMIT_AUTHOR_EMAIL>","commit-committer-name":"<COMMIT_AUTHOR_NAME>","commit-committer-email":"<COMMIT_AUTHOR_EMAIL>","commit-message":"Fix
10
+ test environment issue.","pull-request-number":"123","parallel-nonce":"nonce","parallel-total-shards":2}}}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept:
15
+ - "*/*"
16
+ Date:
17
+ - Thu, 11 Jun 2015 00:20:38 GMT
18
+ Content-Type:
19
+ - application/vnd.api+json
20
+ Authorization:
21
+ - Token token="<FILTERED_PERCY_TOKEN>"
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: Created
26
+ headers:
27
+ Date:
28
+ - Thu, 11 Jun 2015 00:20:39 GMT
29
+ Status:
30
+ - 201 Created
31
+ Connection:
32
+ - close
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ Access-Control-Allow-Origin:
40
+ - "*"
41
+ Access-Control-Allow-Methods:
42
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
43
+ Access-Control-Allow-Headers:
44
+ - Authorization, Content-Type
45
+ Cache-Control:
46
+ - no-cache, no-store, max-age=0, must-revalidate
47
+ Expires:
48
+ - Thu, 01 Jan 1970 00:00:00 GMT
49
+ Content-Type:
50
+ - application/json; charset=utf-8
51
+ X-Request-Id:
52
+ - 446304d0-e682-46b1-b0c0-39eefc375c40
53
+ X-Runtime:
54
+ - '0.422910'
55
+ Transfer-Encoding:
56
+ - chunked
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"data":{"id":"31","type":"builds","attributes":{"build-number":31,"state":"pending","is-pull-request":true,"pull-request-number":123,"pull-request-title":null,"approved-at":null,"parallel-nonce":"nonce","parallel-total-shards":2,"created-at":"2015-06-11T00:20:38.926Z","updated-at":"2015-06-11T00:20:38.926Z"},"links":{"self":"/api/v1/builds/31"},"relationships":{"commit":{"links":{"self":"/api/v1/builds/31/relationships/commit","related":"/api/v1/builds/31/commit"},"data":{"type":"commits","id":"2"}},"repo":{"links":{"self":"/api/v1/builds/31/relationships/repo","related":"/api/v1/builds/31/repo"}},"base-build":{"links":{"self":"/api/v1/builds/31/relationships/base-build","related":"/api/v1/builds/31/base-build"},"data":{"type":"builds","id":"29"}},"approved-by":{"links":{"self":"/api/v1/builds/31/relationships/approved-by","related":"/api/v1/builds/31/approved-by"}},"snapshots":{"links":{"self":"/api/v1/builds/31/relationships/snapshots","related":"/api/v1/builds/31/snapshots"}},"comparisons":{"links":{"self":"/api/v1/builds/31/relationships/comparisons","related":"/api/v1/builds/31/comparisons"}},"missing-resources":{"links":{"self":"/api/v1/builds/31/relationships/missing-resources","related":"/api/v1/builds/31/missing-resources"}}},"meta":{"finalize-link":"/api/v1/builds/31/finalize","approve-link":"/api/v1/builds/31/approve"}},"included":[{"id":"2","type":"commits","attributes":{"sha":"fc4d2c2e6b55d995a005dba2d071e2f2fca5e04b","branch":"master","message":"Fix
60
+ test environment issue.","committed-at":"2015-06-09 23:22:31 -0700","author-name":"<COMMIT_AUTHOR_NAME>","committer-name":"<COMMIT_AUTHOR_NAME>","created-at":"2015-06-11T00:15:24.000Z","updated-at":"2015-06-11T00:15:24.000Z"},"links":{"self":"/api/v1/commits/2"}},{"id":"29","type":"builds","attributes":{"build-number":29,"state":"finished","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-06-11T00:20:38.000Z","updated-at":"2015-06-11T00:20:38.000Z"},"links":{"self":"/api/v1/builds/29"},"relationships":{"commit":{"links":{"self":"/api/v1/builds/29/relationships/commit","related":"/api/v1/builds/29/commit"},"data":{"type":"commits","id":"2"}},"repo":{"links":{"self":"/api/v1/builds/29/relationships/repo","related":"/api/v1/builds/29/repo"}},"base-build":{"links":{"self":"/api/v1/builds/29/relationships/base-build","related":"/api/v1/builds/29/base-build"}},"approved-by":{"links":{"self":"/api/v1/builds/29/relationships/approved-by","related":"/api/v1/builds/29/approved-by"}},"snapshots":{"links":{"self":"/api/v1/builds/29/relationships/snapshots","related":"/api/v1/builds/29/snapshots"}},"comparisons":{"links":{"self":"/api/v1/builds/29/relationships/comparisons","related":"/api/v1/builds/29/comparisons"}},"missing-resources":{"links":{"self":"/api/v1/builds/29/relationships/missing-resources","related":"/api/v1/builds/29/missing-resources"}}},"meta":{"finalize-link":"/api/v1/builds/29/finalize","approve-link":"/api/v1/builds/29/approve"}}]}'
61
+ http_version:
62
+ recorded_at: Thu, 11 Jun 2015 00:20:39 GMT
63
+ recorded_with: VCR 2.9.3
@@ -34,13 +34,14 @@ RSpec.describe Percy::Client::Builds, :vcr do
34
34
  expect(build['data']['relationships']['missing-resources']['data'].length).to eq(1)
35
35
  end
36
36
  context 'parallel test environment' do
37
- it 'raises an error if either parallel_nonce or parallel_total_shards is given alone' do
38
- expect do
39
- Percy.create_build('fotinakis/percy-examples', parallel_nonce: 123)
40
- end.to raise_error(ArgumentError)
41
- expect do
42
- Percy.create_build('fotinakis/percy-examples', parallel_total_shards: 2)
43
- end.to raise_error(ArgumentError)
37
+ it 'passes through parallelism variables' do
38
+ build = Percy.create_build(
39
+ 'fotinakis/percy-examples',
40
+ parallel_nonce: 'nonce',
41
+ parallel_total_shards: 2,
42
+ )
43
+ expect(build['data']['attributes']['parallel-nonce']).to eq('nonce')
44
+ expect(build['data']['attributes']['parallel-total-shards']).to eq(2)
44
45
  end
45
46
  end
46
47
  end
@@ -27,6 +27,7 @@ RSpec.describe Percy::Client::Environment do
27
27
  ENV['CIRCLE_BRANCH'] = nil
28
28
  ENV['CIRCLE_PROJECT_USERNAME'] = nil
29
29
  ENV['CIRCLE_PROJECT_REPONAME'] = nil
30
+ ENV['CIRCLE_BUILD_NUM'] = nil
30
31
  ENV['CI_PULL_REQUESTS'] = nil
31
32
 
32
33
  # Unset Codeship vars.
@@ -236,6 +237,8 @@ RSpec.describe Percy::Client::Environment do
236
237
  ENV['CIRCLE_SHA1'] = 'circle-commit-sha'
237
238
  ENV['CIRCLE_PROJECT_USERNAME'] = 'circle'
238
239
  ENV['CIRCLE_PROJECT_REPONAME'] = 'repo-name'
240
+ ENV['CIRCLE_BUILD_NUM'] = 'build-number'
241
+ ENV['CIRCLE_NODE_TOTAL'] = '2'
239
242
  ENV['CI_PULL_REQUESTS'] = 'https://github.com/owner/repo-name/pull/123'
240
243
  end
241
244
 
@@ -265,6 +268,20 @@ RSpec.describe Percy::Client::Environment do
265
268
  expect(Percy::Client::Environment.repo).to eq('circle/repo-name')
266
269
  end
267
270
  end
271
+ describe '#parallel_nonce' do
272
+ it 'reads from the CI environment (the CI build ID)' do
273
+ expect(Percy::Client::Environment.parallel_nonce).to eq('build-number')
274
+ end
275
+ end
276
+ describe '#parallel_total_shards' do
277
+ it 'reads from the CI environment (the number of nodes)' do
278
+ expect(Percy::Client::Environment.parallel_total_shards).to eq(2)
279
+ end
280
+ it 'is nil if empty' do
281
+ ENV['CIRCLE_NODE_TOTAL'] = ''
282
+ expect(Percy::Client::Environment.parallel_total_shards).to be_nil
283
+ end
284
+ end
268
285
  end
269
286
  context 'in Codeship' do
270
287
  before(:each) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-05 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -135,6 +135,7 @@ files:
135
135
  - percy-client.gemspec
136
136
  - spec/cassettes/Percy_Client_Builds/_create_build/accepts_optional_resources.yml
137
137
  - spec/cassettes/Percy_Client_Builds/_create_build/creates_a_build.yml
138
+ - spec/cassettes/Percy_Client_Builds/_create_build/parallel_test_environment/passes_through_parallelism_variables.yml
138
139
  - spec/cassettes/Percy_Client_Builds/_finalize_build/finalizes_a_build.yml
139
140
  - spec/cassettes/Percy_Client_Resources/_upload_resource/returns_true_with_success.yml
140
141
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/creates_a_snapshot.yml
@@ -176,6 +177,7 @@ summary: Percy::Client
176
177
  test_files:
177
178
  - spec/cassettes/Percy_Client_Builds/_create_build/accepts_optional_resources.yml
178
179
  - spec/cassettes/Percy_Client_Builds/_create_build/creates_a_build.yml
180
+ - spec/cassettes/Percy_Client_Builds/_create_build/parallel_test_environment/passes_through_parallelism_variables.yml
179
181
  - spec/cassettes/Percy_Client_Builds/_finalize_build/finalizes_a_build.yml
180
182
  - spec/cassettes/Percy_Client_Resources/_upload_resource/returns_true_with_success.yml
181
183
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/creates_a_snapshot.yml