Skip to content

Commit 0725c61

Browse files
Don't always use cached dotnet-install script (#9780)
Context: #9761 Partial backport of a941e34 Update `build-tools/xaprepare` to improve reliability when running `Step_InstallDotNetPreview`. `Step_InstallDotNetPreview` will cache e.g. `dotnet-install.sh` into `$HOME/android-archives`, but there was no logic to verify that it was still *valid*. We've been seeing some recurring build failures in **macOS > Build** such as: Downloading dotnet-install script... Warning: Using cached installation script found in '/Users/builder/android-archives/dotnet-install.sh' Discovering download URLs for dotnet SDK '10.0.100-preview.2.25102.3'... Downloading dotnet archive... dotnet archive URL https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz not found Downloading dotnet archive... dotnet archive URL https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-arm64.10.0.100-preview.2.25102.3.tar.gz not found Downloading dotnet archive... Warning: Failed to obtain dotnet archive size. HTTP status code: InternalServerError (500) Downloading dotnet archive... Warning: Failed to obtain dotnet archive size. HTTP status code: InternalServerError (500) Error: Installation of dotnet SDK '10.0.100-preview.2.25102.3' failed. Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed at Xamarin.Android.Prepare.Scenario.Run(Context context, Log log) in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Application/Scenario.cs:line 50 at Xamarin.Android.Prepare.Context.Execute() in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Application/Context.cs:line 488 at Xamarin.Android.Prepare.App.Run(String[] args) in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Main.cs:line 155 Indeed, [`dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz`][0] no longer exists on <https://dotnetcli.azureedge.net>. The problem, though, is that .NET changed the CDN that is used in the past month, and that's not the correct URL. A newer `dotnet-install.sh` reports: % bash "…/dotnet-install.sh" "--version" "10.0.100-preview.2.25102.3" "--install-dir" "/Volumes/Xamarin-Work/src/dotnet/android/bin/Release/dotnet" "--verbose" "--dry-run … dotnet-install: Link 0: primary, 10.0.100-preview.2.25102.3, https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-x64.tar.gz dotnet-install: Link 1: legacy, 10.0.100-preview.2.25102.3, https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-x64.10.0.100-preview.2.25102.3.tar.gz dotnet-install: Link 2: primary, 10.0.100-preview.2.25102.3, https://ci.dot.net/public/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-x64.tar.gz dotnet-install: Link 3: legacy, 10.0.100-preview.2.25102.3, https://ci.dot.net/public/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-x64.10.0.100-preview.2.25102.3.tar.gz Note the different domain, <https://builds.dotnet.microsoft.com>! Update `Step_InstallDotNetPreview` to try to install .NET potentially *twice*: the first time using the cached `dotnet-install.sh`, and *if that fails*, it tries again after downloading a *new* `dotnet-install.sh`. Hopefully this will fix the build failure on this machine! [0]: https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz Co-authored-by: Jonathan Pryor <jonpryor@vt.edu>
1 parent 8c8c94f commit 0725c61

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ protected override async Task<bool> Execute (Context context)
2121
var dotnetPath = Configurables.Paths.DotNetPreviewPath;
2222
dotnetPath = dotnetPath.TrimEnd (new char [] { Path.DirectorySeparatorChar });
2323

24-
if (!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion)) {
24+
if (!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion, useCachedInstallScript: true) &&
25+
!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion, useCachedInstallScript: false)) {
2526
Log.ErrorLine ($"Installation of dotnet SDK '{BuildToolVersion}' failed.");
2627
return false;
2728
}
@@ -77,17 +78,18 @@ protected override async Task<bool> Execute (Context context)
7778
return true;
7879
}
7980

80-
async Task<bool> DownloadDotNetInstallScript (Context context, string dotnetScriptPath, Uri dotnetScriptUrl)
81+
async Task<bool> DownloadDotNetInstallScript (Context context, string dotnetScriptPath, Uri dotnetScriptUrl, bool useCachedInstallScript)
8182
{
8283
string tempDotnetScriptPath = dotnetScriptPath + "-tmp";
8384
Utilities.DeleteFile (tempDotnetScriptPath);
8485

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

87-
if (File.Exists (dotnetScriptPath)) {
88+
if (useCachedInstallScript && File.Exists (dotnetScriptPath)) {
8889
Log.WarningLine ($"Using cached installation script found in '{dotnetScriptPath}'");
8990
return true;
9091
}
92+
Utilities.DeleteFile (dotnetScriptPath);
9193

9294
Log.StatusLine ($" {context.Characters.Link} {dotnetScriptUrl}", ConsoleColor.White);
9395
await Utilities.Download (dotnetScriptUrl, tempDotnetScriptPath, DownloadStatus.Empty);
@@ -173,7 +175,7 @@ string[] GetInstallationScriptArgs (string version, string dotnetPath, string do
173175
return args.ToArray ();
174176
}
175177

176-
async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string version, bool runtimeOnly = false)
178+
async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string version, bool useCachedInstallScript, bool runtimeOnly = false)
177179
{
178180
string cacheDir = context.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory);
179181

@@ -183,7 +185,7 @@ async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string
183185
Uri dotnetScriptUrl = Configurables.Urls.DotNetInstallScript;
184186
string scriptFileName = Path.GetFileName (dotnetScriptUrl.LocalPath);
185187
string cachedDotnetScriptPath = Path.Combine (cacheDir, scriptFileName);
186-
if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl)) {
188+
if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl, useCachedInstallScript)) {
187189
return false;
188190
}
189191

0 commit comments

Comments
 (0)