Skip to content

Conversation

@mfbsouza
Copy link
Contributor

Fixes issue #358.

Description:
This PR adds support for file browsing and git integration when using coveralls with option --coveralls-id=REPO_TOKEN

Details:
For file browsing to work, coveralls expects that the path stored in the "source_files" key it's the same file path for the git repository. To ensure that, this adds the ability to kcov to find the git root path when running it inside of a git project and use it as the strip_path for generating the "source_files" key-pair values.

Git integration was done by adding to the coveralls.out file the expected information defined in coveralls API documentation

Tested with:
What my test repo looks like:

.
├── build.zig
├── build.zig.zon
├── CONTRIBUTING.md
├── kcov-output
│   ├── ...
├── LICENSE
├── README.md
├── shell.nix
├── src
│   ├── memory
│   │   ├── allocator.c
│   │   └── allocator.h
│   └── queue
│       ├── circular_queue.c
│       └── circular_queue.h
├── tests
│   ├── allocator_tests.cpp
│   └── circular_queue_tests.cpp
└── zig-out
    └── bin
        └── boislib_tests

How I ran kcov:
kcov --clean --exclude-pattern=nix,usr,local,cache,_tests.cpp --coveralls-id=MY_REPO_TOKEN kcov-output ./zig-out/bin/boislib_tests

coveralls.out generated:

 cat ./kcov-output/boislib_tests.e67c7dce/coveralls.out
{
 "repo_token": "MY_REPO_TOKEN",
 "git": {
  "head": {
   "id": "9edb5cc7945c5ba3c2055fe896a251d0f5521dfe",
   "author_name": "Matheus 'Bois' Souza",
   "author_email": "mfbsouza.it@gmail.com",
   "committer_name": "GitHub",
   "committer_email": "noreply@github.com",
   "message": "Moving project to use Zig as the build system (#1)"
  },
  "branch": "main"
 },
 "source_files": [
  {
   "name": "src/queue/circular_queue.c",
   "source_digest": "0xc59388d1",
   "coverage": [...]
  },
  {
   "name": "src/memory/allocator.c",
   "source_digest": "0x02902e08",
   "coverage": [...]
  }
 ]
}

What it looks like on coveralls:
image

@SimonKagstrom
Copy link
Owner

Nice, thanks!

I'll investigate the ci failures. I don't think they have anything to do with your changes.

@SimonKagstrom SimonKagstrom merged commit 30d37a3 into SimonKagstrom:master May 16, 2025
5 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants