travis-yaml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +14 -0
  5. data/Gemfile +9 -0
  6. data/Gemfile.lock +73 -0
  7. data/LICENSE +22 -0
  8. data/README.md +232 -0
  9. data/Rakefile +3 -0
  10. data/SPEC.md +1018 -0
  11. data/bench/parser_bench.rb +54 -0
  12. data/config.ru +2 -0
  13. data/lib/travis/yaml.rb +43 -0
  14. data/lib/travis/yaml/matrix.rb +65 -0
  15. data/lib/travis/yaml/nodes.rb +40 -0
  16. data/lib/travis/yaml/nodes/branches.rb +12 -0
  17. data/lib/travis/yaml/nodes/bundler_args.rb +6 -0
  18. data/lib/travis/yaml/nodes/cache.rb +29 -0
  19. data/lib/travis/yaml/nodes/compiler.rb +7 -0
  20. data/lib/travis/yaml/nodes/compiler_entry.rb +9 -0
  21. data/lib/travis/yaml/nodes/deploy.rb +7 -0
  22. data/lib/travis/yaml/nodes/deploy_conditions.rb +12 -0
  23. data/lib/travis/yaml/nodes/deploy_entry.rb +10 -0
  24. data/lib/travis/yaml/nodes/env.rb +36 -0
  25. data/lib/travis/yaml/nodes/fixed_value.rb +60 -0
  26. data/lib/travis/yaml/nodes/git.rb +9 -0
  27. data/lib/travis/yaml/nodes/jdk.rb +11 -0
  28. data/lib/travis/yaml/nodes/language.rb +18 -0
  29. data/lib/travis/yaml/nodes/language_specific.rb +45 -0
  30. data/lib/travis/yaml/nodes/mapping.rb +204 -0
  31. data/lib/travis/yaml/nodes/matrix.rb +36 -0
  32. data/lib/travis/yaml/nodes/node.rb +102 -0
  33. data/lib/travis/yaml/nodes/notifications.rb +77 -0
  34. data/lib/travis/yaml/nodes/open_mapping.rb +18 -0
  35. data/lib/travis/yaml/nodes/os.rb +21 -0
  36. data/lib/travis/yaml/nodes/os_entry.rb +19 -0
  37. data/lib/travis/yaml/nodes/root.rb +44 -0
  38. data/lib/travis/yaml/nodes/ruby.rb +11 -0
  39. data/lib/travis/yaml/nodes/scalar.rb +97 -0
  40. data/lib/travis/yaml/nodes/sequence.rb +84 -0
  41. data/lib/travis/yaml/nodes/stage.rb +6 -0
  42. data/lib/travis/yaml/nodes/version.rb +6 -0
  43. data/lib/travis/yaml/nodes/version_list.rb +7 -0
  44. data/lib/travis/yaml/nodes/virtual_env.rb +7 -0
  45. data/lib/travis/yaml/parser.rb +31 -0
  46. data/lib/travis/yaml/parser/dummy.rb +13 -0
  47. data/lib/travis/yaml/parser/psych.rb +217 -0
  48. data/lib/travis/yaml/parser/ruby.rb +77 -0
  49. data/lib/travis/yaml/secure_string.rb +12 -0
  50. data/lib/travis/yaml/version.rb +5 -0
  51. data/play/lint.rb +8 -0
  52. data/play/spec.rb +183 -0
  53. data/play/weblint.rb +296 -0
  54. data/spec/nodes/.rb +0 -0
  55. data/spec/nodes/branches_spec.rb +45 -0
  56. data/spec/nodes/bundler_args_spec.rb +9 -0
  57. data/spec/nodes/cache_spec.rb +55 -0
  58. data/spec/nodes/compiler_spec.rb +14 -0
  59. data/spec/nodes/deploy_spec.rb +83 -0
  60. data/spec/nodes/git_spec.rb +55 -0
  61. data/spec/nodes/jdk_spec.rb +41 -0
  62. data/spec/nodes/language_spec.rb +79 -0
  63. data/spec/nodes/notifications_spec.rb +45 -0
  64. data/spec/nodes/os_spec.rb +28 -0
  65. data/spec/nodes/ruby_spec.rb +69 -0
  66. data/spec/nodes/stage_spec.rb +34 -0
  67. data/spec/nodes/virtual_env_spec.rb +9 -0
  68. data/spec/parser/dummy_spec.rb +7 -0
  69. data/spec/parser/ruby_spec.rb +41 -0
  70. data/spec/support.rb +3 -0
  71. data/spec/support/coverage.rb +11 -0
  72. data/spec/support/environment.rb +1 -0
  73. data/spec/yaml_spec.rb +26 -0
  74. data/travis-yaml.gemspec +24 -0
  75. metadata +207 -0
