Skip to content

Commit 118d8ee

Browse files
author
Nikolay Pianikov
committed
Add smoke testing for template packages and adjust IncludeAssets for Pure.DI dependencies
1 parent 8d04d52 commit 118d8ee

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

build/Core/Targets/TemplateTarget.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public async Task<Package> RunAsync(CancellationToken cancellationToken)
4848
.BuildAsync(cancellationToken: cancellationToken).EnsureSuccess();
4949

5050
var targetPackage = Path.Combine(packagesDirectory, $"{ProjectName}.{packageVersion}.nupkg");
51+
await SmokeTestTemplatePackageAsync(targetPackage, cancellationToken);
52+
5153
artifactsWriter.PublishArtifact($"{targetPackage} => .");
5254

5355
if (string.IsNullOrWhiteSpace(settings.NuGetKey))
@@ -70,6 +72,68 @@ public async Task<Package> RunAsync(CancellationToken cancellationToken)
7072
}
7173
}
7274

75+
private async Task SmokeTestTemplatePackageAsync(string packagePath, CancellationToken cancellationToken)
76+
{
77+
Summary("Smoke testing template package ", packagePath.WithColor(Color.Details));
78+
79+
var tempDirectory = env.GetPath(PathType.TempDirectory);
80+
var hiveDirectory = Path.Combine(tempDirectory, "hive");
81+
var outputDirectory = Path.Combine(tempDirectory, "out");
82+
var consoleAppDirectory = Path.Combine(outputDirectory, "SmokeConsole");
83+
var classLibraryDirectory = Path.Combine(outputDirectory, "SmokeLib");
84+
85+
try
86+
{
87+
Directory.CreateDirectory(hiveDirectory);
88+
Directory.CreateDirectory(outputDirectory);
89+
90+
await new DotNetNewInstall()
91+
.WithPackage(Path.GetFullPath(packagePath))
92+
.AddArgs("--debug:custom-hive", hiveDirectory)
93+
.WithShortName("installing the template package into a custom hive")
94+
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();
95+
96+
await CreateAndBuildTemplateProjectAsync("di", "SmokeConsole", consoleAppDirectory, hiveDirectory, cancellationToken);
97+
await CreateAndBuildTemplateProjectAsync("dilib", "SmokeLib", classLibraryDirectory, hiveDirectory, cancellationToken);
98+
}
99+
finally
100+
{
101+
if (Directory.Exists(tempDirectory))
102+
{
103+
Directory.Delete(tempDirectory, true);
104+
}
105+
}
106+
}
107+
108+
private static async Task CreateAndBuildTemplateProjectAsync(
109+
string templateName,
110+
string projectName,
111+
string outputDirectory,
112+
string hiveDirectory,
113+
CancellationToken cancellationToken)
114+
{
115+
await new DotNetNew()
116+
.WithTemplateName(templateName)
117+
.WithName(projectName)
118+
.WithOutput(outputDirectory)
119+
.WithForce(true)
120+
.AddArgs("--debug:custom-hive", hiveDirectory)
121+
.WithShortName($"creating a project from the {templateName} template")
122+
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();
123+
124+
var guidelinesPath = Path.Combine(outputDirectory, ".junie", "guidelines.md");
125+
if (File.Exists(guidelinesPath))
126+
{
127+
Error($"The generated project contains unexpected file: {guidelinesPath}");
128+
throw new InvalidOperationException($"The generated project contains unexpected file: {guidelinesPath}");
129+
}
130+
131+
await new DotNetBuild()
132+
.WithProject(Path.Combine(outputDirectory, $"{projectName}.csproj"))
133+
.WithShortName($"building the project from the {templateName} template")
134+
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();
135+
}
136+
73137
private static async Task UpdateJsonFileWithVersion(
74138
IEnumerable<string> jsonFiles,
75139
string targetStr,

src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/_PureDIProjectName_.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Pure.DI" Version="[$(PureDIVersion), 2.4.0)">
1313
<PrivateAssets>all</PrivateAssets>
14-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
1616
<Compile Update="$(CompositionName).cs">
1717
<Pack>true</Pack>

src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/_PureDIProjectName_.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Pure.DI" Version="[$(PureDIVersion), 2.4.0)">
1313
<PrivateAssets>all</PrivateAssets>
14-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
1616
</ItemGroup>
1717

0 commit comments

Comments
 (0)