travis-conditions 1.0.5 → 1.0.6
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/README.md +20 -5
- data/bin/travis-conditions +44 -11
- data/lib/travis/conditions/v1.rb +1 -0
- data/lib/travis/conditions/v1/parser.rb +4 -4
- data/lib/travis/conditions/v1/regex.rb +54 -0
- data/lib/travis/conditions/version.rb +1 -1
- data/spec/v1/data_spec.rb +1 -0
- data/spec/v1/parser/regex_spec.rb +40 -5
- data/spec/v1/user_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cb3e113cdc4a371a2fe5de849be3570fe8b606a
|
4
|
+
data.tar.gz: 3cb1e7b0112ac22b8b15462caa7df1bd6eb5876f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d7015a0e92d371d100731a2dbee62d207bbcd641d3752e14cafd88e518948558c6980d41402d14a689291a3b4ce1089bdf4291bc72f2dd7db0763ba7464eb03
|
7
|
+
data.tar.gz: a65d7844b120833b8ff4387481bc8bfa141a30dff599bcd21fe83a819d1621c9c17157ffb7e2645533bd6f28428b6ef8dbdbb09680003d1b509af6e35f7c4fbe
|
data/README.md
CHANGED
@@ -16,13 +16,28 @@ See [this file](https://github.com/travis-ci/travis-conditions/blob/master/lib/t
|
|
16
16
|
## CLI
|
17
17
|
|
18
18
|
With the gem installed you can use the command `travis-conditions` in order to
|
19
|
-
test your conditions locally.
|
19
|
+
test your conditions locally.
|
20
|
+
|
21
|
+
### parse
|
22
|
+
|
23
|
+
Check the syntax of a condition by inspecting the resulting abstract syntax
|
24
|
+
tree.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ travis-conditions eval "branch = foo"
|
28
|
+
[:eq, [:var, :branch], [:val, "foo"]]
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
### eval
|
33
|
+
|
34
|
+
Check conditions against a given data hash.
|
20
35
|
|
21
36
|
```
|
22
|
-
$ travis-conditions "branch = foo" --data '{"branch": "foo"}'
|
37
|
+
$ travis-conditions eval "branch = foo" --data '{"branch": "foo"}'
|
23
38
|
true
|
24
39
|
|
25
|
-
$ echo '{"branch": "foo"}' | travis-conditions "branch = foo"
|
40
|
+
$ echo '{"branch": "foo"}' | travis-conditions eval "branch = foo"
|
26
41
|
true
|
27
42
|
```
|
28
43
|
|
@@ -30,9 +45,9 @@ The given `data` hash can include known attributes (such as branch, tag, repo)
|
|
30
45
|
and an `env` key that can either hold a hash, or an array of strings:
|
31
46
|
|
32
47
|
```
|
33
|
-
$ travis-conditions "env(foo) = bar" --data '{"env": {"foo": "bar"}}'
|
48
|
+
$ travis-conditions eval "env(foo) = bar" --data '{"env": {"foo": "bar"}}'
|
34
49
|
true
|
35
|
-
$ travis-conditions "env(foo) = bar" --data '{"env": ["foo=bar"]}'
|
50
|
+
$ travis-conditions eval "env(foo) = bar" --data '{"env": ["foo=bar"]}'
|
36
51
|
true
|
37
52
|
```
|
38
53
|
|
data/bin/travis-conditions
CHANGED
@@ -4,20 +4,41 @@ $: << 'lib'
|
|
4
4
|
|
5
5
|
require 'json'
|
6
6
|
require 'optparse'
|
7
|
+
require 'pp'
|
7
8
|
require 'travis/conditions'
|
8
9
|
|
9
10
|
def help
|
10
|
-
abort <<~
|
11
|
-
|
12
|
-
travis-conditions "branch = master" --data '{"branch": "master"}'
|
13
|
-
travis-conditions echo '{"branch": "master"}' | travis-conditions "branch = master"
|
11
|
+
abort <<~str
|
12
|
+
SYNOPSIS:
|
14
13
|
|
15
|
-
|
16
|
-
repo) and an "env" key that can either hold a hash, or an array of strings:
|
14
|
+
travis-conditions <command>
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
COMMANDS:
|
17
|
+
|
18
|
+
parse
|
19
|
+
|
20
|
+
Validate the syntax of a condition, inspect the resulting abstract
|
21
|
+
syntax tree.
|
22
|
+
|
23
|
+
E.g.:
|
24
|
+
|
25
|
+
travis-conditions parse "branch = master"
|
26
|
+
|
27
|
+
eval
|
28
|
+
|
29
|
+
Validate the behavior of a condition, given an input data hash.
|
30
|
+
|
31
|
+
E.g.:
|
32
|
+
|
33
|
+
travis-conditions eval "branch = master" --data '{"branch": "master"}'
|
34
|
+
echo '{"branch": "master"}' | eval travis-conditions "branch = master"
|
35
|
+
|
36
|
+
The given data JSON hash can include known attributes (such as branch, tag,
|
37
|
+
repo) and an "env" key that can either hold a hash, or an array of strings:
|
38
|
+
|
39
|
+
{"env": {"foo": "bar"}}
|
40
|
+
{"env": ["foo=bar"]}
|
41
|
+
str
|
21
42
|
end
|
22
43
|
|
23
44
|
data = $stdin.read unless $stdin.tty?
|
@@ -28,7 +49,19 @@ ARGV.options do |opts|
|
|
28
49
|
opts.parse!
|
29
50
|
end
|
30
51
|
|
52
|
+
cmd = ARGV.shift
|
53
|
+
abort help unless cmd
|
54
|
+
|
31
55
|
cond = ARGV.shift
|
32
|
-
abort help unless cond && data
|
56
|
+
abort help unless cond && (cmd == 'parse' || data)
|
33
57
|
|
34
|
-
|
58
|
+
begin
|
59
|
+
case cmd
|
60
|
+
when 'parse'
|
61
|
+
pp Travis::Conditions.parse(cond, version: :v1)
|
62
|
+
when 'eval'
|
63
|
+
p Travis::Conditions.eval(cond, JSON.parse(data), version: :v1)
|
64
|
+
end
|
65
|
+
rescue Travis::Conditions::ParseError => e
|
66
|
+
abort e.message
|
67
|
+
end
|
data/lib/travis/conditions/v1.rb
CHANGED
@@ -66,7 +66,6 @@ module Travis
|
|
66
66
|
NRE = /!~/
|
67
67
|
COMMA = /,/
|
68
68
|
WORD = /[^\s\(\)"',=!]+/
|
69
|
-
REGEX = %r(/.+/|\S*[^\s\)]+)
|
70
69
|
CONT = /\\\s*[\n\r]/
|
71
70
|
|
72
71
|
OP = {
|
@@ -84,7 +83,7 @@ module Travis
|
|
84
83
|
shell_str: 'Strings cannot start with a dollar (shell code does not work). This can be bypassed by quoting the string.'
|
85
84
|
}
|
86
85
|
|
87
|
-
def_delegators :str, :scan, :skip, :string, :pos, :peek
|
86
|
+
def_delegators :str, :rest, :scan, :skip, :string, :pos, :peek
|
88
87
|
attr_reader :str
|
89
88
|
|
90
89
|
def initialize(str)
|
@@ -118,8 +117,9 @@ module Travis
|
|
118
117
|
def regex
|
119
118
|
val = call
|
120
119
|
return [:reg, val] if val
|
121
|
-
reg = space {
|
122
|
-
|
120
|
+
return unless reg = space { Regex.new(rest).scan }
|
121
|
+
str.pos = str.pos + reg.size
|
122
|
+
[:reg, reg.gsub(%r(^/|/$), '')] # or err('an operand')
|
123
123
|
end
|
124
124
|
|
125
125
|
def eq
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module Travis
|
5
|
+
module Conditions
|
6
|
+
module V1
|
7
|
+
class Regex
|
8
|
+
REGEX = %r(\S*[^\s\)]+)
|
9
|
+
DELIM = '/'
|
10
|
+
ESC = '\\'
|
11
|
+
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
def_delegators :str, :check, :eos?, :getch, :peek, :pos, :scan, :skip, :string
|
15
|
+
attr_reader :str
|
16
|
+
|
17
|
+
def initialize(str)
|
18
|
+
@str = StringScanner.new(str.to_s.strip)
|
19
|
+
@esc = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def scan
|
23
|
+
word || regex
|
24
|
+
end
|
25
|
+
|
26
|
+
def word
|
27
|
+
return if peek(1) == DELIM
|
28
|
+
str.scan(REGEX)
|
29
|
+
end
|
30
|
+
|
31
|
+
def regex
|
32
|
+
return unless peek(1) == DELIM && reg = getch
|
33
|
+
char = nil
|
34
|
+
reg << char while (char = read) && char != :eos
|
35
|
+
reg << DELIM if char == :eos
|
36
|
+
reg unless reg.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def read
|
40
|
+
char = peek(1)
|
41
|
+
if char == DELIM && !@esc
|
42
|
+
:eos
|
43
|
+
elsif char == ESC
|
44
|
+
@esc = true
|
45
|
+
getch
|
46
|
+
else
|
47
|
+
@esc = false
|
48
|
+
getch
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/v1/data_spec.rb
CHANGED
@@ -59,6 +59,7 @@ describe Travis::Conditions::V1::Data do
|
|
59
59
|
describe 'with a string and a secure env var' do
|
60
60
|
let(:env) { ["FOO=foo BAR=bar", { secure: '12345' }] }
|
61
61
|
it { expect(subject.env(:FOO)).to eq 'foo' }
|
62
|
+
it { expect(subject.env(:BAR)).to eq 'bar' }
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -1,12 +1,47 @@
|
|
1
1
|
describe Travis::Conditions::V1::Parser, 'regex' do
|
2
2
|
let(:str) { |e| e.description }
|
3
|
-
let(:subject) { described_class.new(str).
|
3
|
+
let(:subject) { described_class.new(str).parse }
|
4
4
|
|
5
|
-
it '^.*-
|
6
|
-
should eq [:reg, '^.*-
|
5
|
+
it 'branch =~ ^.*-foo$' do
|
6
|
+
should eq [:match, [:var, :branch], [:reg, '^.*-foo$']]
|
7
7
|
end
|
8
8
|
|
9
|
-
it '/^.*
|
10
|
-
should eq [:reg, '^.*
|
9
|
+
it 'branch =~ /^.* foo$/' do
|
10
|
+
should eq [:match, [:var, :branch], [:reg, '^.* foo$']]
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'branch =~ /foo/ OR tag =~ /^foo$/' do
|
14
|
+
should eq [:or,
|
15
|
+
[:match, [:var, :branch], [:reg, 'foo']],
|
16
|
+
[:match, [:var, :tag], [:reg, '^foo$']]
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'branch =~ /foo/ OR (tag =~ /^foo$/)' do
|
21
|
+
should eq [:or,
|
22
|
+
[:match, [:var, :branch], [:reg, 'foo']],
|
23
|
+
[:match, [:var, :tag], [:reg, '^foo$']]
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Travis::Conditions::V1::Regex do
|
29
|
+
let(:str) { |e| e.description }
|
30
|
+
let(:subject) { described_class.new(str).scan }
|
31
|
+
|
32
|
+
it '^.*-foo$' do
|
33
|
+
should eq '^.*-foo$'
|
34
|
+
end
|
35
|
+
|
36
|
+
it '/^.* foo$/' do
|
37
|
+
should eq '/^.* foo$/'
|
38
|
+
end
|
39
|
+
|
40
|
+
it '/^(develop|master|release\/.*)$/' do
|
41
|
+
should eq '/^(develop|master|release\/.*)$/'
|
42
|
+
end
|
43
|
+
|
44
|
+
it '/^(develop|master|release\/.*|feature\/.*)$/' do
|
45
|
+
should eq '/^(develop|master|release\/.*|feature\/.*)$/'
|
11
46
|
end
|
12
47
|
end
|
data/spec/v1/user_spec.rb
CHANGED
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.6
|
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-
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/travis/conditions/v1/eval.rb
|
64
64
|
- lib/travis/conditions/v1/helper.rb
|
65
65
|
- lib/travis/conditions/v1/parser.rb
|
66
|
+
- lib/travis/conditions/v1/regex.rb
|
66
67
|
- lib/travis/conditions/version.rb
|
67
68
|
- spec/conditions_spec.rb
|
68
69
|
- spec/spec_helper.rb
|