Skip to content

Commit

Permalink
Use header of redirect instead of parsing content (actions#1874)
Browse files Browse the repository at this point in the history
* Use header of redirect instead of parsing content

* Add exception so we don't hit 404s later

* Fix typo

* Update SelfUpdaterL0.cs
  • Loading branch information
fhammerl authored May 9, 2022
1 parent 7ba4f85 commit 628f462
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Test/L0/Listener/SelfUpdaterL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ private async Task FetchLatestRunner()
var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, "https://github.com/actions/runner/releases/latest"));
if (response.StatusCode == System.Net.HttpStatusCode.Redirect)
{
var redirect = await response.Content.ReadAsStringAsync();
var redirectUrl = response.Headers.Location.ToString();
Regex regex = new Regex(@"/runner/releases/tag/v(?<version>\d+\.\d+\.\d+)");
var match = regex.Match(redirect);
var match = regex.Match(redirectUrl);
if (match.Success)
{
latestVersion = match.Groups["version"].Value;
Expand All @@ -63,6 +63,10 @@ private async Task FetchLatestRunner()
_packageUrl = $"https://github.com/actions/runner/releases/download/v{latestVersion}/actions-runner-{BuildConstants.RunnerPackage.PackageName}-{latestVersion}.zip";
#endif
}
else
{
throw new Exception("The latest runner version could not be determined so a download URL could not be generated for it. Please check the location header of the redirect response of 'https://github.com/actions/runner/releases/latest'");
}
}
}

Expand Down

0 comments on commit 628f462

Please sign in to comment.