meilisearch / meilisearch-dart

The Meilisearch API client written for Dart
https://meilisearch.com
MIT License
77 stars 26 forks source link

Create code samples from code, a.k.a. code excerpts #358

Closed ahmednfwela closed 9 months ago

ahmednfwela commented 11 months ago

Pull Request

What does this PR do?

This PR completely automates updating the code samples file .code-samples.meilisearch.yaml it creates a new PRIVATE tool that does 2 things

  1. updates the sample file from source code (run by contributors)
  2. check if the sample file is up to date with source code (run in CI)

the private tool checks dart files in lib/ and test/ directory for lines that follow this pattern:

// #docregion key
anything()
// #enddocregion

where key is a key in .code-samples.meilisearch.yaml

This run shows CI fail in action, due to format mismatch for key search_parameter_guide_show_ranking_score_1 between code file and yaml file.

This commit https://github.com/meilisearch/meilisearch-dart/pull/358/commits/f9109a0d7fa11f98e99bf694a79ff236e81f384e shows how to fix the failed run, by running dart run ./tool/bin/meili.dart update-samples in the root directory of the repo.

this should simplify adding samples, and avoid issues like https://github.com/meilisearch/meilisearch-dart/pull/357


Update

I have also added functionality to detect missing and useless keys, see this failing run for example: https://github.com/meilisearch/meilisearch-dart/actions/runs/6262599763/job/17005143489?pr=358#step:4:159

PR checklist

WIP

Thank you so much for contributing to Meilisearch!

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (bf1f5d4) 82.03% compared to head (228a95b) 82.03%. Report is 28 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #358 +/- ## ======================================= Coverage 82.03% 82.03% ======================================= Files 57 57 Lines 1353 1353 ======================================= Hits 1110 1110 Misses 243 243 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ahmednfwela commented 11 months ago

@curquiza @brunoocasali the internal tool still needs more work, but I want your opinion if you agree with this approach.

ahmednfwela commented 9 months ago

@brunoocasali Yes we can definitely do that with any language that supports comments, the tooling is language agnostic.

we can ship the tooling as an exe file that's built from a different repository

ahmednfwela commented 9 months ago

bors merge

meili-bors[bot] commented 9 months ago

Build succeeded: