xp-forge / coverage

Code coverage for XP Framework unittests
2 stars 0 forks source link

Add upload to coveralls #7

Open thekid opened 6 years ago

thekid commented 6 years ago

Usage

$ xp coverage -p src/main/php -j coveralls.json,$API_TOKEN src/test/php
# ...
$ curl -x POST -F 'json_file=@coveralls.json' https://coveralls.io/api/v1/jobs

API

POST https://coveralls.io/api/v1/jobs
{
   "run_at" : "2018-09-23 15:06:08 +0000",
   "git" : {
      "head" : {
         "author_name" : "Timm Friebe",
         "committer_email" : "thekid@example.com",
         "author_email" : "thekid@example.com",
         "id" : "d03c81753e382c494697e08f5a75826c3858a608",
         "message" : "Fix newline and comment handling inside structures",
         "committer_name" : "Timm Friebe"
      },
      "remotes" : [
         {
            "url" : "git@github.com:xp-forge/yaml.git",
            "name" : "origin"
         }
      ],
      "branch" : "master"
   },
   "repo_token" : "...",
   "service_name" : "php-coveralls",
   "service_event_type" : "manual",
   "source_files" : [
      {
         "coverage" : [
            null,
            null,
            0
         ],
         "source" : "<?php namespace xp;\n\n\\lang\\ClassLoader::registerPath(__DIR__);",
         "name" : "src\\main\\php\\autoload.php"
      },
      …
   ]
}

See https://docs.coveralls.io/api-reference

Outcome

coveralls

The paths with the Windows directory separator \ break the detailed view in Coveralls and should probably be translated to / before uploading!

thekid commented 6 years ago

The head commit details can be fetched by this:

$ git log -1 --pretty=format:'%H%n%aN%n%ae%n%cN%n%ce%n%s'
d03c81753e382c494697e08f5a75826c3858a608
Timm Friebe
thekid@example.com
Timm Friebe
thekid@example.com
Fix newline and comment handling inside structures
thekid commented 6 years ago

Basically, after test has run:

  1. For each file:
    1. Generate coverage arrays for each line, e.g. [null, 1, 0, null, 4, 15, null]
    2. Collect sourcecode into a string
  2. Gather head commit details
  3. Set "service_name" : "...", "service_event_type" : "..."
  4. Set "repo_token" : "..."

...and then write all that to a JSON file.