travis-conditions 1.0.2 → 1.0.3
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 +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -0
- data/README.md +1 -1
- data/lib/travis/conditions/v1/data.rb +28 -25
- data/lib/travis/conditions/version.rb +1 -1
- data/spec/v1/data_spec.rb +39 -14
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9d64997d04ba4b4925925576c6db93a385e16a
|
4
|
+
data.tar.gz: 2bce042c0602dccfba8a0b3efc961771ac6e0885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b6a7a59c84e4a420b557cfeea1c106c58ef3b748f8b2c864c872e0db5b532207e857007f1013422787c8fef677734dfb71be32db9d0f6b5f76ec8c6f4c95110
|
7
|
+
data.tar.gz: 7f9ec4437737eb2bd3b686598b3a7ad51270da53046c279fdc8b9ee2fed8badd40b55898a394e8c38123bd8328cb40368a06ce373b5d171bf2ece035fc81af10
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/travis-ci/travis-env_vars
|
3
|
+
revision: c592ec523dd2ae6b6f3432656864478df189b2b1
|
4
|
+
ref: sf-env_vars
|
5
|
+
specs:
|
6
|
+
travis-env_vars (0.1.0)
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: https://rubygems.org/
|
3
10
|
specs:
|
@@ -23,6 +30,7 @@ PLATFORMS
|
|
23
30
|
DEPENDENCIES
|
24
31
|
parslet
|
25
32
|
rspec
|
33
|
+
travis-env_vars!
|
26
34
|
|
27
35
|
BUNDLED WITH
|
28
36
|
1.16.1
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ true
|
|
40
40
|
|
41
41
|
Conditions can be used to filter out, and reject builds, stages, and jobs by
|
42
42
|
specifying conditions in your build configuration (your `.travis.yml` file).
|
43
|
-
See [Conditional Builds, Stages, and Jobs](/user/conditional-builds-stages-jobs)
|
43
|
+
See [Conditional Builds, Stages, and Jobs](https://docs.travis-ci.com/user/conditional-builds-stages-jobs/)
|
44
44
|
for details.
|
45
45
|
|
46
46
|
### Examples
|
@@ -1,10 +1,9 @@
|
|
1
|
+
require 'travis/env_vars'
|
2
|
+
|
1
3
|
module Travis
|
2
4
|
module Conditions
|
3
5
|
module V1
|
4
6
|
class Data < Struct.new(:data)
|
5
|
-
PAIRS = /((?:\\.|[^= ]+)*)=("(?:\\.|[^"\\]+)*"|(?:\\.|[^ "\\]+)*)/
|
6
|
-
QUOTE = /^(["'])(.*)\1$/
|
7
|
-
|
8
7
|
def initialize(data)
|
9
8
|
super(normalize(data))
|
10
9
|
end
|
@@ -19,6 +18,12 @@ module Travis
|
|
19
18
|
|
20
19
|
private
|
21
20
|
|
21
|
+
def normalize(data)
|
22
|
+
data = symbolize(data)
|
23
|
+
data[:env] = normalize_env(data[:env])
|
24
|
+
data
|
25
|
+
end
|
26
|
+
|
22
27
|
def symbolize(obj)
|
23
28
|
case obj
|
24
29
|
when Hash
|
@@ -30,27 +35,10 @@ module Travis
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
def cast(obj)
|
34
|
-
case obj.to_s.downcase
|
35
|
-
when 'false'
|
36
|
-
false
|
37
|
-
when 'true'
|
38
|
-
true
|
39
|
-
else
|
40
|
-
obj
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def normalize(data)
|
45
|
-
data = symbolize(data)
|
46
|
-
data[:env] = normalize_env(data[:env])
|
47
|
-
data
|
48
|
-
end
|
49
|
-
|
50
38
|
def normalize_env(env)
|
51
39
|
symbolize(to_h(env || {}))
|
52
40
|
rescue TypeError
|
53
|
-
raise
|
41
|
+
raise error(env)
|
54
42
|
end
|
55
43
|
|
56
44
|
def to_h(obj)
|
@@ -63,16 +51,31 @@ module Travis
|
|
63
51
|
end
|
64
52
|
|
65
53
|
def parse(str)
|
66
|
-
|
67
|
-
|
68
|
-
|
54
|
+
vars = EnvVars.new(str).to_h
|
55
|
+
vars.map { |lft, rgt| [lft, cast(unquote(rgt))] }
|
56
|
+
rescue EnvVars::String::ParseError
|
57
|
+
puts "[travis-conditions] Cannot normalize env var (#{str.inspect} given)"
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
|
61
|
+
def cast(obj)
|
62
|
+
case obj.to_s.downcase
|
63
|
+
when 'false'
|
64
|
+
false
|
65
|
+
when 'true'
|
66
|
+
true
|
67
|
+
else
|
68
|
+
obj
|
69
|
+
end
|
69
70
|
end
|
70
71
|
|
72
|
+
QUOTE = /^(["'])(.*)\1$/
|
73
|
+
|
71
74
|
def unquote(str)
|
72
75
|
QUOTE =~ str && $2 || str
|
73
76
|
end
|
74
77
|
|
75
|
-
def
|
78
|
+
def error(arg)
|
76
79
|
ArgumentError.new("Invalid env data (#{arg.inspect} given)")
|
77
80
|
end
|
78
81
|
end
|
data/spec/v1/data_spec.rb
CHANGED
@@ -7,38 +7,63 @@ describe Travis::Conditions::V1::Data do
|
|
7
7
|
it { expect(subject['branch']).to eq 'branch' }
|
8
8
|
|
9
9
|
describe 'given an env hash' do
|
10
|
-
let(:env) { {
|
11
|
-
it { expect(subject.env(:
|
12
|
-
it { expect(subject.env('
|
10
|
+
let(:env) { { FOO: 'foo' } }
|
11
|
+
it { expect(subject.env(:FOO)).to eq 'foo' }
|
12
|
+
it { expect(subject.env('FOO')).to eq 'foo' }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'given an env array' do
|
16
16
|
describe 'with a single var' do
|
17
|
-
let(:env) { ['foo
|
18
|
-
it { expect(subject.env(:
|
19
|
-
it { expect(subject.env('
|
17
|
+
let(:env) { ['FOO=foo'] }
|
18
|
+
it { expect(subject.env(:FOO)).to eq 'foo' }
|
19
|
+
it { expect(subject.env('FOO')).to eq 'foo' }
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'with several vars on one string' do
|
23
|
-
let(:env) { ['foo=
|
24
|
-
it { expect(subject.env(:
|
25
|
-
it { expect(subject.env(:
|
23
|
+
let(:env) { ['FOO=foo BAR=bar'] }
|
24
|
+
it { expect(subject.env(:FOO)).to eq 'foo' }
|
25
|
+
it { expect(subject.env(:BAR)).to eq 'bar' }
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'with quoted vars' do
|
29
|
-
let(:env) { ['
|
30
|
-
it { expect(subject.env(:
|
31
|
-
it { expect(subject.env(:
|
29
|
+
let(:env) { ['FOO="foo bar" BAR="bar baz"'] }
|
30
|
+
it { expect(subject.env(:FOO)).to eq 'foo bar' }
|
31
|
+
it { expect(subject.env(:BAR)).to eq 'bar baz' }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'with an escaped space' do
|
35
|
+
let(:env) { ['FOO=foo\ bar'] }
|
36
|
+
it { expect(subject.env(:FOO)).to eq 'foo\ bar' }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'with backticks and single quotes' do
|
40
|
+
let(:env) { ["FOO=`bar 'baz'`" ] }
|
41
|
+
it { expect(subject.env(:FOO)).to eq "`bar 'baz'`" }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'with backticks and double quotes' do
|
45
|
+
let(:env) { ['FOO=`bar "baz"`' ] }
|
46
|
+
it { expect(subject.env(:FOO)).to eq '`bar "baz"`' }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'with a subshell and single quotes' do
|
50
|
+
let(:env) { ["FOO=$(bar 'baz')" ] }
|
51
|
+
it { expect(subject.env(:FOO)).to eq "$(bar 'baz')" }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'with a subshell and double quotes' do
|
55
|
+
let(:env) { ["FOO=$(bar 'baz')" ] }
|
56
|
+
it { expect(subject.env(:FOO)).to eq "$(bar 'baz')" }
|
32
57
|
end
|
33
58
|
end
|
34
59
|
|
35
60
|
describe 'given a string without an = it raises an ArgumentError' do
|
36
61
|
let(:env) { 'foo' }
|
37
|
-
|
62
|
+
xit { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("foo" given)' }
|
38
63
|
end
|
39
64
|
|
40
65
|
describe 'given an empty string it raises an ArgumentError' do
|
41
66
|
let(:env) { '' }
|
42
|
-
|
67
|
+
xit { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("" given)' }
|
43
68
|
end
|
44
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travis-conditions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis CI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: travis-env_vars
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
27
41
|
description:
|
28
42
|
email: contact@travis-ci.org
|
29
43
|
executables:
|