Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class FetchOrchestratedBuildManifestInfo : Task

[Output]
public ITaskItem[] OrchestratedBlobFeedArtifacts { get; set; }

[Output]
public ITaskItem[] OrchestratedBuilds { get; set; }

public override bool Execute()
{
Expand All @@ -58,6 +61,9 @@ public override bool Execute()
VersionsRepoPath)
.Result;

OrchestratedBuildId = manifest.Identity.BuildId;
OrchestratedIdentity = manifest.Identity.ToString();

EndpointModel[] orchestratedFeeds = manifest.Endpoints
.Where(e => e.IsOrchestratedBlobFeed)
.ToArray();
Expand All @@ -74,10 +80,12 @@ public override bool Execute()
IEnumerable<ITaskItem> packageItems = feed.Artifacts.Packages.Select(CreateItem);
IEnumerable<ITaskItem> blobItems = feed.Artifacts.Blobs.Select(CreateItem);

OrchestratedBuildId = manifest.Identity.BuildId;
OrchestratedIdentity = manifest.Identity.ToString();
OrchestratedBlobFeed = new[] { new TaskItem("Endpoint", feed.Attributes) };
OrchestratedBlobFeedArtifacts = packageItems.Concat(blobItems).ToArray();

IEnumerable<ITaskItem> buildItems = manifest.Builds.Select(CreateItem);

OrchestratedBuilds = buildItems.ToArray();
}

return !Log.HasLoggedErrors;
Expand All @@ -93,6 +101,13 @@ private ITaskItem CreateItem(PackageArtifactModel model)
return new TaskItem("Package", ArtifactMetadata(model.ToXml(), model.Attributes));
}

private ITaskItem CreateItem(BuildIdentity model)
{
return new TaskItem(
model.Name,
ArtifactMetadata(model.ToXmlBuildElement(), model.Attributes));
}

private Dictionary<string, string> ArtifactMetadata(
XElement artifactXml,
IDictionary<string, string> attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ public override bool Execute()
ManifestCommit = null;
}

var orchestratedBuild = new OrchestratedBuildModel(new BuildIdentity(
ManifestName,
ManifestBuildId,
ManifestBranch,
ManifestCommit))
var identity = new BuildIdentity
{
Name = ManifestName,
BuildId = ManifestBuildId,
Branch = ManifestBranch,
Commit = ManifestCommit
};

var orchestratedBuild = new OrchestratedBuildModel(identity)
{
Endpoints = new List<EndpointModel>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
ManifestBuildId="$(ManifestBuildId)"
ManifestBranch="$(ManifestBranch)"
ManifestCommit="$(ManifestCommit)"
ManifestBuildData="$(ManifestBuildData)"
SkipCreateManifest="$(SkipCreateManifest)" />
</Target>

Expand Down Expand Up @@ -115,6 +116,7 @@
ManifestBuildId="$(ManifestBuildId)"
ManifestBranch="$(ManifestBranch)"
ManifestCommit="$(ManifestCommit)"
ManifestBuildData="$(ManifestBuildData)"
SkipCreateManifest="$(SkipCreateManifest)" />

</Target>
Expand Down Expand Up @@ -230,6 +232,10 @@
%(Identity): 'Package' or 'Blob', matching manifest element name.
%(Xml): The raw XML string representing the artifact in the manifest.
%(...): Metadata is created for each attribute on the element.
@(OrchestratedBuilds): An item for each Build in the orchestrated build manifest.
%(Identity): The name of the build.
%(Xml): The raw XML string representing the artifact in the manifest.
%(...): Metadata is created for each attribute on the element.
-->
<Target Name="FetchOrchestratedBuildManifestInfo"
DependsOnTargets="CreateVersionsRepoDefaults">
Expand All @@ -251,6 +257,7 @@
<Output TaskParameter="OrchestratedIdentity" PropertyName="OrchestratedIdentity" />
<Output TaskParameter="OrchestratedBlobFeed" ItemName="OrchestratedBlobFeed" />
<Output TaskParameter="OrchestratedBlobFeedArtifacts" ItemName="OrchestratedBlobFeedArtifacts" />
<Output TaskParameter="OrchestratedBuilds" ItemName="OrchestratedBuilds" />
</FetchOrchestratedBuildManifestInfo>

<PropertyGroup>
Expand Down
30 changes: 20 additions & 10 deletions src/Microsoft.DotNet.Build.Tasks.Feed/PushToBlobFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class PushToBlobFeed : MSBuild.Task
public string ManifestBuildId { get; set; } = "no build id provided";
public string ManifestBranch { get; set; }
public string ManifestCommit { get; set; }
public string ManifestBuildData { get; set; }

/// <summary>
/// When publishing build outputs to an orchestrated blob feed, do not change this property.
Expand Down Expand Up @@ -158,11 +159,14 @@ private async Task PushBuildManifestAsync(
else
{
buildModel = new BuildModel(
new BuildIdentity(
ManifestName,
ManifestBuildId,
ManifestBranch,
ManifestCommit));
new BuildIdentity
{
Attributes = ParseManifestMetadataString(ManifestBuildData),
Name = ManifestName,
BuildId = ManifestBuildId,
Branch = ManifestBranch,
Commit = ManifestCommit
});
}

buildModel.Artifacts.Blobs.AddRange(blobArtifacts);
Expand Down Expand Up @@ -257,9 +261,17 @@ private static BlobArtifactModel CreateBlobArtifactModel(ITaskItem item)

private static Dictionary<string, string> ParseCustomAttributes(ITaskItem item)
{
Dictionary<string, string> customAttributes = item
.GetMetadata("ManifestArtifactData")
?.Split(ManifestDataPairSeparators, StringSplitOptions.RemoveEmptyEntries)
return ParseManifestMetadataString(item.GetMetadata("ManifestArtifactData"));
}

private static Dictionary<string, string> ParseManifestMetadataString(string data)
{
if (string.IsNullOrEmpty(data))
{
return new Dictionary<string, string>();
}

return data.Split(ManifestDataPairSeparators, StringSplitOptions.RemoveEmptyEntries)
.Select(pair =>
{
int keyValueSeparatorIndex = pair.IndexOf('=');
Expand All @@ -275,8 +287,6 @@ private static Dictionary<string, string> ParseCustomAttributes(ITaskItem item)
})
.Where(pair => pair != null)
.ToDictionary(pair => pair.Key, pair => pair.Value);

return customAttributes ?? new Dictionary<string, string>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task TestPushNewBuildAsync()
var mockGitHub = new Mock<IGitHubClient>(MockBehavior.Strict);

var client = new BuildManifestClient(mockGitHub.Object);
var build = new OrchestratedBuildModel(new BuildIdentity("orch", "123"));
var build = new OrchestratedBuildModel(new BuildIdentity { Name = "orch", BuildId = "123"});
var proj = new GitHubProject("versions", "dotnet");
string @ref = "heads/master";
string basePath = "build-info/dotnet/product/cli/master";
Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task TestPushChangeSemaphoreAsync()
string message = "Test change manifest commit";
string addSemaphorePath = "add-identity.semaphore";

var fakeExistingBuild = new OrchestratedBuildModel(new BuildIdentity("orch", "123"));
var fakeExistingBuild = new OrchestratedBuildModel(new BuildIdentity { Name = "orch", BuildId = "123"});
string fakeExistingBuildString = fakeExistingBuild.ToXml().ToString();
string fakeCommitHash = "fakeCommitHash";
string fakeTreeHash = "fakeTreeHash";
Expand Down Expand Up @@ -173,8 +173,8 @@ public async Task TestPushConflictingChangeAsync()
string message = "Test change manifest commit";
string addSemaphorePath = "add-identity.semaphore";

var fakeExistingBuild = new OrchestratedBuildModel(new BuildIdentity("orch", "123"));
var fakeNewExistingBuild = new OrchestratedBuildModel(new BuildIdentity("orch", "456"));
var fakeExistingBuild = new OrchestratedBuildModel(new BuildIdentity { Name = "orch", BuildId = "123" });
var fakeNewExistingBuild = new OrchestratedBuildModel(new BuildIdentity { Name = "orch", BuildId = "456" });
string fakeCommitHash = "fakeCommitHash";

mockGitHub
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task TestPushConflictAsync()
var mockGitHub = new Mock<IGitHubClient>(MockBehavior.Strict);

var client = new BuildManifestClient(mockGitHub.Object);
var build = new OrchestratedBuildModel(new BuildIdentity("orch", "123"));
var build = new OrchestratedBuildModel(new BuildIdentity { Name = "orch", BuildId = "123" });
var proj = new GitHubProject("versions", "dotnet");
string @ref = "heads/master";
string basePath = "build-info/dotnet/product/cli/master";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public void TestExampleOrchestratedBuildManifestRoundtrip()
"Model failed to output the parsed XML.");
}

