percy-common 3.0.0 → 3.1.2.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +12 -0
- data/RELEASING.md +7 -10
- data/lib/percy/common/version.rb +1 -1
- data/lib/percy/logger.rb +2 -1
- data/lib/percy/redis_client.rb +101 -0
- data/lib/percy/stats.rb +18 -2
- data/percy-common.gemspec +11 -9
- data/release.sh +64 -0
- metadata +42 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71a703d0ab1210e46a8650fca96cbba72578e3d95d68825ff7c415d2c4ac89b7
|
4
|
+
data.tar.gz: 3b66f2835412dfb59009fe71f7dd983b04e05921fabd204ce1fafab6a14742c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ecdee8f494735c6865d6fc75d059db6dd2a04d68a6988483145c8b03100b39a8e5b02a5b01167b5bdbc131881da528995515a10967259dca3d39a8814d1966d
|
7
|
+
data.tar.gz: 54401332070ec4a7c5c6fd3427447237578cb557c862d56177150fec97b7c69d3552d4d81ea93a27c2ba5940c392315ba862a5c4ea1b145f28a0a7b9555c1c69
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-04-30 16:00:36 -0700 using RuboCop version 0.77.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
RSpec/LeakyConstantDeclaration:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/percy/keyword_struct_spec.rb'
|
data/RELEASING.md
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# Releasing
|
2
2
|
|
3
|
-
1.
|
4
|
-
1.
|
5
|
-
1. `git add lib/percy/common/version.rb`
|
6
|
-
1. `git commit -m "version bump to X.X.X"`
|
7
|
-
1. `git push origin master`
|
8
|
-
1. `git tag vX.X.X`
|
9
|
-
1. `git push --tags`
|
10
|
-
1. `bundle exec rake build`
|
11
|
-
1. `gem push pkg/percy-common-X.X.X.gem`
|
3
|
+
1. Ensure you are on the expected branch (presumably `master`) and the current branch is up-to-date.
|
4
|
+
1. Run `./release.sh`
|
12
5
|
1. Visit [RubyGems.org](https://rubygems.org/gems/percy-common) and see the gem has been published
|
13
|
-
|
6
|
+
|
7
|
+
# Creating a Release on GitHub
|
8
|
+
|
9
|
+
Finish the pre-started release opened by the script, or [create a new release](https://github.com/percy/percy-common/releases/new):
|
10
|
+
|
14
11
|
1. Enter "vX.X.X" as the tag version. It should auto complete to say "Existing Tag"
|
15
12
|
1. Enter "vX.X.X" as the release title
|
16
13
|
1. Write a brief description as to what is included in this release. Linking to specific PRs is great.
|
data/lib/percy/common/version.rb
CHANGED
data/lib/percy/logger.rb
CHANGED
@@ -2,7 +2,8 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module Percy
|
4
4
|
def self.logger
|
5
|
-
@logger if defined?(@logger)
|
5
|
+
return @logger if defined?(@logger)
|
6
|
+
|
6
7
|
@logger ||= Logger.new(STDOUT)
|
7
8
|
@logger.level = Logger::INFO if ENV['PERCY_ENV'] == 'production'
|
8
9
|
@logger.formatter = proc do |severity, _datetime, _progname, msg|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
module Percy
|
6
|
+
class RedisClient
|
7
|
+
class InvalidConfiguration < ArgumentError
|
8
|
+
end
|
9
|
+
attr_reader :client
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(given_options = {})
|
13
|
+
@provided_options = given_options
|
14
|
+
@options = ssl_params.merge(given_options)
|
15
|
+
@client = ::Redis.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private def ssl_enabled?
|
19
|
+
provided_url.to_s.start_with?('rediss://')
|
20
|
+
end
|
21
|
+
|
22
|
+
private def provided_url
|
23
|
+
@provided_options&.dig(:url)
|
24
|
+
end
|
25
|
+
|
26
|
+
private def ssl_options
|
27
|
+
{
|
28
|
+
ssl: ssl_enabled?,
|
29
|
+
ssl_params: ssl_params,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
private def ssl_params
|
34
|
+
return {} unless ssl_enabled?
|
35
|
+
|
36
|
+
{
|
37
|
+
ca_file: certificate_authority,
|
38
|
+
cert: OpenSSL::X509::Certificate.new(client_certificate),
|
39
|
+
key: OpenSSL::PKey::RSA.new(private_key),
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
private def client_certificate
|
44
|
+
@provided_options&.dig(:ssl_params, :cert) ||
|
45
|
+
client_certificate_from_env ||
|
46
|
+
client_certificate_from_path
|
47
|
+
end
|
48
|
+
|
49
|
+
private def client_certificate_from_env
|
50
|
+
ENV['REDIS_SSL_CLIENT_CERTIFICATE']
|
51
|
+
end
|
52
|
+
|
53
|
+
private def client_certificate_from_path
|
54
|
+
File.read(fetch_key('REDIS_SSL_CLIENT_CERTIFICATE_PATH'))
|
55
|
+
end
|
56
|
+
|
57
|
+
private def private_key
|
58
|
+
provided_private_key ||
|
59
|
+
private_key_from_env ||
|
60
|
+
private_key_from_path
|
61
|
+
end
|
62
|
+
|
63
|
+
private def provided_private_key
|
64
|
+
@provided_options&.dig(:ssl_params, :key)
|
65
|
+
end
|
66
|
+
|
67
|
+
private def private_key_from_env
|
68
|
+
ENV['REDIS_SSL_PRIVATE_KEY']
|
69
|
+
end
|
70
|
+
|
71
|
+
private def private_key_from_path
|
72
|
+
File.read(fetch_key('REDIS_SSL_PRIVATE_KEY_PATH'))
|
73
|
+
end
|
74
|
+
|
75
|
+
private def certificate_authority
|
76
|
+
provided_certificate_authority ||
|
77
|
+
certificate_authority_from_env ||
|
78
|
+
certificate_authority_from_path
|
79
|
+
end
|
80
|
+
|
81
|
+
private def provided_certificate_authority
|
82
|
+
@provided_options&.dig(:ssl_params, :ca_file)
|
83
|
+
end
|
84
|
+
|
85
|
+
private def certificate_authority_from_env
|
86
|
+
ENV['REDIS_SSL_CERTIFICATE_AUTHORITY']
|
87
|
+
end
|
88
|
+
|
89
|
+
private def certificate_authority_from_path
|
90
|
+
File.read(fetch_key('REDIS_SSL_CERTIFICATE_AUTHORITY_PATH'))
|
91
|
+
end
|
92
|
+
|
93
|
+
private def fetch_key(key)
|
94
|
+
ENV.fetch(key) { missing_key(key) }
|
95
|
+
end
|
96
|
+
|
97
|
+
private def missing_key(key)
|
98
|
+
raise InvalidConfiguration, "#{key} is not defined"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/percy/stats.rb
CHANGED
@@ -44,15 +44,31 @@ module Percy
|
|
44
44
|
# Programmer mistake, so raise an error.
|
45
45
|
raise 'no timing started' unless @_timing_start
|
46
46
|
|
47
|
-
|
47
|
+
time_since_monotonic(stat, @_timing_start, options)
|
48
48
|
@_timing_start = nil
|
49
49
|
true
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
# dogstatsd uses a monotonic (linearly increasing) clock to calculate time
|
53
|
+
# intervals, so this should be used where necessary. However, it's not
|
54
|
+
# possible to compare monotonic time values with fixed times, so both are
|
55
|
+
# available.
|
56
|
+
def time_since_monotonic(stat, start, opts = {})
|
57
|
+
unless start.instance_of? Float
|
58
|
+
raise ArgumentError, 'start value must be Float'
|
59
|
+
end
|
60
|
+
|
53
61
|
timing(stat, ((now.to_f - start.to_f) * 1000).round, opts)
|
54
62
|
end
|
55
63
|
|
64
|
+
def time_since(stat, start, opts = {})
|
65
|
+
unless start.instance_of? Time
|
66
|
+
raise ArgumentError, 'start value must be Time'
|
67
|
+
end
|
68
|
+
|
69
|
+
timing(stat, ((Time.now.to_f - start.to_f) * 1000).round, opts)
|
70
|
+
end
|
71
|
+
|
56
72
|
private def now
|
57
73
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
58
74
|
end
|
data/percy-common.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'percy/common/version'
|
5
4
|
|
@@ -9,19 +8,22 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ['Perceptual Inc.']
|
10
9
|
spec.email = ['team@percy.io']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = 'Server-side common library for Percy.'
|
12
|
+
spec.description = ''
|
14
13
|
spec.homepage = ''
|
15
14
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(/^(test|spec|features)\//)
|
17
|
+
end
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
20
|
spec.add_dependency 'dogstatsd-ruby', '~> 4.4.0'
|
20
21
|
spec.add_dependency 'excon', '~> 0.57'
|
22
|
+
spec.add_dependency 'redis', '>= 4.1.3', '< 5.0.0'
|
21
23
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rspec', '~> 3.2'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.1.4'
|
25
25
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
26
|
-
spec.add_development_dependency 'percy-style', '~> 0.
|
26
|
+
spec.add_development_dependency 'percy-style', '~> 0.7.0'
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
27
29
|
end
|
data/release.sh
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
cd "$(dirname "$0")" || exit 1
|
6
|
+
CURDIR="$(pwd)"
|
7
|
+
|
8
|
+
PERCY_COMMON_VERSION="$(grep "VERSION" lib/percy/common/version.rb | awk -F "'" '{print $2}')"
|
9
|
+
|
10
|
+
echo "Current percy-common version: $PERCY_COMMON_VERSION"
|
11
|
+
|
12
|
+
if [[ $# -lt 1 ]]; then
|
13
|
+
echo "Usage $0 <version>"
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
|
17
|
+
rm "$CURDIR/"percy-common*.gem >/dev/null 2>&1 || true
|
18
|
+
|
19
|
+
delete_existing_version() {
|
20
|
+
git tag -d "v$1" || true
|
21
|
+
git push origin ":v$1" || true
|
22
|
+
gem yank "percy-common$1.gem" || true
|
23
|
+
}
|
24
|
+
|
25
|
+
if [[ $1 == 'delete' ]]; then
|
26
|
+
delete_existing_version "$PERCY_COMMON_VERSION"
|
27
|
+
else
|
28
|
+
CLEAN=$(
|
29
|
+
git diff-index --quiet HEAD --
|
30
|
+
echo $?
|
31
|
+
)
|
32
|
+
if [[ "$CLEAN" == "0" ]]; then
|
33
|
+
if [[ $1 == '--force' ]]; then
|
34
|
+
shift
|
35
|
+
if [[ -n $1 ]]; then
|
36
|
+
echo "Deleting version $1"
|
37
|
+
sleep 1
|
38
|
+
delete_existing_version "$1"
|
39
|
+
else
|
40
|
+
echo "Missing release version"
|
41
|
+
exit 1
|
42
|
+
fi
|
43
|
+
fi
|
44
|
+
VERSION=$1
|
45
|
+
echo "Releasing $VERSION"
|
46
|
+
sleep 1
|
47
|
+
|
48
|
+
sed -i "" -e "s/$PERCY_COMMON_VERSION/$VERSION/g" "lib/percy/common/version.rb"
|
49
|
+
git add "lib/percy/common/version.rb"
|
50
|
+
git commit -a -m "Release $VERSION" || true
|
51
|
+
|
52
|
+
git tag -a "v$VERSION" -m "$1" || true
|
53
|
+
git push origin "v$VERSION" || true
|
54
|
+
|
55
|
+
bundle exec rake build
|
56
|
+
gem push "$CURDIR/pkg/percy-common-$VERSION.gem"
|
57
|
+
open "https://github.com/percy/percy-common/releases/new?tag=v$VERSION&title=$VERSION"
|
58
|
+
rm "$CURDIR/pkg/percy-common-$VERSION.gem"
|
59
|
+
else
|
60
|
+
echo "Please commit your changes and try again"
|
61
|
+
exit 1
|
62
|
+
fi
|
63
|
+
fi
|
64
|
+
echo "Done"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.2.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dogstatsd-ruby
|
@@ -38,76 +38,96 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.57'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.1.3
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 5.0.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 4.1.3
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.0.0
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: bundler
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
65
|
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
67
|
+
version: 2.1.4
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
72
|
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
74
|
+
version: 2.1.4
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
76
|
+
name: guard-rspec
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
79
|
- - "~>"
|
60
80
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
81
|
+
version: '4.7'
|
62
82
|
type: :development
|
63
83
|
prerelease: false
|
64
84
|
version_requirements: !ruby/object:Gem::Requirement
|
65
85
|
requirements:
|
66
86
|
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
88
|
+
version: '4.7'
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
90
|
+
name: percy-style
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
72
92
|
requirements:
|
73
93
|
- - "~>"
|
74
94
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
95
|
+
version: 0.7.0
|
76
96
|
type: :development
|
77
97
|
prerelease: false
|
78
98
|
version_requirements: !ruby/object:Gem::Requirement
|
79
99
|
requirements:
|
80
100
|
- - "~>"
|
81
101
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
102
|
+
version: 0.7.0
|
83
103
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
104
|
+
name: rake
|
85
105
|
requirement: !ruby/object:Gem::Requirement
|
86
106
|
requirements:
|
87
107
|
- - "~>"
|
88
108
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
109
|
+
version: '12.3'
|
90
110
|
type: :development
|
91
111
|
prerelease: false
|
92
112
|
version_requirements: !ruby/object:Gem::Requirement
|
93
113
|
requirements:
|
94
114
|
- - "~>"
|
95
115
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
116
|
+
version: '12.3'
|
97
117
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
118
|
+
name: rspec
|
99
119
|
requirement: !ruby/object:Gem::Requirement
|
100
120
|
requirements:
|
101
121
|
- - "~>"
|
102
122
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
123
|
+
version: '3.2'
|
104
124
|
type: :development
|
105
125
|
prerelease: false
|
106
126
|
version_requirements: !ruby/object:Gem::Requirement
|
107
127
|
requirements:
|
108
128
|
- - "~>"
|
109
129
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
130
|
+
version: '3.2'
|
111
131
|
description: ''
|
112
132
|
email:
|
113
133
|
- team@percy.io
|
@@ -119,6 +139,7 @@ files:
|
|
119
139
|
- ".gitignore"
|
120
140
|
- ".rspec"
|
121
141
|
- ".rubocop.yml"
|
142
|
+
- ".rubocop_todo.yml"
|
122
143
|
- Gemfile
|
123
144
|
- Guardfile
|
124
145
|
- LICENSE
|
@@ -132,8 +153,10 @@ files:
|
|
132
153
|
- lib/percy/logger.rb
|
133
154
|
- lib/percy/network_helpers.rb
|
134
155
|
- lib/percy/process_helpers.rb
|
156
|
+
- lib/percy/redis_client.rb
|
135
157
|
- lib/percy/stats.rb
|
136
158
|
- percy-common.gemspec
|
159
|
+
- release.sh
|
137
160
|
homepage: ''
|
138
161
|
licenses: []
|
139
162
|
metadata: {}
|
@@ -148,12 +171,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
171
|
version: '0'
|
149
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
173
|
requirements:
|
151
|
-
- - "
|
174
|
+
- - ">"
|
152
175
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
176
|
+
version: 1.3.1
|
154
177
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.7.8
|
178
|
+
rubygems_version: 3.1.2
|
157
179
|
signing_key:
|
158
180
|
specification_version: 4
|
159
181
|
summary: Server-side common library for Percy.
|