@@ -0,0 +1,69 @@
1
+ describe Travis::Yaml::Nodes::Ruby do
2
+ context 'from ruby' do
3
+ specify 'empty section' do
4
+ config = Travis::Yaml.parse(ruby: [])
5
+ expect(config.ruby).to be_nil
6
+ expect(config.nested_warnings).to include([[], 'value for "ruby" section is empty, dropping'])
7
+ end
8
+
9
+ specify 'with a single value' do
10
+ config = Travis::Yaml.parse(ruby: 'jruby')
11
+ expect(config.ruby).to be == ['jruby']
12
+ end
13
+
14
+ specify 'with a list' do
15
+ config = Travis::Yaml.parse(ruby: ['jruby', '2.0.0'])
16
+ expect(config.ruby).to be == ['jruby', '2.0.0']
17
+ end
18
+
19
+ specify 'filters out invalid entries' do
20
+ config = Travis::Yaml.parse(ruby: [:jruby, '2.0.0', nil, 1.0, { foo: :bar }])
21
+ expect(config.ruby).to be == ['jruby', '2.0.0']
22
+ expect(config.nested_warnings).to include([["ruby"], '"null" not supported, dropping ""'])
23
+ expect(config.nested_warnings).to include([["ruby"], '"float" not supported, dropping "1.0"'])
24
+ expect(config.nested_warnings).to include([["ruby"], 'unexpected mapping'])
25
+ end
26
+
27
+ specify 'called rvm' do
28
+ config = Travis::Yaml.parse(rvm: ['jruby', '2.0.0'])
29
+ expect(config.ruby) .to be == ['jruby', '2.0.0']
30
+ expect(config.rvm) .to be == ['jruby', '2.0.0']
31
+ expect(config["rvm"]) .to be == ['jruby', '2.0.0']
32
+ expect(config[:ruby]) .to be == ['jruby', '2.0.0']
33
+ end
34
+ end
35
+
36
+ context 'from yaml' do
37
+ specify 'empty section' do
38
+ config = Travis::Yaml.parse('ruby:')
39
+ expect(config.ruby).to be_nil
40
+ expect(config.nested_warnings).to include([[], 'value for "ruby" section is empty, dropping'])
41
+ end
42
+
43
+ specify 'with a single value' do
44
+ config = Travis::Yaml.parse('ruby: jruby')
45
+ expect(config.ruby).to be == ['jruby']
46
+ end
47
+
48
+ specify 'with a list' do
49
+ config = Travis::Yaml.parse('ruby: [jruby, 2.0.0]')
50
+ expect(config.ruby).to be == ['jruby', '2.0.0']
51
+ end
52
+
53
+ specify 'filters out invalid entries' do
54
+ config = Travis::Yaml.parse('ruby: [jruby, 2.0, !null ~, !float 1.0, { foo: bar }]')
55
+ expect(config.ruby).to be == ['jruby', '2.0']
56
+ expect(config.nested_warnings).to include([["ruby"], '"null" not supported, dropping "~"'])
57
+ expect(config.nested_warnings).to include([["ruby"], '"float" not supported, dropping "1.0"'])
58
+ expect(config.nested_warnings).to include([["ruby"], 'unexpected mapping'])
59
+ end
60
+
61
+ specify 'called rvm' do
62
+ config = Travis::Yaml.parse('rvm: [jruby, 2.0.0]')
63
+ expect(config.ruby) .to be == ['jruby', '2.0.0']
64
+ expect(config.rvm) .to be == ['jruby', '2.0.0']
65
+ expect(config["rvm"]) .to be == ['jruby', '2.0.0']
66
+ expect(config[:ruby]) .to be == ['jruby', '2.0.0']
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ describe Travis::Yaml::Nodes::Stage do
2
+ stages = [:before_install, :install, :before_script, :script, :after_result, :after_script,
3
+ :after_success, :after_failure, :before_deploy, :after_deploy]
4
+
5
+ shared_examples "a stage" do
6
+ specify 'with one entry' do
7
+ config = Travis::Yaml.load(stage => 'rake')
8
+ expect(config[stage]).to be == ['rake']
9
+ end
10
+
11
+ specify 'with multiple entries' do
12
+ config = Travis::Yaml.load(stage => ['rake', 'echo 1'])
13
+ expect(config[stage]).to be == ['rake', 'echo 1']
14
+ end
15
+
16
+ specify 'empty stage' do
17
+ config = Travis::Yaml.load(stage => [])
18
+ expect(config[stage]).to be_nil
19
+ expect(config.warnings).to include("value for \"#{stage}\" section is empty, dropping")
20
+ end
21
+
22
+ specify 'no warnings if missing' do
23
+ config = Travis::Yaml.load(language: "ruby")
24
+ expect(config.warnings).to be_empty
25
+ end
26
+ end
27
+
28
+ stages.each do |stage|
29
+ describe stage do
30
+ let(:stage) { stage }
31
+ include_examples "a stage"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ describe Travis::Yaml::Nodes::VirtualEnv do
2
+ context 'from Ruby' do
3
+ specify 'can only be set for python' do
4
+ expect(Travis::Yaml.parse(language: 'python', virtualenv: { system_site_packages: true }).warnings).to be == []
5
+ expect(Travis::Yaml.parse(language: 'php', virtualenv: { system_site_packages: true }).warnings).to \
6
+ include('specified "virtualenv", but setting is not relevant for "php"')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ describe Travis::Yaml::Parser::Dummy do
2
+ example do
3
+ config = Travis::Yaml.parse({})
4
+ parsed = Travis::Yaml.parse(config)
5
+ expect(parsed).to be == config
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ describe Travis::Yaml::Parser::Ruby do
2
+ subject { described_class }
3
+ let(:secure_string) { Travis::Yaml::SecureString.new("") }
4
+ let(:input) {{ ruby: ['2.0.0', :jruby, 10, 4.2, Time.now, false, nil, secure_string, Object.new] }}
5
+
6
+ describe :parse do
7
+ example do
8
+ result = subject.parse(input)
9
+ expect(result).to be == { rvm: ['2.0.0', 'jruby'], language: 'ruby', os: ['linux'] }
10
+ end
11
+ end
12
+
13
+ describe :parses? do
14
+ it { should be_parses(input) }
15
+ end
16
+
17
+ describe :cast do
18
+ let(:time) { Time.at(0) }
19
+ subject(:parser) { Travis::Yaml::Parser::Ruby.new({}) }
20
+ specify(:str) { expect(parser.cast(:str, "foo")) .to be == "foo" }
21
+ specify(:binary) { expect(parser.cast(:binary, "Zm9v")) .to be == "foo" }
22
+ specify(:bool) { expect(parser.cast(:bool, true)) .to be == true }
23
+ specify(:float) { expect(parser.cast(:float, 1)) .to be == 1.0 }
24
+ specify(:int) { expect(parser.cast(:int, 1)) .to be == 1 }
25
+ specify(:time) { expect(parser.cast(:time, time)) .to be == time }
26
+ specify(:secure) { expect(parser.cast(:secure, secure_string)) .to be == secure_string }
27
+ specify { expect { parser.cast(:foo, 10) }.to raise_error(ArgumentError) }
28
+ end
29
+
30
+ describe :generate_key do
31
+ subject(:parser) { Travis::Yaml::Parser::Ruby.new({}) }
32
+ specify { expect(parser.generate_key(nil, "foo")).to be == "foo" }
33
+ specify { expect(parser.generate_key(nil, :foo )).to be == "foo" }
34
+
35
+ specify do
36
+ node = Travis::Yaml::Nodes::Node.new(nil)
37
+ parser.generate_key(node, 10)
38
+ expect(node.errors).to include("expected string as key")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler/setup'
2
+ require 'support/coverage'
3
+ require 'support/environment'
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+
5
+ SimpleCov.start do
6
+ project_name 'travis-yaml'
7
+ coverage_dir '.coverage'
8
+
9
+ add_filter "/spec/"
10
+ add_group 'Library', 'lib'
11
+ end
@@ -0,0 +1 @@
1
+ require 'travis/yaml'
@@ -0,0 +1,26 @@
1
+ describe Travis::Yaml do
2
+ specify :parse! do
3
+ expect(Travis::Yaml).to receive(:warn).
4
+ with('.travis.yml: missing key "language", defaulting to "ruby"')
5
+ Travis::Yaml.parse! ""
6
+ end
7
+
8
+ describe :new do
9
+ specify 'with block' do
10
+ config = Travis::Yaml.new { |c| c.language = 'php' }
11
+ expect(config.language).to be == 'php'
12
+ expect(config.nested_warnings).to be_empty
13
+ end
14
+
15
+ specify 'without block' do
16
+ config = Travis::Yaml.new
17
+ expect(config.language).to be == 'ruby'
18
+ expect(config.nested_warnings).to include([[], 'missing key "language", defaulting to "ruby"'])
19
+ end
20
+ end
21
+
22
+ specify :inspect do
23
+ config = Travis::Yaml.parse(rvm: ['jruby', '2.0.0'], language: :ruby)
24
+ expect(config.inspect).to be == '#<Travis::Yaml:{"ruby"=>["jruby", "2.0.0"], "language"=>"ruby", "os"=>"linux"}>'
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "travis/yaml/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "travis-yaml"
6
+ s.version = Travis::Yaml::VERSION
7
+ s.author = "Travis CI GmbH"
8
+ s.email = "contact@travis-ci.com"
9
+ s.homepage = "https://github.com/travis-ci/travis-yaml"
10
+ s.summary = %q{parses your .travis.yml}
11
+ s.description = %q{parses and validates your .travis.yml, fast ans secure}
12
+ s.license = 'MIT'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_path = 'lib'
17
+ s.required_ruby_version = '>= 1.9.3'
18
+
19
+ s.add_dependency 'psych', '~> 2.0'
20
+ s.add_development_dependency 'rspec', '~> 3.0.0.beta'
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'simplecov'
23
+ s.add_development_dependency 'safe_yaml', '~> 1.0.1'
24
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis CI GmbH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0.beta
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0.beta
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: safe_yaml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.1
83
+ description: parses and validates your .travis.yml, fast ans secure
84
+ email: contact@travis-ci.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - SPEC.md
98
+ - bench/parser_bench.rb
99
+ - config.ru
100
+ - lib/travis/yaml.rb
101
+ - lib/travis/yaml/matrix.rb
102
+ - lib/travis/yaml/nodes.rb
103
+ - lib/travis/yaml/nodes/branches.rb
104
+ - lib/travis/yaml/nodes/bundler_args.rb
105
+ - lib/travis/yaml/nodes/cache.rb
106
+ - lib/travis/yaml/nodes/compiler.rb
107
+ - lib/travis/yaml/nodes/compiler_entry.rb
108
+ - lib/travis/yaml/nodes/deploy.rb
109
+ - lib/travis/yaml/nodes/deploy_conditions.rb
110
+ - lib/travis/yaml/nodes/deploy_entry.rb
111
+ - lib/travis/yaml/nodes/env.rb
112
+ - lib/travis/yaml/nodes/fixed_value.rb
113
+ - lib/travis/yaml/nodes/git.rb
114
+ - lib/travis/yaml/nodes/jdk.rb
115
+ - lib/travis/yaml/nodes/language.rb
116
+ - lib/travis/yaml/nodes/language_specific.rb
117
+ - lib/travis/yaml/nodes/mapping.rb
118
+ - lib/travis/yaml/nodes/matrix.rb
119
+ - lib/travis/yaml/nodes/node.rb
120
+ - lib/travis/yaml/nodes/notifications.rb
121
+ - lib/travis/yaml/nodes/open_mapping.rb
122
+ - lib/travis/yaml/nodes/os.rb
123
+ - lib/travis/yaml/nodes/os_entry.rb
124
+ - lib/travis/yaml/nodes/root.rb
125
+ - lib/travis/yaml/nodes/ruby.rb
126
+ - lib/travis/yaml/nodes/scalar.rb
127
+ - lib/travis/yaml/nodes/sequence.rb
128
+ - lib/travis/yaml/nodes/stage.rb
129
+ - lib/travis/yaml/nodes/version.rb
130
+ - lib/travis/yaml/nodes/version_list.rb
131
+ - lib/travis/yaml/nodes/virtual_env.rb
132
+ - lib/travis/yaml/parser.rb
133
+ - lib/travis/yaml/parser/dummy.rb
134
+ - lib/travis/yaml/parser/psych.rb
135
+ - lib/travis/yaml/parser/ruby.rb
136
+ - lib/travis/yaml/secure_string.rb
137
+ - lib/travis/yaml/version.rb
138
+ - play/lint.rb
139
+ - play/spec.rb
140
+ - play/weblint.rb
141
+ - spec/nodes/.rb
142
+ - spec/nodes/branches_spec.rb
143
+ - spec/nodes/bundler_args_spec.rb
144
+ - spec/nodes/cache_spec.rb
145
+ - spec/nodes/compiler_spec.rb
146
+ - spec/nodes/deploy_spec.rb
147
+ - spec/nodes/git_spec.rb
148
+ - spec/nodes/jdk_spec.rb
149
+ - spec/nodes/language_spec.rb
150
+ - spec/nodes/notifications_spec.rb
151
+ - spec/nodes/os_spec.rb
152
+ - spec/nodes/ruby_spec.rb
153
+ - spec/nodes/stage_spec.rb
154
+ - spec/nodes/virtual_env_spec.rb
155
+ - spec/parser/dummy_spec.rb
156
+ - spec/parser/ruby_spec.rb
157
+ - spec/support.rb
158
+ - spec/support/coverage.rb
159
+ - spec/support/environment.rb
160
+ - spec/yaml_spec.rb
161
+ - travis-yaml.gemspec
162
+ homepage: https://github.com/travis-ci/travis-yaml
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 1.9.3
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.0.14
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: parses your .travis.yml
186
+ test_files:
187
+ - spec/nodes/.rb
188
+ - spec/nodes/branches_spec.rb
189
+ - spec/nodes/bundler_args_spec.rb
190
+ - spec/nodes/cache_spec.rb
191
+ - spec/nodes/compiler_spec.rb
192
+ - spec/nodes/deploy_spec.rb
193
+ - spec/nodes/git_spec.rb
194
+ - spec/nodes/jdk_spec.rb
195
+ - spec/nodes/language_spec.rb
196
+ - spec/nodes/notifications_spec.rb
197
+ - spec/nodes/os_spec.rb
198
+ - spec/nodes/ruby_spec.rb
199
+ - spec/nodes/stage_spec.rb
200
+ - spec/nodes/virtual_env_spec.rb
201
+ - spec/parser/dummy_spec.rb
202
+ - spec/parser/ruby_spec.rb
203
+ - spec/support.rb
204
+ - spec/support/coverage.rb
205
+ - spec/support/environment.rb
206
+ - spec/yaml_spec.rb
207
+ has_rdoc: