percy-client 0.8.0 → 0.9.0

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: 5df2807d5bef5b5b77ca00292bb84ebe7f7fd83d
4
- data.tar.gz: 783f788102ad2f7c36e3118b3a41e67e97d21fd5
3
+ metadata.gz: bc578e0917f5911a1aa66074c6b3df2cfd29f13b
4
+ data.tar.gz: e8018bcffe5f1023331a360f6e3c1137409e15e9
5
5
  SHA512:
6
- metadata.gz: 26e5228491098661a2338a110da7f2f2fad75273d12a6649221be1ec489eee7f25e2a52b4f1814f1032326ca3eadffb0e2d0998e672416c8c2626d45d11e84a0
7
- data.tar.gz: dbc6d60778ace333d3378f539617f1922c550c55618466c62f5ba4a43964fdd682369186916900591557d33d56d234e53e1ef30ddb3ea952725d3b096ec326e9
6
+ metadata.gz: f2fd7787234164b43c0ba7b9cc65a5414f374b7515f7ae397cbcb2de889020f1bb55678876433ab166c4be29418b00b4260ed8e55141deff7da6383c2ec820a6
7
+ data.tar.gz: e6b211360bd8650475918f344f9f810349407e0f1a961d97fdd5f56e9214062de4e95390128d9d60aaf2350a518ad511ee591687a01b4d95d74b35e975ced155
@@ -6,6 +6,13 @@ module Percy
6
6
  Percy::Client::Environment.pull_request_number
7
7
  commit_data = options[:commit_data] || Percy::Client::Environment.commit
8
8
  resources = options[:resources]
9
+ parallel_nonce = options[:parallel_nonce] || Percy::Client::Environment.parallel_nonce
10
+ parallel_total_shards = options[:parallel_total_shards] \
11
+ || Percy::Client::Environment.parallel_total_shards
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.')
15
+ end
9
16
 
10
17
  data = {
11
18
  'data' => {
@@ -20,6 +27,8 @@ module Percy
20
27
  'commit-committer-email' => commit_data[:committer_email],
21
28
  'commit-message' => commit_data[:message],
22
29
  'pull-request-number' => pull_request_number,
30
+ 'parallel-nonce' => parallel_nonce,
31
+ 'parallel-total-shards' => parallel_total_shards,
23
32
  },
24
33
  }
25
34
  }
@@ -41,6 +50,12 @@ module Percy
41
50
 
42
51
  build_data = post("#{config.api_url}/repos/#{repo}/builds/", data)
43
52
  Percy.logger.debug { "Build #{build_data['data']['id']} created" }
53
+ parallelism_msg = if parallel_total_shards
54
+ "#{parallel_total_shards} shards detected (nonce: #{parallel_nonce.inspect})"
55
+ else
56
+ 'not detected'
57
+ end
58
+ Percy.logger.debug { "Parallel test environment: #{parallelism_msg}" }
44
59
  build_data
45
60
  end
46
61
 
@@ -156,6 +156,14 @@ module Percy
156
156
  end
157
157
  end
158
158
 
159
+ def self.parallel_nonce
160
+ return ENV['PERCY_PARALLEL_NONCE'] if ENV['PERCY_PARALLEL_NONCE']
161
+ end
162
+
163
+ def self.parallel_total_shards
164
+ return Integer(ENV['PERCY_PARALLEL_TOTAL']) if ENV['PERCY_PARALLEL_TOTAL']
165
+ end
166
+
159
167
  # @private
160
168
  def self._get_origin_url
161
169
  `git config --get remote.origin.url`
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
@@ -33,6 +33,16 @@ RSpec.describe Percy::Client::Builds, :vcr do
33
33
  expect(build['data']['relationships']['missing-resources']['data']).to be
34
34
  expect(build['data']['relationships']['missing-resources']['data'].length).to eq(1)
35
35
  end
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)
44
+ end
45
+ end
36
46
  end
37
47
  describe '#finalize_build' do
38
48
  it 'finalizes a build' do
@@ -5,6 +5,8 @@ RSpec.describe Percy::Client::Environment do
5
5
  ENV['PERCY_BRANCH'] = nil
6
6
  ENV['PERCY_PULL_REQUEST'] = nil
7
7
  ENV['PERCY_REPO_SLUG'] = nil
8
+ ENV['PERCY_PARALLEL_NONCE'] = nil
9
+ ENV['PERCY_PARALLEL_TOTAL'] = nil
8
10
 
9
11
  # Unset Travis vars.
10
12
  ENV['TRAVIS_BUILD_ID'] = nil
@@ -139,6 +141,24 @@ RSpec.describe Percy::Client::Environment do
139
141
  Percy::Client::Environment::RepoNotFoundError)
140
142
  end
141
143
  end
144
+ describe '#parallel_nonce' do
145
+ it 'returns nil' do
146
+ expect(Percy::Client::Environment.parallel_nonce).to be_nil
147
+ end
148
+ it 'can be set with environment var' do
149
+ ENV['PERCY_PARALLEL_NONCE'] = 'nonce'
150
+ expect(Percy::Client::Environment.parallel_nonce).to eq('nonce')
151
+ end
152
+ end
153
+ describe '#parallel_total_shards' do
154
+ it 'returns nil' do
155
+ expect(Percy::Client::Environment.parallel_nonce).to be_nil
156
+ end
157
+ it 'can be set with environment var' do
158
+ ENV['PERCY_PARALLEL_TOTAL'] = '3'
159
+ expect(Percy::Client::Environment.parallel_total_shards).to eq(3)
160
+ end
161
+ end
142
162
  end
143
163
  context 'in Jenkins CI' do
144
164
  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.8.0
4
+ version: 0.9.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-01 00:00:00.000000000 Z
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday