diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..b76d2fd9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "health", + "program": "pkgs/firehose/bin/health.dart", + "request": "launch", + "type": "dart", + "env": { + "GITHUB_REPOSITORY": "dart-lang/ecosystem", + "ISSUE_NUMBER": "173", + "GITHUB_SHA": "null", + "GITHUB_STEP_SUMMARY": "/tmp/github_step_summary_mock.md", + }, + "args": [ + "--checks", + "version,changelog,license,coverage,do-not-submit" + ] + } + ] +} \ No newline at end of file diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 147c4e4f..cac9a63e 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,7 +1,8 @@ -## 0.4.1-wip +## 0.4.1 - Ensure that packages are listed in lexical order. - Require the latest `package:http`. +- Delay Github requests by a small delay to avoid http errors. ## 0.4.0 diff --git a/pkgs/firehose/lib/src/delayed_client.dart b/pkgs/firehose/lib/src/delayed_client.dart new file mode 100644 index 00000000..93cb2519 --- /dev/null +++ b/pkgs/firehose/lib/src/delayed_client.dart @@ -0,0 +1,75 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:convert'; + +import 'dart:typed_data'; + +import 'package:http/http.dart' as http; + +class DelayedClient implements http.Client { + final http.Client _client; + final Duration duration; + + factory DelayedClient(Duration duration) => DelayedClient._( + client: http.Client(), + duration: duration, + ); + + DelayedClient._({required this.duration, required http.Client client}) + : _client = client; + + @override + void close() => _client.close(); + + @override + Future delete(Uri url, + {Map? headers, Object? body, Encoding? encoding}) => + Future.delayed( + duration, + () => _client.delete(url, + body: body, encoding: encoding, headers: headers)); + + @override + Future get(Uri url, {Map? headers}) => + Future.delayed(duration, () => _client.get(url, headers: headers)); + + @override + Future head(Uri url, {Map? headers}) => + Future.delayed(duration, () => _client.head(url, headers: headers)); + + @override + Future patch(Uri url, + {Map? headers, Object? body, Encoding? encoding}) => + Future.delayed( + duration, + () => _client.patch(url, + headers: headers, body: body, encoding: encoding)); + + @override + Future post(Uri url, + {Map? headers, Object? body, Encoding? encoding}) => + Future.delayed( + duration, + () => _client.post(url, + headers: headers, body: body, encoding: encoding)); + @override + Future put(Uri url, + {Map? headers, Object? body, Encoding? encoding}) => + Future.delayed( + duration, + () => _client.put(url, + headers: headers, body: body, encoding: encoding)); + @override + Future read(Uri url, {Map? headers}) => + Future.delayed(duration, () => _client.read(url, headers: headers)); + + @override + Future readBytes(Uri url, {Map? headers}) => + Future.delayed(duration, () => _client.readBytes(url, headers: headers)); + + @override + Future send(http.BaseRequest request) => + Future.delayed(duration, () => _client.send(request)); +} diff --git a/pkgs/firehose/lib/src/github.dart b/pkgs/firehose/lib/src/github.dart index cf1b31a7..f2d763ba 100644 --- a/pkgs/firehose/lib/src/github.dart +++ b/pkgs/firehose/lib/src/github.dart @@ -6,8 +6,10 @@ import 'dart:io'; import 'package:github/github.dart'; +import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; +import 'delayed_client.dart'; import 'repo.dart'; class GithubApi { @@ -24,9 +26,14 @@ class GithubApi { : _repoSlug = repoSlug, _issueNumber = issueNumber; + final http.Client _client = DelayedClient(const Duration(milliseconds: 50)); + late GitHub github = githubAuthToken != null - ? GitHub(auth: Authentication.withToken(githubAuthToken)) - : GitHub(); + ? GitHub( + auth: Authentication.withToken(githubAuthToken), + client: _client, + ) + : GitHub(client: _client); String? get githubAuthToken => _env['GITHUB_TOKEN']; diff --git a/pkgs/firehose/lib/src/health/health.dart b/pkgs/firehose/lib/src/health/health.dart index 774c4dfe..9e4831b8 100644 --- a/pkgs/firehose/lib/src/health/health.dart +++ b/pkgs/firehose/lib/src/health/health.dart @@ -47,7 +47,6 @@ class Health { var github = GithubApi(); // Do basic validation of our expected env var. - if (!expectEnv(github.githubAuthToken, 'GITHUB_TOKEN')) return; if (!expectEnv(github.repoSlug?.fullName, 'GITHUB_REPOSITORY')) return; if (!expectEnv(github.issueNumber?.toString(), 'ISSUE_NUMBER')) return; if (!expectEnv(github.sha, 'GITHUB_SHA')) return; @@ -78,10 +77,11 @@ class Health { !github.prLabels.contains('skip-do-not-submit-check')) doNotSubmitCheck, ]; - - var checked = - await Future.wait(checks.map((check) => check(github)).toList()); - await writeInComment(github, checked); + final results = []; + for (var check in checks) { + results.add(await check(github)); + } + await writeInComment(github, results); } Future validateCheck(GithubApi github) async { diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index 0479b3b6..4f265733 100644 --- a/pkgs/firehose/pubspec.yaml +++ b/pkgs/firehose/pubspec.yaml @@ -1,6 +1,6 @@ name: firehose description: A tool to automate publishing of Pub packages from GitHub actions. -version: 0.4.1-wip +version: 0.4.1 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose environment: