Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 27 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ea65fac
add code coverage
ahmednfwela Aug 16, 2023
af67346
Merge branch 'main' of github.com:Bdaya-Dev/meilisearch-dart
ahmednfwela Sep 14, 2023
e5fdad3
initial code-excerpts
ahmednfwela Sep 21, 2023
1614344
don't fail CI if codecov fails
ahmednfwela Sep 21, 2023
ab4332c
Merge branch 'main' into code-excerpts
ahmednfwela Sep 21, 2023
be80c7f
yaml lint
ahmednfwela Sep 21, 2023
af7f4dd
fix matrix
ahmednfwela Sep 21, 2023
f0a4288
lints
ahmednfwela Sep 21, 2023
280d323
don't depend on yaml lint
ahmednfwela Sep 21, 2023
e30bd09
pub get before running
ahmednfwela Sep 21, 2023
5c93135
run on ubuntu only.
ahmednfwela Sep 21, 2023
433b277
exit code 255 for failing.
ahmednfwela Sep 21, 2023
851281b
run pub get in tool
ahmednfwela Sep 21, 2023
ada94a4
format
ahmednfwela Sep 21, 2023
f9109a0
fix key mismatch
ahmednfwela Sep 21, 2023
9dc8b44
added functionality to detect missing and extra keys
ahmednfwela Sep 21, 2023
0dc2c87
temp add keys
ahmednfwela Sep 21, 2023
b93d369
fix tool
ahmednfwela Sep 21, 2023
afed5f4
Merge branch 'main' of github.com:meilisearch/meilisearch-dart into c…
ahmednfwela Sep 21, 2023
b9aab22
added all samples
ahmednfwela Sep 21, 2023
03209bb
fix: MeiliDateTimeValueExpression should calculate seconds since epoc…
ahmednfwela Sep 21, 2023
1ad1bb9
fix datetime tests
ahmednfwela Sep 21, 2023
e617174
update mismatched keys
ahmednfwela Sep 22, 2023
ed5b488
Merge branch 'main' into code-excerpts
ahmednfwela Oct 17, 2023
e91493e
Merge branch 'main' into code-excerpts
ahmednfwela Nov 21, 2023
92ed56c
Update contributing guide
ahmednfwela Nov 22, 2023
228a95b
fix test message changing
ahmednfwela Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
467 changes: 82 additions & 385 deletions .code-samples.meilisearch.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
- name: Run integration tests
run: docker run --net="host" -v $PWD:/package -w /package dart:${{ matrix.version }} /bin/sh -c 'dart pub get && dart run test'
run: docker run --net="host" -v $PWD:/package -w /package dart:${{ matrix.version }} /bin/sh -c 'dart pub get && dart pub get -C tool && dart run test'
18 changes: 17 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- name: Install dependencies
run: |
dart pub get
dart pub get -C tool
dart pub global activate coverage
- name: Run integration tests
run: dart test --concurrency=4 --reporter=github --coverage=./coverage/reports
Expand All @@ -61,7 +62,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: dart pub get
run: |
dart pub get
dart pub get -C tool
- name: Run linter
run: dart analyze --fatal-infos && dart format . --set-exit-if-changed

Expand All @@ -75,6 +78,19 @@ jobs:
with:
config_file: .yamllint.yml

check-code-samples:
name: check .code-samples.meilisearch.yaml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: '3.0.0'
- name: check if samples changed
run: |
dart pub get
dart pub get -C tool
dart run ./tool/bin/meili.dart update-samples --fail-on-change
pana:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
- [Requirements ](#requirements-)
- [Setup ](#setup-)
- [Tests and Linter ](#tests-and-linter-)
- [Updating code samples](#updating-code-samples)
- [Git Guidelines](#git-guidelines)
- [Git Branches ](#git-branches-)
- [Git Commits ](#git-commits-)
Expand Down Expand Up @@ -76,6 +77,31 @@ dart test
dart analyze
```

### Updating code samples

Some PRs require updating the code samples (found in `.code-samples.meilisearch.yaml`), this is done automatically using code excerpts, which are actual pieces of code subject to testing and linting.

A lot of them are placed in `test/code_samples.dart`.

Also most of the tests in that file are skipped, since they are mostly duplicated in other test files.

The process to define a new code sample is as follows:
1. Add the piece of code in `test/code_samples.dart`
2. surround it with `#docregion key` and `#enddocregion`, e.g.
```
// #docregion meilisearch_contributing_1
final client = MeilisearchClient();
anything();
// #enddocregion
```
3. run this command to update the code samples
```bash
dart run ./tool/bin/meili.dart update-samples
```
4. to test if the code samples are updated correctly, run:
```bash
dart run ./tool/bin/meili.dart update-samples --fail-on-change
```
## Git Guidelines

### Git Branches <!-- omit in TOC -->
Expand Down
4 changes: 3 additions & 1 deletion lib/src/filter_builder/values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class MeiliDateTimeValueExpression extends MeiliValueExpressionBase {
"DateTime passed to Meili must be in UTC to avoid inconsistency accross multiple devices",
);

/// Unix epoch time is seconds since epoch
@override
String transform() => value.millisecondsSinceEpoch.toString();
String transform() =>
(value.millisecondsSinceEpoch / 1000).floor().toString();

@override
bool operator ==(Object other) {
Expand Down
Loading
Loading