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

Fix error message from FindDotNetCliPackage task #6630

Merged
2 commits merged into from
Dec 2, 2020
Merged
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
73 changes: 37 additions & 36 deletions src/Microsoft.DotNet.Helix/Sdk/FindDotNetCliPackage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -51,36 +49,46 @@ private async Task ExecuteAsync()
NormalizeParameters();
await ResolveVersionAsync();

var downloadUrl = GetDownloadUrl();
string downloadUrl = GetDownloadUrl();

Log.LogMessage($"Retrieved dotnet cli {PackageType} version {Version} package uri {downloadUrl}, testing...");

using (var req = new HttpRequestMessage(HttpMethod.Head, downloadUrl))
try
{
var res = await _client.SendAsync(req);
res.EnsureSuccessStatusCode();
}
using var req = new HttpRequestMessage(HttpMethod.Head, downloadUrl);
using HttpResponseMessage res = await _client.SendAsync(req);

Log.LogMessage($"Url {downloadUrl} is valid.");
if (res.StatusCode == HttpStatusCode.NotFound)
{
// 404 means that we successfully hit the server, and it returned 404. This cannot be a network hiccup
Log.LogError(FailureCategory.Build, $"Unable to find dotnet cli {PackageType} version {Version}, tried {downloadUrl}");
}
else
{
res.EnsureSuccessStatusCode();
}
}
catch (Exception ex)
{
Log.LogError(FailureCategory.Build, $"Unable to access dotnet cli {PackageType} version {Version} at {downloadUrl}, {ex.Message}");
}

PackageUri = downloadUrl;
if (!Log.HasLoggedErrors)
{
Log.LogMessage($"Url {downloadUrl} is valid.");
PackageUri = downloadUrl;
}
}

private string GetDownloadUrl()
{
var extension = Runtime.StartsWith("win") ? "zip" : "tar.gz";
if (PackageType == "sdk")
string extension = Runtime.StartsWith("win") ? "zip" : "tar.gz";
return PackageType switch
{
return $"{DotNetCliAzureFeed}/Sdk/{Version}/dotnet-sdk-{Version}-{Runtime}.{extension}";
}
else if (PackageType == "aspnetcore-runtime")
{
return $"{DotNetCliAzureFeed}/aspnetcore/Runtime/{Version}/aspnetcore-runtime-{Version}-{Runtime}.{extension}";
}
else // PackageType == "runtime"
{
return $"{DotNetCliAzureFeed}/Runtime/{Version}/dotnet-runtime-{Version}-{Runtime}.{extension}";
}
"sdk" => $"{DotNetCliAzureFeed}/Sdk/{Version}/dotnet-sdk-{Version}-{Runtime}.{extension}",
"aspnetcore-runtime" => $"{DotNetCliAzureFeed}/aspnetcore/Runtime/{Version}/aspnetcore-runtime-{Version}-{Runtime}.{extension}",
_ => $"{DotNetCliAzureFeed}/Runtime/{Version}/dotnet-runtime-{Version}-{Runtime}.{extension}"
};
}

private void NormalizeParameters()
Expand Down Expand Up @@ -126,23 +134,16 @@ private async Task ResolveVersionAsync()
if (Version == "latest")
{
Log.LogMessage(MessageImportance.Low, "Resolving latest dotnet cli version.");
string latestVersionUrl;
if (PackageType == "sdk")
string latestVersionUrl = PackageType switch
{
latestVersionUrl = $"{DotNetCliAzureFeed}/Sdk/{Channel}/latest.version";
}
else if (PackageType == "aspnetcore-runtime")
{
latestVersionUrl = $"{DotNetCliAzureFeed}/aspnetcore/Runtime/{Channel}/latest.version";
}
else // PackageType == "runtime"
{
latestVersionUrl = $"{DotNetCliAzureFeed}/Runtime/{Channel}/latest.version";
}
"sdk" => $"{DotNetCliAzureFeed}/Sdk/{Channel}/latest.version",
"aspnetcore-runtime" => $"{DotNetCliAzureFeed}/aspnetcore/Runtime/{Channel}/latest.version",
_ => $"{DotNetCliAzureFeed}/Runtime/{Channel}/latest.version"
};

Log.LogMessage(MessageImportance.Low, $"Resolving latest version from url {latestVersionUrl}");
var latestVersionContent = await _client.GetStringAsync(latestVersionUrl);
var versionData = latestVersionContent.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
string latestVersionContent = await _client.GetStringAsync(latestVersionUrl);
string[] versionData = latestVersionContent.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
Version = versionData[1];
Log.LogMessage(MessageImportance.Low, $"Got latest dotnet cli version {Version}");
}
Expand Down