travis-lint 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ #~
3
+ *~
4
+ Gemfile.lock
5
+ *.gem
6
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format
3
+ progress
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - jruby-head
10
+ - ruby-head
11
+ - 1.8.7
12
+ script: bundle exec rspec -c spec
13
+ notifications:
14
+ irc: "irc.freenode.org#travis"
15
+ email:
16
+ recepients:
17
+ - michaelklishin@me.com
18
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rake", ">= 0.9.2.2"
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2012 Travis CI Development Team <contact@travis-ci.org>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # What is travis-lint
2
+
3
+ `travis-lint` is a tool that checks your `.travis.yml` file for possible issues, deprecations and so on.
4
+
5
+ [![Continuous Integration status](https://secure.travis-ci.org/travis-ci/travis-lint.png)](http://travis-ci.org/travis-ci/travis-lint)
6
+
7
+
8
+ ## Installation
9
+
10
+ TBD: we need to do initial gem release first
11
+
12
+
13
+ ## Usage
14
+
15
+ travis-lint ./.travis.yml
16
+ travis-lint ~/your/project/.travis.yml
17
+
18
+
19
+ ## Development
20
+
21
+ Install dependencies with
22
+
23
+ bundle install
24
+
25
+ then run tests with
26
+
27
+ bundle exec rspec spec
28
+
29
+ Once you are done with your changes, push a branch and submit a pull request.
30
+
31
+
32
+ ## License & Copyright
33
+
34
+ Copyright 2012 (c) Travis CI Development Team.
35
+
36
+ Released under the MIT license.
data/bin/travis-lint ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'travis/lint'
5
+
6
+ runner = Travis::Lint::Runner.new(ARGV)
7
+ runner.run
8
+ rescue LoadError => e
9
+ $stderr.puts <<-EOS
10
+ #{'*'*50}
11
+ Could not find 'travis/lint'
12
+
13
+ This may happen if you're using rubygems as your package manager, but it is not
14
+ being required through some mechanism before executing the travis-lint command.
15
+
16
+ You may need to do one of the following in your shell:
17
+
18
+ # for bash/zsh
19
+ export RUBYOPT=rubygems
20
+
21
+ # for csh, etc.
22
+ set RUBYOPT=rubygems
23
+
24
+ For background, please see http://gist.github.com/54177.
25
+ #{'*'*50}
26
+ EOS
27
+
28
+ raise e
29
+
30
+ exit(1)
31
+ end
@@ -0,0 +1,4 @@
1
+ require "travis/lint/version"
2
+
3
+ require "travis/lint/runner"
4
+ require "travis/lint/linter"
@@ -0,0 +1,26 @@
1
+ require "travis/lint/validator"
2
+
3
+ module Travis
4
+ module Lint
5
+ module DSL
6
+ @@validators = []
7
+
8
+ def validator_for(language, key, message, &validator)
9
+ @@validators << Validator.new(language, key, message, validator)
10
+ end
11
+
12
+
13
+ def validators_for_language(language)
14
+ @@validators.select { |v| v.language.to_s.downcase == language.to_s.downcase }
15
+ end
16
+
17
+ def generic_validators
18
+ @@validators.select { |v| v.language.to_s.downcase == :all.to_s }
19
+ end
20
+
21
+ def find_validators_for(language)
22
+ generic_validators + validators_for_language(language)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "travis/lint/dsl"
3
+
4
+ module Travis
5
+ module Lint
6
+ class Linter
7
+
8
+ #
9
+ # Behaviors
10
+ #
11
+
12
+ extend Lint::DSL
13
+
14
+
15
+ #
16
+ # API
17
+ #
18
+
19
+ def self.validate(hsh)
20
+ issues = find_validators_for(hsh[:language]).inject([]) do |acc, val|
21
+ acc << val.call(hsh)
22
+ acc
23
+ end.reject(&:first).map { |pair| pair[1] }
24
+ end
25
+
26
+ def self.valid?(hsh)
27
+ validate(hsh).empty?
28
+ end
29
+
30
+
31
+ #
32
+ # General
33
+ #
34
+
35
+ validator_for :all, :language, "Language: key is mandatory" do |hsh|
36
+ hsh[:language].blank?
37
+ end
38
+
39
+
40
+ #
41
+ # Erlang
42
+ #
43
+
44
+ validator_for :erlang, :otp_release, "Specify OTP releases you want to test against using the :otp_release key" do |hsh|
45
+ hsh[:language].to_s.downcase == "erlang" && hsh[:otp_release].blank?
46
+ end
47
+
48
+
49
+ #
50
+ # Ruby
51
+ #
52
+
53
+ validator_for :ruby, :rvm, "Specify Ruby versions/implementations you want to test against using the :rvm key" do |hsh|
54
+ hsh[:language].to_s.downcase == "ruby" && hsh[:rvm].blank?
55
+ end
56
+
57
+ validator_for :ruby, :rvm, "Prefer jruby-18mode RVM alias to jruby" do |hsh|
58
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("jruby")
59
+ end
60
+
61
+ validator_for :ruby, :rvm, "Prefer rbx-18mode RVM alias to rbx" do |hsh|
62
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx")
63
+ end
64
+
65
+ validator_for :ruby, :rvm, "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
66
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0")
67
+ end
68
+
69
+ validator_for :ruby, :rvm, "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
70
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0.0pre")
71
+ end
72
+
73
+ validator_for :ruby, :rvm, "Ruby 1.9.1 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.9.3." do |hsh|
74
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.9.1")
75
+ end
76
+
77
+ validator_for :ruby, :rvm, "Ruby 1.8.6 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.8.7." do |hsh|
78
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.8.6")
79
+ end
80
+
81
+
82
+
83
+ validator_for :ruby, :language, "Language is set to Ruby but node_js key is present. Ruby builder will ignore node_js key." do |hsh|
84
+ hsh[:language].to_s.downcase == "ruby" && hsh[:node_js].present?
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,79 @@
1
+ require "pathname"
2
+ require "yaml"
3
+
4
+ require "hashr"
5
+
6
+ require "travis/lint/linter"
7
+
8
+ module Travis
9
+ module Lint
10
+
11
+ class Runner
12
+ def initialize(argv)
13
+ if argv.empty?
14
+ if File.exists?(".travis.yml")
15
+ argv = [".travis.yml"]
16
+ else
17
+ show_help
18
+ end
19
+ end
20
+
21
+ @travis_file_path = Pathname.new(argv.first).expand_path
22
+ end
23
+
24
+
25
+ def run
26
+ check_that_travis_yml_file_exists!
27
+ check_that_travis_yml_file_is_valid_yaml!
28
+
29
+ if (issues = Linter.validate(self.parsed_travis_yml)).empty?
30
+ puts "Hooray, .travis.yml at #{@travis_file_path} seems to be solid!"
31
+ else
32
+ issues.each do |i|
33
+ puts "Found an issue with the `#{i[:key]}:` key:\n\n\t#{i[:issue]}"
34
+ puts
35
+ puts
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ protected
42
+
43
+ def check_that_travis_yml_file_exists!
44
+ quit("Cannot read #{@travis_file_path}: file does not exist or is not readable") unless File.exists?(@travis_file_path) &&
45
+ File.file?(@travis_file_path) &&
46
+ File.readable?(@travis_file_path)
47
+ end
48
+
49
+ def check_that_travis_yml_file_is_valid_yaml!
50
+ begin
51
+ YAML.load_file(@travis_file_path)
52
+ rescue ArgumentError, Psych::SyntaxError => e
53
+ quit ".travis.yml at #{@travis_file_path} is not a valid YAML file and thus will be ignored by Travis CI."
54
+ end
55
+ end
56
+
57
+ def parsed_travis_yml
58
+ Hashr.new(YAML.load_file(@travis_file_path))
59
+ end
60
+
61
+ def show_help
62
+ puts <<-EOS
63
+ Usage:
64
+
65
+ travis-lint [path to your .travis.yml]
66
+ EOS
67
+
68
+ exit(1)
69
+ end
70
+
71
+ def quit(message, status = 1)
72
+ puts message
73
+ puts
74
+
75
+ exit(status)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,15 @@
1
+ module Travis
2
+ module Lint
3
+ module DSL
4
+ class Validator < Struct.new(:language, :key, :message, :validator)
5
+ def call(hash)
6
+ if self.validator.call(hash)
7
+ [false, { :key => self.key, :issue => self.message }]
8
+ else
9
+ [true, {}]
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Travis
2
+ module Lint
3
+ VERSION = "1.0.0"
4
+ Version = VERSION
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - jruby-19mode
4
+ - rbx-19mode
5
+ gemfile:
6
+ - Gemfile
7
+ - gemfiles/eventmachine-pre
8
+ notifications:
9
+ recipients:
10
+ - recepient@example.com
11
+ branches:
12
+ only:
13
+ - master
14
+ - 0.9.x-stable
15
+ - 0.8.x-stable
16
+ - 0.7.x-stable
@@ -0,0 +1 @@
1
+ language: ruby
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby
4
+ - rbx-2.0.0pre
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - rbx-2.0
5
+ - rbx-2.0.0pre
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ node_js:
5
+ - 0.6
@@ -0,0 +1,11 @@
1
+ # encoding: binary
2
+ require "pathname"
3
+
4
+ require 'bundler'
5
+ Bundler.setup(:default, :test)
6
+
7
+ require 'rspec'
8
+
9
+
10
+ $: << File.expand_path('../../lib', __FILE__)
11
+ require "travis/lint"
@@ -0,0 +1,109 @@
1
+ require "spec_helper"
2
+
3
+ describe "A .travis.yml" do
4
+ let(:language_key_is_mandatory) do
5
+ { :key => :language, :issue => "Language: key is mandatory" }
6
+ end
7
+
8
+ let(:rvm_key_is_recommended) do
9
+ { :key => :rvm, :issue => "Specify Ruby versions/implementations you want to test against using the :rvm key" }
10
+ end
11
+
12
+ let(:prefer_jruby18mode_over_jruby) do
13
+ { :key => :rvm, :issue => "Prefer jruby-18mode RVM alias to jruby" }
14
+ end
15
+
16
+ let(:prefer_rbx18mode_over_rbx) do
17
+ { :key => :rvm, :issue => "Prefer rbx-18mode RVM alias to rbx" }
18
+ end
19
+
20
+ let(:rbx20_is_no_longer_provided) do
21
+ { :key => :rvm, :issue => "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
22
+ end
23
+
24
+ let(:rbx200pre_is_no_longer_provided) do
25
+ { :key => :rvm, :issue => "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
26
+ end
27
+
28
+
29
+ def content_of_sample_file(name)
30
+ path = Pathname.new(File.join("spec", "files", name)).expand_path
31
+
32
+ Hashr.new(YAML.load_file(path.to_s))
33
+ end
34
+
35
+
36
+ context "that is blank" do
37
+ it "is invalid" do
38
+ Travis::Lint::Linter.validate({}).should include(language_key_is_mandatory)
39
+
40
+ Travis::Lint::Linter.valid?(content_of_sample_file("no_language_key.yml")).should be_false
41
+ end
42
+ end
43
+
44
+ context "that has language set to Ruby" do
45
+ context "but has no :rvm key" do
46
+ it "is invalid" do
47
+ Travis::Lint::Linter.validate({ :language => "ruby" }).should include(rvm_key_is_recommended)
48
+ Travis::Lint::Linter.valid?(content_of_sample_file("no_rvm_key.yml")).should be_false
49
+ end
50
+ end
51
+
52
+
53
+ context "and uses jruby instead of jruby-18mode" do
54
+ let(:travis_yml) do
55
+ { :language => "ruby", :rvm => ["jruby"] }
56
+ end
57
+
58
+ it "is invalid" do
59
+ Travis::Lint::Linter.validate(travis_yml).should include(prefer_jruby18mode_over_jruby)
60
+ Travis::Lint::Linter.valid?(content_of_sample_file("uses_jruby_instead_of_jruby_in_specific_mode.yml")).should be_false
61
+ end
62
+ end
63
+
64
+
65
+ context "and uses rbx instead of rbx-18mode" do
66
+ let(:travis_yml) do
67
+ { :language => "ruby", :rvm => ["rbx", "1.9.3"] }
68
+ end
69
+
70
+ it "is invalid" do
71
+ Travis::Lint::Linter.validate(travis_yml).should include(prefer_rbx18mode_over_rbx)
72
+ end
73
+ end
74
+
75
+
76
+ context "and uses rbx-2.0 instead of rbx-18mode" do
77
+ let(:travis_yml) do
78
+ { :language => "ruby", :rvm => ["rbx-2.0", "1.9.3"] }
79
+ end
80
+
81
+ it "is invalid" do
82
+ Travis::Lint::Linter.validate(travis_yml).should include(rbx20_is_no_longer_provided)
83
+ Travis::Lint::Linter.valid?(content_of_sample_file("uses_old_rbx_aliases.yml")).should be_false
84
+ end
85
+ end
86
+
87
+
88
+ context "and uses rbx-2.0.0pre instead of rbx-18mode" do
89
+ let(:travis_yml) do
90
+ { :language => "ruby", :rvm => ["rbx-2.0.0pre", "1.9.3"] }
91
+ end
92
+
93
+ it "is invalid" do
94
+ Travis::Lint::Linter.validate(travis_yml).should include(rbx200pre_is_no_longer_provided)
95
+ end
96
+ end
97
+
98
+
99
+ context "that specifies Ruby as the language but tries to set node_js version" do
100
+ let(:travis_yml) do
101
+ { :language => "ruby", :rvm => ["1.9.3"], :node_js => ["0.6"] }
102
+ end
103
+
104
+ it "is invalid" do
105
+ Travis::Lint::Linter.validate(travis_yml).should include({ :key => :language, :issue => "Language is set to Ruby but node_js key is present. Ruby builder will ignore node_js key." })
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "travis/lint/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "travis-lint"
7
+ s.version = Travis::Lint::Version.to_s
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael S. Klishin", "Travis CI Development Team"]
10
+ s.email = ["michaelklishin@me.com", "michael@novemberain.com"]
11
+ s.homepage = "http://github.com/travis-ci"
12
+ s.summary = %q{Checks your .travis.yml for possible issues, deprecations and so on}
13
+ s.description = %q{travis-lint is a tool that check your .travis.yml for possible issues, deprecations and so on. Recommended for all travis-ci.org users.}
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency("activesupport", ["~> 3.2.0"])
20
+ # activesupport 3.1 and 3.2 have a bug in HashWithIndifferentAccess that
21
+ # causes an undefined method exception when hash values are arrays, so we
22
+ # retreat to Hashr. MK.
23
+ s.add_runtime_dependency("hashr", [">= 0.0.19"])
24
+
25
+ s.add_development_dependency("rspec", ["~> 2.8.0"])
26
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis-lint
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Michael S. Klishin
14
+ - Travis CI Development Team
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-02-10 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 3
32
+ - 2
33
+ - 0
34
+ version: 3.2.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: hashr
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 57
46
+ segments:
47
+ - 0
48
+ - 0
49
+ - 19
50
+ version: 0.0.19
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 47
62
+ segments:
63
+ - 2
64
+ - 8
65
+ - 0
66
+ version: 2.8.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: travis-lint is a tool that check your .travis.yml for possible issues, deprecations and so on. Recommended for all travis-ci.org users.
70
+ email:
71
+ - michaelklishin@me.com
72
+ - michael@novemberain.com
73
+ executables:
74
+ - travis-lint
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - .rspec
82
+ - .travis.yml
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - bin/travis-lint
87
+ - lib/travis/lint.rb
88
+ - lib/travis/lint/dsl.rb
89
+ - lib/travis/lint/linter.rb
90
+ - lib/travis/lint/runner.rb
91
+ - lib/travis/lint/validator.rb
92
+ - lib/travis/lint/version.rb
93
+ - spec/files/no_language_key.yml
94
+ - spec/files/no_rvm_key.yml
95
+ - spec/files/uses_jruby_instead_of_jruby_in_specific_mode.yml
96
+ - spec/files/uses_old_rbx_aliases.yml
97
+ - spec/files/uses_ruby_as_language_but_tries_to_switch_nodejs.yml
98
+ - spec/spec_helper.rb
99
+ - spec/travis_lint_spec.rb
100
+ - travis-lint.gemspec
101
+ homepage: http://github.com/travis-ci
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.10
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Checks your .travis.yml for possible issues, deprecations and so on
134
+ test_files:
135
+ - spec/files/no_language_key.yml
136
+ - spec/files/no_rvm_key.yml
137
+ - spec/files/uses_jruby_instead_of_jruby_in_specific_mode.yml
138
+ - spec/files/uses_old_rbx_aliases.yml
139
+ - spec/files/uses_ruby_as_language_but_tries_to_switch_nodejs.yml
140
+ - spec/spec_helper.rb
141
+ - spec/travis_lint_spec.rb