[Fact]
public void TestExampleCustomBuildIdentityRoundtrip()
{
XElement xml = XElement.Parse(
@"<Build Name=""Example"" BuildId=""123"" ProductVersion=""1.0.0-preview"" Branch=""master"" Commit=""abcdef"" BlankExtra="""" Extra=""extra-foo"" />");
var model = BuildModel.Parse(xml);
XElement modelXml = model.ToXml();

Assert.True(
XNode.DeepEquals(xml, modelXml),
"Model failed to output the parsed XML.");
}

[Fact]
public void TestPackageOnlyBuildManifest()
{
Expand All @@ -56,7 +69,7 @@ public void TestPackageOnlyBuildManifest()
[Fact]
public void TestMergeBuildManifests()
{
var orchestratedModel = new OrchestratedBuildModel(new BuildIdentity("Orchestrated", "123"))
var orchestratedModel = new OrchestratedBuildModel(new BuildIdentity { Name = "Orchestrated", BuildId = "123" })
{
Endpoints = new List<EndpointModel>
{
Expand Down Expand Up @@ -87,7 +100,7 @@ public void TestMergeBuildManifests()

private BuildModel CreatePackageOnlyBuildManifestModel()
{
return new BuildModel(new BuildIdentity("SimpleBuildManifest", "123"))
return new BuildModel(new BuildIdentity { Name = "SimpleBuildManifest", BuildId = "123" })
{
Artifacts = new ArtifactSet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.VersionTools.Util;
using System.Collections.Generic;
using System.Xml.Linq;

Expand All @@ -14,24 +15,27 @@ public class BlobArtifactModel
nameof(Id)
};

public Dictionary<string, string> Attributes { get; set; } = new Dictionary<string, string>();
public IDictionary<string, string> Attributes { get; set; } = new Dictionary<string, string>();

public string Id
{
get { return Attributes[nameof(Id)]; }
get { return Attributes.GetOrDefault(nameof(Id)); }
set { Attributes[nameof(Id)] = value; }
}

public override string ToString() => $"Blob {Id}";

public XElement ToXml() => new XElement(
"Blob",
Attributes.CreateXmlAttributes(AttributeOrder));
Attributes
.ThrowIfMissingAttributes(AttributeOrder)
.CreateXmlAttributes(AttributeOrder));

public static BlobArtifactModel Parse(XElement xml) => new BlobArtifactModel
{
Id = xml.GetRequiredAttribute(nameof(Id)),
Attributes = xml.CreateAttributeDictionary()
Attributes = xml
.CreateAttributeDictionary()
.ThrowIfMissingAttributes(AttributeOrder)
};
}
}
Loading