Skip to content

Commit

Permalink
Github release retries (#1651)
Browse files Browse the repository at this point in the history
* Add retries to Github release steps
  • Loading branch information
howardlopez committed Oct 18, 2018
1 parent ec24754 commit 677eabd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion build/gh-release.php
Expand Up @@ -23,13 +23,31 @@
chdir(dirname(__DIR__));
$message = `chag contents -t "$tag"` or die('Chag could not find or parse the tag');

// Add retry middleware
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(\GuzzleHttp\Middleware::retry(
function ($retries, $request, $response) {
$statusCode = $response->getStatusCode();
if ($retries < 3 && !in_array($statusCode, [200, 201, 202])) {
echo "Attempt failed with status code {$statusCode}: "
. $response->getBody();
return true;
}
return false;
},
function ($retries) {
return 1000 * (1 + $retries);
}
));

// Create a GitHub client.
$client = new GuzzleHttp\Client([
'base_uri' => 'https://api.github.com/',
'headers' => ['Authorization' => "token $token"],
'handler' => $stack,
]);

// Create the release
// Publish the release
$response = $client->post("repos/${owner}/${repo}/releases", [
'json' => [
'tag_name' => $tag,
Expand Down

0 comments on commit 677eabd

Please sign in to comment.