Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[wasm] Fix workload install for tests, with 6.0.0
Move to using the generated nuget.config, which has the feeds added by
darc. The target is a duplicate from
`src/installer/tests/PrepareTestAssets/PrepareTestAssets.proj`, and
should be moved to a common location in future.

Thanks to @lewing for the suggestion.
  • Loading branch information
radical committed Oct 18, 2021
commit 1091ed9f57ca814b4046a860d36d3acf94bf4def
59 changes: 56 additions & 3 deletions src/libraries/workloads-testing.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Project>
<PropertyGroup>
<_NuGetConfigForWorkloadInstall>$(ArtifactsBinDir)workload-nuget.config</_NuGetConfigForWorkloadInstall>
</PropertyGroup>

<Target Name="ProvisionSdkForWorkloadTesting"
DependsOnTargets="_ProvisionSdkWithNoWorkload"
Condition="!Exists($(SdkWithNoWorkloadStampPath)) or !Exists($(SdkWithWorkloadStampPath))">
Expand Down Expand Up @@ -61,7 +65,7 @@

<Target Name="InstallWorkloadUsingArtifacts"
AfterTargets="ArchiveTests"
DependsOnTargets="ProvisionSdkForWorkloadTesting;GetWorkloadInputs;_InstallWorkload;_UpdateManifestsForSdkWithNoWorkload"
DependsOnTargets="GenerateTestRestoreSourcesNuGetConfig_ForWorkloadInstall;ProvisionSdkForWorkloadTesting;GetWorkloadInputs;_InstallWorkload;_UpdateManifestsForSdkWithNoWorkload"
Condition="'$(InstallWorkloadForTesting)' == 'true'" />

<Target Name="_InstallWorkload"
Expand Down Expand Up @@ -100,7 +104,7 @@
<InstallWorkloadFromArtifacts
WorkloadId="@(WorkloadIdForTesting)"
VersionBand="$(SdkBandVersion)"
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
NuGetConfigFile="$(_NuGetConfigForWorkloadInstall)"
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
SdkDir="$(SdkWithWorkloadForTestingPath)" />
<WriteLinesToFile File="$(SdkWithWorkload_WorkloadStampPath)" Lines="" Overwrite="true" />
Expand All @@ -113,11 +117,60 @@
<InstallWorkloadFromArtifacts
WorkloadId="@(WorkloadIdForTesting)"
VersionBand="$(SdkBandVersion)"
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
NuGetConfigFile="$(_NuGetConfigForWorkloadInstall)"
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
SdkDir="$(SdkWithNoWorkloadForTestingPath)"
OnlyUpdateManifests="true"/>

<WriteLinesToFile File="$(SdkWithNoWorkload_WorkloadStampPath)" Lines="" Overwrite="true" />
</Target>

<!-- Copy of the target from src/installer/tests/PrepareTestAssets/PrepareTestAssets.proj -->
<Target Name="GenerateTestRestoreSourcesNuGetConfig_ForWorkloadInstall">
<ItemGroup>
<RestoreTestSource Include="$(ArtifactsShippingPackagesDir)" Key="artifacts-shipping-packages" />
<RestoreTestSource Include="$(ArtifactsNonShippingPackagesDir)" Key="artifacts-nonshipping-packages" />
<RestoreTestSource Include="$(LibrariesShippingPackagesDir)" Condition="Exists('$(LibrariesShippingPackagesDir)')" Key="libraries-shipping-packages" />
<RestoreTestSource Include="$(LibrariesNonShippingPackagesDir)" Condition="Exists('$(LibrariesNonShippingPackagesDir)')" Key="libraries-nonshipping-packages" />
</ItemGroup>

<ItemGroup Condition="'$(LibrariesPackagesDir)' != '$(LibrariesAllConfigPackagesDir)'">
<RestoreTestSource Include="$(LibrariesAllConfigShippingPackagesDir)" Condition="Exists('$(LibrariesAllConfigShippingPackagesDir)')" Key="libraries-allconfig-shipping-packages" />
<RestoreTestSource Include="$(LibrariesAllConfigNonShippingPackagesDir)" Condition="Exists('$(LibrariesAllConfigNonShippingPackagesDir)')" Key="libraries-allconfig-nonshipping-packages" />
</ItemGroup>

<ItemGroup>
<RestoreTestSource Include="$(TestStabilizedLegacyPackagesDir)" Key="stabilized-legacy-packages" />

<RestoreTestSource
Condition="'$(ContinuousIntegrationBuild)' == 'true'"
Include="$(InternalNupkgCacheDir)"
Key="internal-nupkg-cache-packages" />
</ItemGroup>

<PropertyGroup>
<TemplateNuGetConfigFile>$(RepoRoot)NuGet.config</TemplateNuGetConfigFile>

<RestoreTestSourceConfigLines>@(RestoreTestSource -> '&lt;add key="%(Key)" value="%(Identity)" /&gt;', '%0A ')</RestoreTestSourceConfigLines>

<TestRestoreNuGetConfigContent>$([System.IO.File]::ReadAllText('$(TemplateNuGetConfigFile)').Replace(
'&lt;!-- TEST_RESTORE_SOURCES_INSERTION_LINE --&gt;',
'$(RestoreTestSourceConfigLines)'))</TestRestoreNuGetConfigContent>

<!--
Remove Azure DevOps feeds from NuGet.Config because they may require authenticated restore,
which is too flaky to use in test restore. See also
CopyPotentiallyInternalPackagesForTestRestore. https://github.com/dotnet/arcade/issues/3932
-->
<TestRestoreNuGetConfigContent>$([System.Text.RegularExpressions.Regex]::Replace(
'$(TestRestoreNuGetConfigContent)',
'&lt;add key=".+" value="https://pkgs.dev.azure.com/dnceng/internal/.+" /&gt;',
''))</TestRestoreNuGetConfigContent>
</PropertyGroup>

<WriteLinesToFile
File="$(_NuGetConfigForWorkloadInstall)"
Lines="$(TestRestoreNuGetConfigContent)"
Overwrite="true" />
</Target>
</Project>
31 changes: 8 additions & 23 deletions src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class InstallWorkloadFromArtifacts : Task
public string? VersionBand { get; set; }

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

[Required, NotNull]
public string? SdkDir { get; set; }
Expand All @@ -48,6 +48,12 @@ public override bool Execute()
return false;
}

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

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

string nugetConfigContents = GetNuGetConfig();
Expand Down Expand Up @@ -84,28 +90,7 @@ public override bool Execute()
return !Log.HasLoggedErrors;
}

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}"" />");
}

nugetConfigBuilder.AppendLine($"</packageSources>{Environment.NewLine}</configuration>");
return nugetConfigBuilder.ToString();
}
private string GetNuGetConfig() => File.ReadAllText(NuGetConfigFile);

private bool InstallWorkloadManifest(string name, string version, string nugetConfigContents, bool stopOnMissing)
{
Expand Down