aantron / bisect_ppx

Code coverage for OCaml and ReScript
http://aantron.github.io/bisect_ppx/demo/
MIT License
302 stars 60 forks source link

Emit JSON for a Shields.io badge in the HTML report #372

Closed aantron closed 1 year ago

aantron commented 3 years ago

See https://shields.io/endpoint. This will allow an uploaded report to be used for rendering coverage percentages with shields.io. The server probably has to know to set the right Content-Type, though.

{
  "schemaVersion": 1,
  "label": "hello",
  "message": "sweet world",
  "color": "orange"
}

I would still use Coveralls for the bot and GitHub status, but link to the Bisect_ppx report and use its badge for the more accurate statistics (and IMO better-looking presentation).

zapashcanon commented 3 years ago

@aantron have you considered using OCamlPro/ocb ?

aantron commented 3 years ago

Thanks for the link.

I've looked at it now. The issue with using it is that if a repo has other dynamically generated badges, it can probably only get a consistent look between them if it uses shields.io or a similar service.

zapashcanon commented 3 years ago

What kind of look are you thinking of that is missing in ocb ? In ocb's README the exemple is made with the flat style but the classic one is also available. :)

EDIT: I just made osh, it's been made quick and dirty but it works as a PoC, using dream :grin:, a preview is online.

I'm already using bisect_ppx + dream to get a coverage badge, e.g. here and I'm doing it this way, it's a little bit ugly so I'd love to have support for this directly in bisect_ppx, but I'd also like not having to depend on an external service (except if it's written in OCaml :-)).

aantron commented 3 years ago

@zapashcanon I didn't see your edit (it doesn't trigger an email), but it sounds great. I've thought many times about making an OCaml clone of shields.io, but never did it because I already worry I have too many projects sometimes :)

The issue was not with the looks, but with the availability of dynamic integrations, which were provided by the shields.io server. Is osh meant to provide that? If so, I'd be glad to use it. osh looks down at the moment.

zapashcanon commented 3 years ago

@aantron I'll deploy it on a proper environment, I'll let you know once it's done

zapashcanon commented 3 years ago

@aantron see osh.ocamlpro.com, the code is available at gitlab.ocamlpro.com/OCamlPro/osh. There's not a lot of documentation atm but it shouldn't be hard to achieve what you want. Let me know if you have a question or want me to add a feature.

I'll also publish it on opam once I found the time to write some documentation.

aantron commented 3 years ago

Nice. I just tried it.

The issue is that I would want to use one service to ensure consistency between all badges. shields.io is capable of querying e.g. CI build status on its end, instead of repo maintainers (me in this case) having to do the integration. For Bisect badges, there is no such thing to query anyway — Bisect would generate the badge URL itself, so there is no difference between using osh and shields.io. But my repos also have CI or other badges, so if I switch to osh for coverage, I have to either risk losing visual consistency if I keep using shields.io for the other badges, or do integration work to either generate badge URLs repo-side, or contribute higher-level integrations to osh (which is the right thing to do).

zapashcanon commented 3 years ago

OK so IIUC, you'd like osh to provide something like: https://osh.ocamlpro.com/badge/cibuildstatus/?url=https://github.com/aantron/bisect_ppx ? And allow to override each parameter with additional parameters (style, label...).

aantron commented 3 years ago

Yes, something equivalent to (a subset of) the endpoints on this page: https://shields.io/category/build (edited)

aantron commented 3 years ago

Oops, linked to wrong page. https://shields.io/category/build

aantron commented 3 years ago

The single endpoint that is the most valuable to me is a GitHub Actions endpoint. After that, I could probably help out by contributing any other endpoints I may eventually need.

zapashcanon commented 3 years ago

@aantron, I've implemented it and tested it quickly, it seems to work well. Let me know if something is missing.

I can't deploy it for now as it needs a new release of c-cube/ezcurl (no user agent was set and we were rejected by the GitHub API, I fixed this in a PR that has been merged, now we just have to wait it lands in opam). cc @c-cube :)

zapashcanon commented 3 years ago

(btw, I had a look at how it's implemented in shields.io and what they do is fetching the gitHub generated SVG, grep inside it to get the status and then, generate their own badge from it... I went with the GitHub API :D)

zapashcanon commented 3 years ago

@aantron, it's online now. :)

aantron commented 3 years ago

Very nice! I put in my queue to switch over to these gradually/make some contributions! It'll become clear what to do with this issue in particular along the way. Maybe we can even host Bisect_ppx reports :P But that seems like a pretty big project since a full coverage hosting service would need a lot of integrations and the like. So I'll probably stick with just outputting a badge URL.

aantron commented 2 years ago

@zapashcanon I've reached this issue and I want to work with osh. I see that it is hosted on the OCP GitLab. However, I can't find any way (in a few minutes) to create a user account there. What should I do?

zapashcanon commented 2 years ago

We're discussing it, I'll come back to you very soon. You need an account to access the source code ? Or to contribute to osh ?

aantron commented 2 years ago

Contribute. I can see the code.

zapashcanon commented 2 years ago

@aantron can you send me an email to *** so we can create your account ?

aantron commented 2 years ago

Sent an email.

I want to ask about the "meta" of this. In case osh becomes widely used (and I will try to help that), it will likely attract more contributors that want to add new badge endpoints. If they have to get individual accounts in this way, it will be an obstacle.

zapashcanon commented 2 years ago

Yes, we know about the issue. We'll see if it's possible to open registration but we need to consider some potential issues first. Another solution would be to have a mirror on GitHub and to merge manually things into our GitLab. I'll let you know once we decided the way we go.

aantron commented 2 years ago

Great, thanks!

zapashcanon commented 2 years ago

@aantron it's now possible to register easily on our gitlab (the account will have to be allowed by an admin but we'll get a notification and either accept it or send an e-mail to know who's the person creating the account if we can't guess)

aantron commented 1 year ago

I'm going to close this for now, as I was formerly the only interested user, but I've since moved away from most badges, as changes to the GitHub page layout have made most badges redundant. Coverage badges are basically the only ones I still use, but I probably wouldn't introduce them in a new repo of mine.