Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8fca4360d78d0646d7e1225162066eea195a2c6e @michaelklishin michaelklishin committed Feb 9, 2012
@@ -0,0 +1,5 @@
+.DS_Store
+#~
+*~
+Gemfile.lock
+*.gem
3 .rspec
@@ -0,0 +1,3 @@
+--color
+--format
+progress
@@ -0,0 +1,8 @@
+language: ruby
+rvm:
+ - 1.9.2
+ - 1.9.3
+ - jruby-19mode
+ - rbx-19mode
+ - jruby-head
+ - ruby-head
@@ -0,0 +1,7 @@
+source "http://rubygems.org"
+
+gemspec
+
+group :test do
+ gem "rake", ">= 0.9.2.2"
+end
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'travis/lint'
+
+ runner = Travis::Lint::Runner.new(ARGV)
+ runner.run
+rescue LoadError => e
+ $stderr.puts <<-EOS
+#{'*'*50}
+ Could not find 'travis/lint'
+
+ This may happen if you're using rubygems as your package manager, but it is not
+ being required through some mechanism before executing the travis-lint command.
+
+ You may need to do one of the following in your shell:
+
+ # for bash/zsh
+ export RUBYOPT=rubygems
+
+ # for csh, etc.
+ set RUBYOPT=rubygems
+
+ For background, please see http://gist.github.com/54177.
+#{'*'*50}
+ EOS
+
+ raise e
+
+ exit(1)
+end
@@ -0,0 +1,4 @@
+require "travis/lint/version"
+
+require "travis/lint/runner"
+require "travis/lint/linter"
@@ -0,0 +1,26 @@
+require "travis/lint/validator"
+
+module Travis
+ module Lint
+ module DSL
+ @@validators = []
+
+ def validator_for(language, key, message, &validator)
+ @@validators << Validator.new(language, key, message, validator)
+ end
+
+
+ def validators_for_language(language)
+ @@validators.select { |v| v.language.to_s.downcase == language.to_s.downcase }
+ end
+
+ def generic_validators
+ @@validators.select { |v| v.language.to_s.downcase == :all.to_s }
+ end
+
+ def find_validators_for(language)
+ generic_validators + validators_for_language(language)
+ end
+ end
+ end
+end
@@ -0,0 +1,82 @@
+require "active_support/core_ext/object/blank"
+require "travis/lint/dsl"
+
+module Travis
+ module Lint
+ class Linter
+
+ #
+ # Behaviors
+ #
+
+ extend Lint::DSL
+
+
+ #
+ # API
+ #
+
+ def self.validate(hsh)
+ issues = find_validators_for(hsh[:language]).inject([]) do |acc, val|
+ acc << val.call(hsh)
+ acc
+ end.reject(&:first).map { |pair| pair[1] }
+ end
+
+ def self.valid?(hsh)
+ validate(hsh).empty?
+ end
+
+
+ #
+ # General
+ #
+
+ validator_for :all, :language, "Language: key is mandatory" do |hsh|
+ hsh[:language].blank?
+ end
+
+
+ #
+ # Erlang
+ #
+
+ validator_for :erlang, :otp_release, "Specify OTP releases you want to test against using the :otp_release key" do |hsh|
+ hsh[:language].to_s.downcase == "erlang" && hsh[:otp_release].blank?
+ end
+
+
+ #
+ # Ruby
+ #
+
+ validator_for :ruby, :rvm, "Specify Ruby versions/implementations you want to test against using the :rvm key" do |hsh|
+ hsh[:language].to_s.downcase == "ruby" && hsh[:rvm].blank?
+ end
+
+ validator_for :ruby, :rvm, "Prefer jruby-18mode RVM alias to jruby" do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("jruby")
+ end
+
+ validator_for :ruby, :rvm, "Prefer rbx-18mode RVM alias to rbx" do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx")
+ end
+
+ validator_for :ruby, :rvm, "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0")
+ end
+
+ validator_for :ruby, :rvm, "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0.0pre")
+ end
+
+ 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|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.9.1")
+ end
+
+ 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|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.8.6")
+ end
+ end
+ end
+end
@@ -0,0 +1,73 @@
+require "pathname"
+require "yaml"
+
+require "hashr"
+
+require "travis/lint/linter"
+
+module Travis
+ module Lint
+
+ class Runner
+ def initialize(argv)
+ show_help if argv.empty?
+
+ @travis_file_path = Pathname.new(argv.first).expand_path
+ end
+
+
+ def run
+ check_that_travis_yml_file_exists!
+ check_that_travis_yml_file_is_valid_yaml!
+
+ if (issues = Linter.validate(self.parsed_travis_yml)).empty?
+ puts "Hooray, your .travis.yml seems to be solid!"
+ else
+ issues.each do |i|
+ puts "Found an issue with the `#{i[:key]}:` key:\n\n\t#{i[:issue]}"
+ puts
+ puts
+ end
+ end
+ end
+
+
+ protected
+
+ def check_that_travis_yml_file_exists!
+ quit("Cannot read #{@travis_file_path}: file does not exist or is not readable") unless File.exists?(@travis_file_path) &&
+ File.file?(@travis_file_path) &&
+ File.readable?(@travis_file_path)
+ end
+
+ def check_that_travis_yml_file_is_valid_yaml!
+ begin
+ YAML.load_file(@travis_file_path)
+ rescue ArgumentError, Psych::SyntaxError => e
+ quit ".travis.yml at #{@travis_file_path} is not a valid YAML file and thus will be ignored by Travis CI."
+ end
+ end
+
+ def parsed_travis_yml
+ Hashr.new(YAML.load_file(@travis_file_path))
+ end
+
+ def show_help
+ puts <<-EOS
+Usage:
+
+ travis-lint [path to your .travis.yml]
+ EOS
+
+ exit(1)
+ end
+
+ def quit(message, status = 1)
+ puts message
+ puts
+
+ exit(status)
+ end
+ end
+ end
+end
@@ -0,0 +1,15 @@
+module Travis
+ module Lint
+ module DSL
+ class Validator < Struct.new(:language, :key, :message, :validator)
+ def call(hash)
+ if self.validator.call(hash)
+ [false, { :key => self.key, :issue => self.message }]
+ else
+ [true, {}]
+ end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,6 @@
+module Travis
+ module Lint
+ VERSION = "1.0.0"
+ Version = VERSION
+ end
+end
@@ -0,0 +1,16 @@
+rvm:
+ - 1.9.3
+ - jruby-19mode
+ - rbx-19mode
+gemfile:
+ - Gemfile
+ - gemfiles/eventmachine-pre
+notifications:
+ recipients:
+ - recepient@example.com
+branches:
+ only:
+ - master
+ - 0.9.x-stable
+ - 0.8.x-stable
+ - 0.7.x-stable
@@ -0,0 +1 @@
+language: ruby
@@ -0,0 +1,4 @@
+language: ruby
+rvm:
+ - jruby
+ - rbx-2.0.0pre
@@ -0,0 +1,5 @@
+language: ruby
+rvm:
+ - 1.8.7
+ - rbx-2.0
+ - rbx-2.0.0pre
@@ -0,0 +1,11 @@
+# encoding: binary
+require "pathname"
+
+require 'bundler'
+Bundler.setup(:default, :test)
+
+require 'rspec'
+
+
+$: << File.expand_path('../../lib', __FILE__)
+require "travis/lint"
Oops, something went wrong.

0 comments on commit 8fca436

Please sign in to comment.