csMACnz / coveralls.net

Coveralls uploader for .Net Code coverage
MIT License
87 stars 27 forks source link

TeamCity Git Data Resolver #73

Open zone117x opened 6 years ago

zone117x commented 6 years ago

Would be nice to have a class TeamCityGitDataResolver : IGitDataResolver

For example, when the Codecov.io bash script is ran in a teamcity build step, the following output is given:

[19:08:41]  [Step 4/5] ==> TeamCity CI detected.
[19:08:41]  [Step 4/5]     Teamcity does not automatically make build parameters available as environment variables.
[19:08:41]  [Step 4/5]     Add the following environment parameters to the build configuration
[19:08:41]  [Step 4/5]     env.TEAMCITY_BUILD_BRANCH = %teamcity.build.branch%
[19:08:41]  [Step 4/5]     env.TEAMCITY_BUILD_ID = %teamcity.build.id%
[19:08:41]  [Step 4/5]     env.TEAMCITY_BUILD_URL = %teamcity.serverUrl%/viewLog.html?buildId=%teamcity.build.id%
[19:08:41]  [Step 4/5]     env.TEAMCITY_BUILD_COMMIT = %system.build.vcs.number%
[19:08:41]  [Step 4/5]     env.TEAMCITY_BUILD_REPOSITORY = %vcsroot.<YOUR TEAMCITY VCS NAME>.url%

Then after following the instructions, it proceeds to work as expected.

Could this project implement a similar way? Thoughts?

I may attempt to implement this if reasonable. Would appreciate any insight.

csMACnz commented 6 years ago

You read my mind. TeamCity was going to be next, I just started refactoring to support Travis as well.

I also want to add the ability to it to write out teamcity coverage stats as well

csMACnz commented 6 years ago

It seems sensible to use the same names as codcov, as people may already have them set up. It might also be possible to call the api and pull the parameters automagically, I will have to see.

csMACnz commented 6 years ago

In the meantime it works with command line arguments so you can still make it work. Look at one of the existing Travis examples in csMACnz/Coveralls.net-Samples branches.

csMACnz commented 6 years ago

As far as i can see, env.BUILD_VCS_NUMBER is standard for commit, and env.TEAMCITY_VERSION is a standard way to detect on teamcity. Othrwise there is not enough data already in there to make it magically work. The server url is a parameter, so would need to be exposed, that work is better spent adding env-vars. Also if anyone is running this inside docker, env vars are easier to setup and pass through.

Copy codecov it is.

zone117x commented 6 years ago

I actually ran into annoyances getting some of those server env parameters into the build script and did not get that codecov message to go away. Despite that message still appearing, the codecov bash script is able to gather everything it needs for a full report with git info. Its not completely clear to me how it's doing that.

csMACnz commented 6 years ago

pushed a first draft to develop, will get some testing done and should make it in the next next release (probably 1.1.0, 1.0.0 is gonna be hopefully just the stable 2.1 tools support release)

csMACnz commented 6 years ago

It looks like apart from the complexity of pull requests, using env.BUILD_VCS_NUMBER and pushing to the alternative commit_sha value rather than pushing all the git data, it should get to a mostly just works for master, customise for PRs state. But as i say, needs testing.

zone117x commented 6 years ago

Awesome! Thanks for doing this so fast. Can you push a nuget prerelease package? Currently using v1.0.0-beta0003 with the dotnet 2.1 RC1 build tools.

csMACnz commented 6 years ago

From memory appveyor has a nuget feed of the artifacts, in the meantime you might find it there. If I get develop stable enough there is a change it will merge into the next pre release of 1.0.0, otherwise.

zone117x commented 6 years ago

Looks liked the dev appveyor build failed to find a nupkg file

zone117x commented 6 years ago

I compiled the latest source and tried using the new version of the tool. Stilling getting a "no git data" message. I'm not sure if the teamcity adapter is not implemented correctly, or if my server is still using the previous version. Please update this issue once the nuget package is pushed so I can test!

csMACnz commented 6 years ago

sorry, forgot to wire in the new classes, I've added tests and chased out a few bugs in my logic as well. You could try again if you have the time or inclination.

zone117x commented 6 years ago

I'd love to test, could you fix the appveyor nupkg building? https://ci.appveyor.com/project/MarkClearwater/coveralls-net/build/1.1.0-unstable.6.build.1322/job/ebcn8bqjg4fidp5j#L1605 I can pull the package from appveyor.

csMACnz commented 6 years ago

So sorry about that I lost a local commit along the way between my two dev machines. all sorted now 🤦‍♂️

https://ci.appveyor.com/project/MarkClearwater/coveralls-net/build/1.1.0-unstable.9.build.1325/job/x53nnpcxov851sjg/artifacts

csMACnz commented 6 years ago

I've gotten access to teamcity.jetbrains.com opensource build service to build and test out this functionality proper.

csMACnz commented 4 years ago

The functionality from the Develop Branch is now heading towards a 2.0.0 release (there is a first alpha published. Certainly needs more attention and feedback from anyone who is actually using this on teamcity. there is a build running of itself on https://teamcity.jetbrains.com/ that does publish it's own coverage, but i probably need to make the usage instructions more visible somewhere. And a solution for loading all the git metadata (commit author, commit message) or guidance on if these are required could be useful. The solution to use the commit_sha only seems potentially better for some cases.