Save dependent dotnet/runtime's commit and version to productCommit-rid.txt

This commit is contained in:
EgorBo 2022-01-27 19:21:52 +03:00
parent 542bf3308b
commit 8fa51f49e8
3 changed files with 73 additions and 1 deletions

View file

@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build
{
/// <summary>
/// Gets version and commit of a dependency by its name
/// from eng/Version.Details.xml
/// </summary>
public class GetDependencyInfo : Task
{
[Required]
public string DotnetInstallerCommit { get; set; }
[Required]
public string DependencyName { get; set; }
[Output]
public string DependencyVersion { get; set; }
[Output]
public string DependencyCommit { get; set; }
public override bool Execute()
{
try
{
using Stream file = new HttpClient().GetStreamAsync(
$"https://raw.githubusercontent.com/dotnet/installer/{DotnetInstallerCommit}/eng/Version.Details.xml")
.Result;
XDocument document = XDocument.Load(file);
XElement dependency = document
.Element("Dependencies")?
.Element("ProductDependencies")?
.Elements("Dependency")
.FirstOrDefault(d => DependencyName.Equals(d.Attribute("Name")?.Value));
if (dependency != null)
{
DependencyVersion = dependency.Attribute("Version")?.Value;
DependencyCommit = dependency.Element("Sha")?.Value;
}
}
catch (Exception ex)
{
Log.LogWarning($"GetComponentCommit failed for DotnetInstallerCommit={DotnetInstallerCommit}, DependencyName={DependencyName}: {ex}");
}
return true;
}
}
}

View file

@ -39,5 +39,6 @@
<UsingTask TaskName="GetLinuxNativeInstallerDependencyVersions" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="CollatePackageDownloads" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="GenerateSdkRuntimeIdentifierChain" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="GetDependencyInfo" AssemblyFile="$(CoreSdkTaskDll)"/>
</Project>

View file

@ -16,9 +16,20 @@
Overwrite="true"
Encoding="ASCII" />
<GetDependencyInfo
DotnetInstallerCommit="$(BUILD_SOURCEVERSION)"
DependencyName="Microsoft.NETCore.App.Ref">
<Output TaskParameter="DependencyVersion" PropertyName="DepRuntimeVersion" />
<Output TaskParameter="DependencyCommit" PropertyName="DepRuntimeCommit" />
</GetDependencyInfo>
<!-- Format for productCommit-%rid%.txt:
installer:%commit%, %version
runtime:%commit%, $version
-->
<WriteLinesToFile
File="$(ArtifactsShippingPackagesDir)productCommit-$(Rid).txt"
Lines="$(BUILD_SOURCEVERSION)%0A$(PackageVersion)"
Lines="installer%3A$(BUILD_SOURCEVERSION)%2C%20$(PackageVersion)%0Aruntime%3A$(DepRuntimeCommit)%2C%20$(DepRuntimeVersion)%0A"
Overwrite="true"
Encoding="ASCII"/>