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

Latest version reports it is old (Target: main) #4206

Closed
wants to merge 21 commits into from
7 changes: 4 additions & 3 deletions publish-scripts/chocolatey/installps_template
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ $packageArgs = @{
Install-ChocolateyZipPackage @packageArgs

# only symlink for func.exe
$files = Get-ChildItem $toolsDir -include *.exe -recurse
$files = Get-ChildItem $toolsDir -filter *.exe -Recurse -File
VineethReyya marked this conversation as resolved.
Show resolved Hide resolved
foreach ($file in $files) {
if (!$file.Name.Equals("func.exe")) {
if (!$file.Name.Equals("func.exe") -or (!($file.DirectoryName -eq $toolsDir) -and $file.Name.Equals("func.exe"))) {
#generate an ignore file
New-Item "$file.ignore" -type file -force | Out-Null
$ignoreFilePath = Join-Path -Path $file.DirectoryName -ChildPath "$($file.Name).ignore"
New-Item -Path $ignoreFilePath -Type File -Force | Out-Null
}
}

Expand Down
40 changes: 32 additions & 8 deletions src/Azure.Functions.Cli/Helpers/VersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task<bool> IsRunningAnOlderVersion()
{
var client = new System.Net.Http.HttpClient
{
Timeout = TimeSpan.FromSeconds(1)
Timeout = TimeSpan.FromSeconds(5)
};
var response = await client.GetAsync(Constants.CoreToolsVersionsFeedUrl);
var content = await response.Content.ReadAsStringAsync();
Expand All @@ -53,13 +53,13 @@ public static async Task<bool> IsRunningAnOlderVersion()
{
var jProperty = (Newtonsoft.Json.Linq.JProperty)item;
var releaseDetail = JsonConvert.DeserializeObject<ReleaseDetail>(jProperty.Value.ToString());
releaseList.Add(new ReleaseSummary() { Release = jProperty.Name, ReleaseDetail = releaseDetail.ReleaseList.FirstOrDefault() });
releaseList.Add(new ReleaseSummary(jProperty.Name, releaseDetail.ReleaseList.FirstOrDefault()));
}

var latestCoreToolsReleaseVersion = releaseList.FirstOrDefault(x => x.Release == data.Tags.V4Release.ReleaseVersion)?.CoreToolsReleaseNumber;
var latestCoreToolsAssemblyZipFile = releaseList.FirstOrDefault(x => x.Release == data.Tags.V4Release.ReleaseVersion)?.CoreToolsAssemblyZipFile;

if (!string.IsNullOrEmpty(latestCoreToolsReleaseVersion) &&
Constants.CliVersion != latestCoreToolsReleaseVersion)
if (!string.IsNullOrEmpty(latestCoreToolsAssemblyZipFile) &&
VineethReyya marked this conversation as resolved.
Show resolved Hide resolved
!latestCoreToolsAssemblyZipFile.Contains($"{Constants.CliVersion}.zip"))
{
return true;
}
Expand Down Expand Up @@ -159,8 +159,24 @@ private class Release
public bool Hidden { get; set; }
}

private class ReleaseSummary
internal class ReleaseSummary
{
private readonly string _CoreToolsAssemblyZipFile;
VineethReyya marked this conversation as resolved.
Show resolved Hide resolved
public ReleaseSummary(string release, CoreToolsRelease releaseDetail)
{
Release = release;
ReleaseDetail = releaseDetail;

if (string.IsNullOrEmpty(ReleaseDetail?.DownloadLink))
{
_CoreToolsAssemblyZipFile = string.Empty;
}
else
{
Uri uri = new UriBuilder(ReleaseDetail?.DownloadLink).Uri;
_CoreToolsAssemblyZipFile = uri.Segments.FirstOrDefault(segment => segment.EndsWith(".zip", StringComparison.OrdinalIgnoreCase));
}
}
public string Release { get; set; }

public string CoreToolsReleaseNumber
Expand All @@ -184,15 +200,23 @@ public string CoreToolsReleaseNumber
}
}
public CoreToolsRelease ReleaseDetail { get; set; }
public string CoreToolsAssemblyZipFile
{
get
{
return _CoreToolsAssemblyZipFile;
}
}

}

private class ReleaseDetail
internal class ReleaseDetail
{
[JsonProperty("coreTools")]
public IList<CoreToolsRelease> ReleaseList { get; set; }
}

private class CoreToolsRelease
internal class CoreToolsRelease
{
[JsonProperty("OS")]
public string Os { get; set; }
Expand Down
27 changes: 26 additions & 1 deletion test/Azure.Functions.Cli.Tests/E2E/VersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Threading.Tasks;
using Azure.Functions.Cli.Common;
using Azure.Functions.Cli.Tests.E2E.Helpers;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
using static Azure.Functions.Cli.Helpers.VersionHelper;

namespace Azure.Functions.Cli.Tests.E2E
{
Expand All @@ -24,5 +26,28 @@ await CliTester.Run(new RunConfiguration
CommandTimeout = TimeSpan.FromSeconds(30)
}, _output);
}

[Fact]
public void CoreToolsAssemblyZipFile_ShouldParseCorrectSegment_WhenValidDownloadLinkIsProvided()
{
var fakeDownloadLink = "https://example.com/public/coretoolnumber/V4/assemblyfile.zip";
var releaseDetail = new CoreToolsRelease { DownloadLink = fakeDownloadLink };
var releaseSummary = new ReleaseSummary ("V4",releaseDetail);

var result = releaseSummary.CoreToolsAssemblyZipFile;

result.Should().Be("assemblyfile.zip"); // We expect the segment "assemblyfile.zip" based on the provided URL
}

[Fact]
public void CoreToolsAssemblyZipFile_ShouldReturnEmpty_WhenDownloadLinkIsNull()
{
var releaseDetail = new CoreToolsRelease { DownloadLink = null };
var releaseSummary = new ReleaseSummary("V4", releaseDetail);

var result = releaseSummary.CoreToolsAssemblyZipFile;

result.Should().Be(string.Empty); // The result should be empty when there is no link
}
}
}
}
Loading