cainus / codecov.io

MIT License
44 stars 50 forks source link

Add support for snap-ci #17

Closed kentcdodds closed 9 years ago

kentcdodds commented 9 years ago

Closes #16

I couldn't find a way to get owner or repo from snap's environment variables :-(

codecov-io commented 9 years ago

Current coverage is 77.65%

Merging #17 into master will change coverage by +1.70% by 3f5ffe3

Coverage Diff

@@            master     #17   diff @@
======================================
  Files           14      15     +1
  Stmts           79      85     +6
  Branches        32      34     +2
  Methods         23      25     +2
======================================
+ Hit             60      66     +6
  Partial          1       1       
  Missed          18      18       

Powered by Codecov

kentcdodds commented 9 years ago

Just forced pushed an update because I forgot to add this to getConfiguration (and it broke my build)

stevepeak commented 9 years ago

Thanks @kentcdodds. Does SnapCI work with open source too? If they have an builds endpoint I can update our server to not require the token for public repos.

kentcdodds commented 9 years ago

I hooked them up using GitHub on my open source project, so yeah, they do.

stevepeak commented 9 years ago

Can you send me a link to their api endpoint to get builds/jobs. Thanks!

kentcdodds commented 9 years ago

Updated the PR to use the SNAP_COMMIT environment variable. I've asked someone from snap to help with the api endpoint. Thanks!

akshaykarle commented 9 years ago

Hey guys, dev from snap-ci here. You can get the latest build using - GET /project/:owner/:repository/branch/:branch_name/pipelines/{latest,newest} you can find more info and examples in our docs. Right now all our API endpoints require authentication including the public builds. You can supply the username and api token in the url for now. We will look into the possibility of removing the authentication for public builds soon. Let me know if you have any problems integrating.

stevepeak commented 9 years ago

@akshaykarle thank you for the reply! Does a single uses api key work for all public repos? I ask because I'd like to hookup snap-ci into Codecov backend so that customers will no longer need repo tokens making the installation more seamless. I can use "my personal" access token to request public repos if necessary until you remove the requirement. Thanks!

akshaykarle commented 9 years ago

@stevepeak unfortunately no. You can use the API token only to access the builds that you collaborate on. So you may have to ask users to enter their API token and username. Can they supply this as arguments to codecov.io?

stevepeak commented 9 years ago

@akshaykarle unfortunately it wont work in that case. Until snap-ci can allow access to public builds with no token customers will need to provide the repo token.

Is there a way to get notified if this changes in the future?

kentcdodds commented 9 years ago

@stevepeak, any way I can be notified when I can start using snap-ci to report coverage even with a work-around?

stevepeak commented 9 years ago

I'll publish this to npm now. Thanks!

kentcdodds commented 9 years ago

It's definitely published and the library works, but codecov throws up when I try to make the request: https://snap-ci.com/kentcdodds/ng-stats/branch/master/logs/defaultPipeline/16/Coverage?back_to=build_history

kentcdodds commented 9 years ago
$ cat ./coverage/lcov.info | codecov
configuration:  { service: 'snapci',
  build: '16',
  commit: '6a60680fac80b5cf2c491e9a6bba42b20f81e14a',
  branch: 'master',
  pull_request: undefined,
  token: '********',
  package: 'node' }
error sending to codecov.io:  { [Error: non-success response]
  detail: 
   { statusCode: 400,
     body: '{"message": "Invalid value \'snapci\' (str): must be ci-provider (at service)", "uploaded": false, "meta": {"status": 400, "request": "2476771e-db9a-4f9d-a395-4d1704ece149"}}',
     request: 
      { url: 'https://codecov.io/upload/v2?service=snapci&build=16&commit=6a60680fac80b5cf2c491e9a6bba42b20f81e14a&branch=master&pull_request=&token=********&package=node',
        body: 'TN:\nSF:/var/snap-ci/repo/src/index.js\nFN:8,_interopRequireDefault\nFN:28,(anonymous_2)\nFN:30,(anonymous_3)\nFN:49,hijackDigest\nFN:56,$digest\nFN:65,isChromeApp\nFN:75,autoload\nFN:80,(anonymous_8)\nFN:86,showAngularStats\nFN:169,(anonymous_10)\nFN:173,(anonymous_11)\nFN:183,track\nFN:187,(anonymou    ........................ etc...
stevepeak commented 9 years ago

Fixed the issue with snapci, I should have caught this before, sorry for that: d61345c9bff7204a969d6352e0bc8c986589f681 (published version that fixes it)

kentcdodds commented 9 years ago

Verified. Thanks!

kentcdodds commented 9 years ago

Well... It worked on one project and failed on another. Any ideas?

stevepeak commented 9 years ago

Was the token included on the failed build? That is odd indeed. Perhaps you can transition to the bash uploader.

- cat ./coverage/lcov.info | ./node_modules/.bin/codecov
+ bash <(curl -s https://codecov.io/bash) -f ./coverage/lcov.info
kentcdodds commented 9 years ago

Well I feel dumb... I didn't have the token :-( 100% coverage :-) https://codecov.io/github/kentcdodds/api-check

stevepeak commented 9 years ago

Hey no problem! It happens to the best of us. Nice job with 100% coverage!

kentcdodds commented 9 years ago

heh, really helps when you have a githook that doesn't allow you to commit anything less than 100% code coverage :-) https://github.com/kentcdodds/api-check/blob/master/package.json#L46

-Kent C. Dodds

On Mon, Jun 22, 2015 at 11:56 AM, Steve Peak notifications@github.com wrote:

Hey no problem! It happens to the best of us. Nice job with 100% coverage!

— Reply to this email directly or view it on GitHub https://github.com/cainus/codecov.io/pull/17#issuecomment-114199197.

stevepeak commented 9 years ago

I'm going to patch the server to chop off the var/snap-ci/repo automatically. So the files line up correctly.

kentcdodds commented 9 years ago

Perfect. Thanks!

-Kent C. Dodds

On Mon, Jun 22, 2015 at 11:57 AM, Steve Peak notifications@github.com wrote:

I'm going to patch the server to chop off the var/snap-ci/repo automatically. So the files line up correctly.

— Reply to this email directly or view it on GitHub https://github.com/cainus/codecov.io/pull/17#issuecomment-114199532.

akshaykarle commented 9 years ago

@stevepeak I've already spoken to our product owner about using the API without auth for public builds and we've put the feature in our backlog. We don't have a public listing of the backlog yet, but you can usually keep track of what is new on snap from our docs, blogs and what's new. I can get back to you once this is available so that we can make the codecov experience better.

stevepeak commented 9 years ago

@akshaykarle thank you for doing this! I look forward to this change of API. Cheers!

kentcdodds commented 9 years ago

@akshaykarle, looks like there is no SNAP_BRANCH environment variable available for pull request builds :-( This breaks codecov... Here's some useful output from my private build:

All of the environment variables available from snap

$ export SNAP_CI=true
$ export CI=true
$ export SNAP_CACHE_DIR=/var/go
$ export LANG=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ export SNAP_WORKING_DIR=/var/snap-ci/repo
$ export SNAP_PIPELINE_COUNTER=1
$ export SNAP_STAGE_NAME=Test
$ export SNAP_PULL_REQUEST_NUMBER=1
$ export SNAP_UPSTREAM_BRANCH=master
$ export SNAP_COMMIT=fb4aec4b75e8c8efe732ae421b0f4e2a06b7214d
$ export SNAP_COMMIT_SHORT=fb4aec4
$ export SNAP_TRACKING_PIPELINE=true
$ export SNAP_INTEGRATION_PIPELINE=false

The attempt to send coverage stats to codecov:

configuration:  { service: 'snap',
  build: '1',
  commit: 'fb4aec4b75e8c8efe732ae421b0f4e2a06b7214d',
  branch: undefined,
  pull_request: '1',
  token: '********',
  package: 'node' }
error sending to codecov.io:  { [Error: non-success response]
  detail: 
   { statusCode: 400,
     body: '{"uploaded": false, "meta": {"status": 400, "request": "1b1d451e-055a-46f5-9e06-698feb2ac8a8"}, "message": "Invalid value {\'package\': \'node\', \'build\': \'1\', \'pull_request\': \'1\', \'service\': \'snap\', \'commit\': \'fb4aec4b75e8c8efe732ae421b0f4e2a06b7214d\', \'token\': \'********\'} (dict): missing required properties: [\'branch\']"}',
     request: 
      { url: 'https://codecov.io/upload/v2?service=snap&build=1&commit=fb4aec4b75e8c8efe732ae421b0f4e2a06b7214d&branch=&pull_request=1&token=********&package=node',
        body: 'TN:\nSF:/var/snap-ci/repo/app/index.common.js\nFNF:0\

... etc

So it's missing branch because SNAP_BRANCH is not available in the PR build... Why is that? Is it a bug? Can it be fixed? Are we going to have to figure out the branch ourselves via git?

kentcdodds commented 9 years ago

Uh oh... Using snap-shell if I execute $ git rev-parse --abbrev-ref HEAD I get: master even on the PR build... If I execute $ git branch, I get:

* master
  pull-1

This tells me that snap-ci has no concept of pull request branches... What do you think a timeline would be to make it possible for me to send what branch this PR is for to codecov @akshaykarle? This basically makes codecov not work with PRs when building with snap. A real downer :-(

kentcdodds commented 9 years ago

@stevepeak, what does snap need to do for this?

akshaykarle commented 9 years ago

@kentcdodds @stevepeak I've just sent PR #18 to resolve the issue with pull request builds.

We don't set the $SNAP_COMMIT environment variable purposely because for pull request builds your build is really running on an unmerged upstream branch from the pull request changes. The absence of $SNAP_COMMIT environment variable is also used to identify that it is a pull request build. The branch you are integrating with is identified in the build using the $SNAP_UPSTREAM_COMMIT environment variable hence I decided to use that if the SNAP_COMMIT environment variable was not preset.