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

Add retries to pub.dev/api/ calls #199

Merged
merged 4 commits into from
Nov 22, 2023
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
3 changes: 1 addition & 2 deletions .github/workflows/post_summaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
github.event.workflow_run.event == 'pull_request'
continue-on-error: true
steps:

Expand Down
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.33

- Retry calls to pub.dev API.

## 0.3.32

- Fix an issue validating pre-release git publishing tags (#176).
Expand Down
18 changes: 16 additions & 2 deletions pkgs/firehose/lib/src/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Pub {
http.Client get httpClient => _httpClient ??= http.Client();

Future<bool> hasPublishedVersion(String name, String version) async {
var response =
await httpClient.get(Uri.parse('https://pub.dev/api/packages/$name'));
var uri = Uri.parse('https://pub.dev/api/packages/$name');
var response = await getCall(uri, retries: 3);
if (response.statusCode != 200) {
return false;
}
Expand All @@ -26,6 +26,20 @@ class Pub {
.contains(version);
}

Future<http.Response> getCall(Uri uri, {required int retries}) async {
for (var i = 0; i < retries + 1; i++) {
try {
var response = await httpClient.get(uri);
return response;
} catch (e) {
if (i >= retries) {
rethrow;
}
}
}
throw AssertionError('This should be unreachable');
}

void close() {
_httpClient?.close();
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
version: 0.3.32
version: 0.3.33
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down