Skip to content

Commit

Permalink
[xaprepare] Fix dotnet-install script size check (#8311)
Browse files Browse the repository at this point in the history
CI builds have been failing frequently and quietly:

    Downloading dotnet-install...
      Error: Installation of dotnet SDK 8.0.100-rc.2.23422.31 failed.

    Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed
    System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed

We were returning early when attempts to calculate the size of the
`dotnet-install` script failed, and a cached install script file was not
already on disk.  This has been fixed by ensuring that we still attempt
to download the script if the size calculation fails.

The size check failure has also been fixed by using a get request, and
logging around this prepare step has been improved.
  • Loading branch information
pjcollins authored and jonathanpeppers committed Sep 15, 2023
1 parent 1f58112 commit 551dfe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 1 addition & 4 deletions build-tools/xaprepare/xaprepare/Application/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,7 @@ static decimal SignificantDigits (decimal number, int maxDigitCount)
try {
using (var httpClient = new HttpClient ()) {
httpClient.Timeout = WebRequestTimeout;
var req = new HttpRequestMessage (HttpMethod.Head, url);
req.Headers.ConnectionClose = true;

HttpResponseMessage resp = await httpClient.SendAsync (req, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait (true);
HttpResponseMessage resp = await httpClient.GetAsync (url, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait (true);
if (!resp.IsSuccessStatusCode || !resp.Content.Headers.ContentLength.HasValue)
return (false, 0, resp.StatusCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override async Task<bool> Execute (Context context)
dotnetPath = dotnetPath.TrimEnd (new char [] { Path.DirectorySeparatorChar });

if (!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion)) {
Log.ErrorLine ($"Installation of dotnet SDK {BuildToolVersion} failed.");
Log.ErrorLine ($"Installation of dotnet SDK '{BuildToolVersion}' failed.");
return false;
}

Expand All @@ -47,7 +47,7 @@ protected override async Task<bool> Execute (Context context)
ProcessRunner.QuoteArgument ($"-bl:{logPath}"),
};
if (!Utilities.RunCommand (Configurables.Paths.DotNetPreviewTool, restoreArgs)) {
Log.ErrorLine ($"dotnet restore {packageDownloadProj} failed.");
Log.ErrorLine ($"Failed to restore runtime packs using '{packageDownloadProj}'.");
return false;
}

Expand All @@ -74,18 +74,19 @@ async Task<bool> DownloadDotNetInstallScript (Context context, string dotnetScri
string tempDotnetScriptPath = dotnetScriptPath + "-tmp";
Utilities.DeleteFile (tempDotnetScriptPath);

Log.StatusLine ("Downloading dotnet-install...");
Log.StatusLine ("Downloading dotnet-install script...");

(bool success, ulong size, HttpStatusCode status) = await Utilities.GetDownloadSizeWithStatus (dotnetScriptUrl);
if (!success) {
string message;
if (status == HttpStatusCode.NotFound) {
message = "dotnet-install URL not found";
message = $"dotnet-install URL '{dotnetScriptUrl}' not found.";
} else {
message = $"Failed to obtain dotnet-install size. HTTP status code: {status} ({(int)status})";
message = $"Failed to obtain dotnet-install script size from URL '{dotnetScriptUrl}'. HTTP status code: {status} ({(int)status})";
}

return ReportAndCheckCached (message, quietOnError: true);
if (ReportAndCheckCached (message, quietOnError: true))
return true;
}

DownloadStatus downloadStatus = Utilities.SetupDownloadStatus (context, size, context.InteractiveSession);
Expand Down Expand Up @@ -192,6 +193,7 @@ async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string
string scriptFileName = Path.GetFileName (dotnetScriptUrl.LocalPath);
string cachedDotnetScriptPath = Path.Combine (cacheDir, scriptFileName);
if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl)) {
Log.ErrorLine ($"Failed to download dotnet-install script.");
return false;
}

Expand Down

0 comments on commit 551dfe8

Please sign in to comment.