Skip to content

Commit

Permalink
InstallWorkload: Use the repo's nuget.config as the base for instal…
Browse files Browse the repository at this point in the history
…ling manifests (#60699)
  • Loading branch information
radical authored Nov 9, 2021
1 parent 603aedf commit 3076586
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
7 changes: 2 additions & 5 deletions eng/testing/workloads-testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@
WorkingDirectory="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App" />

<ItemGroup>
<_NuGetSourceForWorkloads Include="dotnet6" Value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<_NuGetSourceForWorkloads Include="dotnet7" Value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />

<_BuiltNuGets Include="$(LibrariesShippingPackagesDir)\*.nupkg" />
</ItemGroup>

Expand All @@ -111,7 +108,7 @@
WorkloadId="@(WorkloadIdForTesting)"
VersionBand="$(SdkBandVersion)"
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
SdkDir="$(SdkWithWorkloadForTestingPath)" />
<WriteLinesToFile File="$(SdkWithWorkload_WorkloadStampPath)" Lines="" Overwrite="true" />
</Target>
Expand All @@ -124,7 +121,7 @@
WorkloadId="@(WorkloadIdForTesting)"
VersionBand="$(SdkBandVersion)"
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
SdkDir="$(SdkWithNoWorkloadForTestingPath)"
OnlyUpdateManifests="true"/>

Expand Down
46 changes: 27 additions & 19 deletions src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,30 @@ public class InstallWorkloadFromArtifacts : Task
[Required, NotNull]
public string? LocalNuGetsPath { get; set; }

[Required, NotNull]
public string? TemplateNuGetConfigPath { get; set; }

[Required, NotNull]
public string? SdkDir { get; set; }

public bool OnlyUpdateManifests{ get; set; }

public ITaskItem[] ExtraNuGetSources { get; set; } = Array.Empty<ITaskItem>();
private const string s_nugetInsertionTag = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->";

public override bool Execute()
{
try
{
return ExecuteInternal();
}
catch (LogAsErrorException laee)
{
Log.LogError(laee.Message);
return false;
}
}

private bool ExecuteInternal()
{
if (!HasMetadata(WorkloadId, nameof(WorkloadId), "Version") ||
!HasMetadata(WorkloadId, nameof(WorkloadId), "ManifestName"))
Expand All @@ -48,6 +64,12 @@ public override bool Execute()
return false;
}

if (!File.Exists(TemplateNuGetConfigPath))
{
Log.LogError($"Cannot find TemplateNuGetConfigPath={TemplateNuGetConfigPath}");
return false;
}

Log.LogMessage(MessageImportance.High, $"{Environment.NewLine}** Installing workload manifest {WorkloadId.ItemSpec} **{Environment.NewLine}");

string nugetConfigContents = GetNuGetConfig();
Expand Down Expand Up @@ -86,25 +108,11 @@ public override bool Execute()

private string GetNuGetConfig()
{
StringBuilder nugetConfigBuilder = new();
nugetConfigBuilder.AppendLine($"<configuration>{Environment.NewLine}<packageSources>");

nugetConfigBuilder.AppendLine($@"<add key=""nuget-local"" value=""{LocalNuGetsPath}"" />");
foreach (ITaskItem source in ExtraNuGetSources)
{
string key = source.ItemSpec;
string value = source.GetMetadata("Value");
if (string.IsNullOrEmpty(value))
{
Log.LogWarning($"ExtraNuGetSource {key} is missing Value metadata");
continue;
}

nugetConfigBuilder.AppendLine($@"<add key=""{key}"" value=""{value}"" />");
}
string contents = File.ReadAllText(TemplateNuGetConfigPath);
if (contents.IndexOf(s_nugetInsertionTag) < 0)
throw new LogAsErrorException($"Could not find {s_nugetInsertionTag} in {TemplateNuGetConfigPath}");

nugetConfigBuilder.AppendLine($"</packageSources>{Environment.NewLine}</configuration>");
return nugetConfigBuilder.ToString();
return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{LocalNuGetsPath}"" />");
}

private bool InstallWorkloadManifest(string name, string version, string nugetConfigContents, bool stopOnMissing)
Expand Down
1 change: 1 addition & 0 deletions src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\Utils.cs" />
<Compile Include="..\Common\LogAsErrorException.cs" />

<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
</ItemGroup>
Expand Down

0 comments on commit 3076586

Please sign in to comment.