Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .github/scripts/check-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ file1='pubspec.yaml'
file2='example/pubspec.yaml'
file3='example/pubspec.lock'
file4='README.md'
file5='lib/src/version.dart'
changelog_file='CHANGELOG.md'
ret=0

file_tag1=$(grep '^version: ' $file1 | cut -d ':' -f 2 | tr -d ' ')
file_tag2=$(grep 'meilisearch: "' $file2 | cut -d ':' -f 2 | tr -d '"' | tr -d ' ')
file_tag3=$(grep 'meilisearch' -A 6 $file3 | grep 'version: ' | cut -d ':' -f2 | tr -d '"' | tr -d ' ')
file_tag4=$(grep 'meilisearch: ' $file4 | cut -d '^' -f2)
if [ "$current_tag" != "$file_tag1" ] || [ "$current_tag" != "$file_tag2" ] || [ "$current_tag" != "$file_tag3" ] || [ "$current_tag" != "$file_tag4" ]; then
file_tag5=$(grep -o "[0-9\.]" $file5 | tr -d '[:space:]')
if [ "$current_tag" != "$file_tag1" ] || [ "$current_tag" != "$file_tag2" ] || [ "$current_tag" != "$file_tag3" ] || [ "$current_tag" != "$file_tag4" ] || [ "$current_tag" != "$file_tag5" ]; then
echo "Error: the current tag does not match the version in package file(s)."
echo "$file1: found $file_tag1 - expected $current_tag"
echo "$file2: found $file_tag2 - expected $current_tag"
echo "$file3: found $file_tag3 - expected $current_tag"
echo "$file4: found $file_tag4 - expected $round_current_tag"
echo "$file4: found $file_tag4 - expected $current_tag"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't found the definition of the$round_current_tag so I replaced with $current_tag

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mistake, well spotted

echo "$file5: found $file_tag5 - expected $current_tag"
ret=1
fi

Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m

Make a PR modifying the version in:

- the file [`lib/src/version.dart:2`](./lib/src/version.dart).

```dart
static const String current = 'X.X.X';
```

- the file [`pubspec.yaml`](./pubspec.yaml).

```yaml
Expand Down
3 changes: 3 additions & 0 deletions lib/src/http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ abstract class HttpRequest {
/// Timeout in milliseconds for opening a url.
int? get connectTimeout;

/// Retrieve all headers used when Http calls are made.
Map<String, dynamic> headers();

/// GET method
Future<Response<T>> getMethod<T>(
String path, {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/http_request_impl.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:meilisearch/src/version.dart';
import 'http_request.dart';
import 'exception.dart';

Expand All @@ -9,6 +10,7 @@ class HttpRequestImpl implements HttpRequest {
headers: <String, dynamic>{
if (apiKey != null) 'Authorization': 'Bearer ${apiKey}',
'Content-Type': 'application/json',
'User-Agent': Version.qualifiedVersion,
},
responseType: ResponseType.json,
connectTimeout: connectTimeout ?? 0,
Expand All @@ -25,6 +27,11 @@ class HttpRequestImpl implements HttpRequest {

final Dio dio;

@override
Map<String, dynamic> headers() {
return this.dio.options.headers;
}

@override
Future<Response<T>> getMethod<T>(
String path, {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Version {
static const String current = '0.5.0';

static String get qualifiedVersion {
return "MeiliSearch Dart (v${current})";
}
}
40 changes: 40 additions & 0 deletions test/analytics_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'dart:io';

import 'package:meilisearch/src/version.dart';
import 'package:test/test.dart';

import 'utils/client.dart';

void main() {
final RegExp semVer = new RegExp(
r"version\:.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?");

group('Version', () {
test('matches with the current package version in pubspec.yaml', () {
final path = '${Directory.current.path}/pubspec.yaml';
String data = new File(path).readAsStringSync();
String? version = semVer.stringMatch(data)?.replaceFirst('version: ', '');

expect(version, isNotNull);
expect(Version.current, isNotNull);
expect(Version.current, equals(version));
});
});

group('Analytics', () {
setUpClient();

test('sends the User-Agent header in every call', () {
final headers = client.http.headers();

expect(headers.keys, contains('User-Agent'));
expect(headers['User-Agent'], isNotNull);
});

test('has current version data from Version class', () {
final headers = client.http.headers();

expect(headers['User-Agent'], equals(Version.qualifiedVersion));
});
});
}