Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --travispro flag #223

Merged
merged 5 commits into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## master

* Add `--travispro` flag
[sbhklr](https://github.com/sbhklr)
[#223](https://github.com/SlatherOrg/slather/pull/223), [#219](https://github.com/SlatherOrg/slather/issues/219)

* Fixes silent failure in case of unsuccessful upload to Coveralls
[sbhklr](https://github.com/sbhklr)
[#222](https://github.com/SlatherOrg/slather/pull/222), [#217](https://github.com/SlatherOrg/slather/issues/217)

## v2.2.1

* Make `project.coverage_files` public
Expand Down
3 changes: 3 additions & 0 deletions lib/slather/command/coverage_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class CoverageCommand < Clamp::Command
parameter "[PROJECT]", "Path to the xcodeproj", :attribute_name => :xcodeproj_path

option ["--travis", "-t"], :flag, "Indicate that the builds are running on Travis CI"
option ["--travispro"], :flag, "Indicate that the builds are running on Travis Pro CI"
option ["--circleci"], :flag, "Indicate that the builds are running on CircleCI"
option ["--jenkins"], :flag, "Indicate that the builds are running on Jenkins"
option ["--buildkite"], :flag, "Indicate that the builds are running on Buildkite"
Expand Down Expand Up @@ -73,6 +74,8 @@ def setup_ignore_list
def setup_service_name
if travis?
project.ci_service = :travis_ci
elsif travispro?
project.ci_service = :travis_pro
elsif circleci?
project.ci_service = :circleci
elsif jenkins?
Expand Down
25 changes: 23 additions & 2 deletions lib/slather/coverage_service/coveralls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,22 @@ def coveralls_coverage_data
if ci_service == :travis_ci || ci_service == :travis_pro
if travis_job_id
if ci_service == :travis_ci

if coverage_access_token.to_s.strip.length > 0
raise StandardError, "Access token is set. Uploading coverage data for public repositories doesn't require an access token."
end

{
:service_job_id => travis_job_id,
:service_name => "travis-ci",
:source_files => coverage_files.map(&:as_json)
}.to_json
elsif ci_service == :travis_pro
elsif ci_service == :travis_pro

if coverage_access_token.to_s.strip.length == 0
raise StandardError, "Access token is not set. Uploading coverage data for private repositories requires an access token."
end

{
:service_job_id => travis_job_id,
:service_name => "travis-pro",
Expand Down Expand Up @@ -172,7 +182,18 @@ def post
begin
f.write(coveralls_coverage_data)
f.close
`curl -s --form json_file=@#{f.path} #{coveralls_api_jobs_path}`

curl_result = `curl -s --form json_file=@#{f.path} #{coveralls_api_jobs_path}`

if curl_result.is_a? String
curl_result_json = JSON.parse(curl_result)

if curl_result_json["error"]
error_message = curl_result_json["message"]
raise StandardError, "Error while uploading coverage data to Coveralls. CI Service: #{ci_service} Message: #{error_message}"
end
end

rescue StandardError => e
FileUtils.rm(f)
raise e
Expand Down
19 changes: 19 additions & 0 deletions spec/slather/coverage_service/coveralls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
allow(fixtures_project).to receive(:travis_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end

it "should raise an error if there is a COVERAGE_ACCESS_TOKEN" do
allow(fixtures_project).to receive(:coverage_access_token).and_return("abc123")
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end

end

context "coverage_service is :travis_pro" do
Expand All @@ -57,6 +63,12 @@
allow(fixtures_project).to receive(:travis_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end

it "should raise an error if there is no COVERAGE_ACCESS_TOKEN" do
allow(fixtures_project).to receive(:coverage_access_token).and_return("")
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end

end

context "coverage_service is :circleci" do
Expand Down Expand Up @@ -143,6 +155,13 @@
fixtures_project.post
end

it "should save the coveralls_coverage_data to a file, post it to coveralls, and fail due to a Coveralls error" do
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:`).and_return("{\"message\":\"Couldn't find a repository matching this job.\",\"error\":true}")
expect(fixtures_project).to receive(:`).once
expect { fixtures_project.post }.to raise_error(StandardError)
end

it "should always remove the coveralls_json_file after it's done" do
allow(fixtures_project).to receive(:`)
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
Expand Down