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

Build Statistic Reporting for TeamCity #150

Merged
merged 6 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ cobertura.xml
html
*.gcda
*.gcno

# JetBrains IDE
.idea/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ $ slather coverage --html path/to/project.xcodeproj

This will make a directory named `html` in your root directory (unless `--output-directory` is specified) and will generate all the reports as static html pages inside the directory. It will print out the report's path by default, but you can also specify `--show` flag to open it in your browser automatically.

### TeamCity Reporting

To report the coverage statistics to TeamCity:

```sh
$ slather coverage --teamcity -s
```

### Coverage for code included via CocoaPods

If you're trying to compute the coverage of code that has been included via
Expand Down
3 changes: 3 additions & 0 deletions bin/slather
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Clamp do
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"
option ["--teamcity"], :flag, "Indicate that the builds are running on TeamCity"

option ["--coveralls", "-c"], :flag, "Post coverage results to coveralls"
option ["--simple-output", "-s"], :flag, "Output coverage results to the terminal"
Expand Down Expand Up @@ -81,6 +82,8 @@ Clamp do
project.ci_service = :jenkins
elsif buildkite?
project.ci_service = :buildkite
elsif teamcity?
project.ci_service = :teamcity
end
end

Expand Down
16 changes: 16 additions & 0 deletions lib/slather/coverage_service/simple_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ def post

puts "#{coverage_file.source_file_pathname_relative_to_repo_root}: #{lines_tested} of #{total_lines} lines (#{percentage}%)"
end

# check if there needs to be custom reporting based on the ci service
if ci_service == :teamcity
# TeamCity Build Statistic Reporting
#
# Reporting format ##teamcity[buildStatisticValue key='<valueTypeKey>' value='<value>']
# key='CodeCoverageAbsLCovered' is total number of lines covered
# key='CodeCoverageAbsLTotal' is total number of lines
#
# Sources:
# - https://confluence.jetbrains.com/display/TCDL/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingBuildStatistics
# - https://confluence.jetbrains.com/display/TCDL/Custom+Chart#CustomChart-listOfDefaultStatisticValues
puts "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='%i']" % total_project_lines_tested
puts "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='%i']" % total_project_lines
end

total_percentage = '%.2f' % [(total_project_lines_tested / total_project_lines.to_f) * 100.0]
puts "Test Coverage: #{total_percentage}%"
end
Expand Down
27 changes: 26 additions & 1 deletion spec/slather/coverage_service/simple_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
proj.build_directory = TEMP_DERIVED_DATA_PATH
proj.input_format = "profdata"
proj.configure
proj.send(:configure)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to the PR. Leftover or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, this isn't needed.

proj
end

Expand All @@ -30,5 +30,30 @@

fixtures_project.post
end

describe 'ci_service reporting output' do

context "ci_service is :teamcity" do
before(:each) { fixtures_project.ci_service = :teamcity }

it "should print out the coverage" do
["spec/fixtures/fixtures/fixtures.m: 3 of 6 lines (50.00%)",
"spec/fixtures/fixtures/more_files/Branches.m: 13 of 30 lines (43.33%)",
"spec/fixtures/fixturesTests/BranchesTests.m: 16 of 16 lines (100.00%)",
"spec/fixtures/fixturesTests/fixturesTests.m: 12 of 12 lines (100.00%)",
"spec/fixtures/fixturesTests/peekaviewTests.m: 11 of 11 lines (100.00%)",
"##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='55']",
"##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='75']",
"Test Coverage: 73.33%"
].each do |line|
expect(fixtures_project).to receive(:puts).with(line)
end

fixtures_project.post
end
end

end

end
end