Skip to content

Commit

Permalink
Merge pull request #6645 from jhelwig/PUP-8463-warning-cleanup-5-bloo…
Browse files Browse the repository at this point in the history
…dlines

(PUP-8463) Check modified Ruby files in PRs against 'ruby -wc'
  • Loading branch information
joshcooper committed Feb 22, 2018
2 parents 73d94af + dfec254 commit fad5336
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Expand Up @@ -17,6 +17,7 @@ env:
- "CHECK=parallel:spec\\[2\\]"
- "CHECK=rubocop"
- "CHECK=commits"
- "CHECK=warnings"

matrix:
exclude:
Expand All @@ -40,3 +41,13 @@ matrix:
env: "CHECK=commits"
- rvm: 1.9.3
env: "CHECK=commits"
- rvm: 2.3.6
env: "CHECK=warnings"
- rvm: 2.2.9
env: "CHECK=warnings"
- rvm: 2.1.9
env: "CHECK=warnings"
- rvm: 2.0.0
env: "CHECK=warnings"
- rvm: 1.9.3
env: "CHECK=warnings"
26 changes: 26 additions & 0 deletions Rakefile
Expand Up @@ -19,6 +19,7 @@ rescue LoadError
end

require 'rake'
require 'open3'

Dir['tasks/**/*.rake'].each { |t| load t }

Expand Down Expand Up @@ -110,6 +111,31 @@ task(:commits) do
end
end

desc "verify that changed files are clean of Ruby warnings"
task(:warnings) do
# This rake task looks at all files modified in this branch. This is
# accomplished by using the TRAVIS_COMMIT_RANGE environment variable, which
# is present in travis CI and populated with the range of commits the PR
# contains. If not available, this falls back to `master..HEAD` as a next
# best bet as `master` is unlikely to ever be absent.
commit_range = ENV['TRAVIS_COMMIT_RANGE'].nil? ? 'master...HEAD' : ENV['TRAVIS_COMMIT_RANGE']
ruby_files_ok = true
puts "Checking modified files #{commit_range}"
%x{git diff --name-only #{commit_range}}.each_line do |modified_file|
modified_file.chomp!
next unless File.extname(modified_file) == '.rb'
puts modified_file

stdout, stderr, _ = Open3.capture3("ruby -wc \"#{modified_file}\"")
unless stderr.empty?
ruby_files_ok = false
puts stderr
end
puts stdout
end
raise "One or more ruby files contain warnings." unless ruby_files_ok
end

if Rake.application.top_level_tasks.grep(/^gettext:/).any?
begin
spec = Gem::Specification.find_by_name 'gettext-setup'
Expand Down

0 comments on commit fad5336

Please sign in to comment.