-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor start script and add option for custom coverage directory
- Loading branch information
Joakim Reinert
committed
Nov 24, 2016
1 parent
59b4668
commit 69d2a41
Showing
1 changed file
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "codeclimate-test-reporter" | ||
require "optparse" | ||
|
||
COVERAGE_FILE = "coverage/.resultset.json".freeze | ||
|
||
if (repo_token = ENV["CODECLIMATE_REPO_TOKEN"]) && !repo_token.empty? | ||
if File.exist?(COVERAGE_FILE) | ||
begin | ||
results = JSON.parse(File.read(COVERAGE_FILE)) | ||
rescue JSON::ParserError => e | ||
$stderr.puts "Error encountered while parsing #{COVERAGE_FILE}: #{e}" | ||
exit(1) | ||
end | ||
|
||
CodeClimate::TestReporter.run(results) | ||
else | ||
$stderr.puts "Coverage results not found" | ||
exit(1) | ||
repo_token = ENV["CODECLIMATE_REPO_TOKEN"] | ||
if repo_token.nil? || repo_token.empty? | ||
abort "Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set." | ||
end | ||
|
||
coverage_dir = "coverage" | ||
parser = OptionParser.new do |p| | ||
p.banner = "Usage: #{$0} [options]" | ||
on("-d PATH", "--directory PATH", "Path to coverage results directory (default: coverage)") do |path| | ||
coverage_dir = path | ||
end | ||
|
||
p.on("-h", "--help", "Show this message") do | ||
puts p | ||
exit | ||
end | ||
else | ||
$stderr.puts "Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set." | ||
exit(0) | ||
end | ||
|
||
parser.parse! | ||
|
||
coverage_file = File.join(coverage_dir, ".resultset.json") | ||
abort "Coverage results not found" unless File.exist?(coverage_file) | ||
|
||
begin | ||
results = JSON.parse(File.read(coverage_file)) | ||
rescue JSON::ParserError => e | ||
abort("Error encountered while parsing #{coverage_file}: #{e}") | ||
end | ||
|
||
CodeClimate::TestReporter.run(results) |