Skip to content

Commit cf93626

Browse files
authored
Assert each build produces packages (#910)
Detects new packages after each repo and prints a hopefully useful error if none were produced. As a side benefit, stop printing the entire package version props file before every single repo: instead, print the list of package identities each build produced.
1 parent 3520f7f commit cf93626

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

repos/dir.targets

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,26 @@
166166

167167
<Target Name="CreateBuildOutputProps"
168168
BeforeTargets="Build">
169+
<PropertyGroup>
170+
<_PackageVersionPropsBackupPath>$(PackageVersionPropsPath).pre.$(RepositoryName).xml</_PackageVersionPropsBackupPath>
171+
</PropertyGroup>
172+
169173
<ItemGroup>
170-
<_PreviouslySourceBuiltPackages Include="$(SourceBuiltPackagesPath)*.nupkg"
174+
<PreviouslySourceBuiltPackages Include="$(SourceBuiltPackagesPath)*.nupkg"
171175
Exclude="$(SourceBuiltPackagesPath)*.symbols.nupkg" />
172176
</ItemGroup>
173-
<WriteBuildOutputProps NuGetPackages="@(_PreviouslySourceBuiltPackages)"
177+
178+
<WriteBuildOutputProps NuGetPackages="@(PreviouslySourceBuiltPackages)"
174179
ExtraPackageInfo="@(ExtraPackageVersionPropsPackageInfo)"
175180
OutputPath="$(PackageVersionPropsPath)" />
176181

177-
<WriteBuildOutputProps NuGetPackages="@(_PreviouslySourceBuiltPackages)"
182+
<WriteBuildOutputProps NuGetPackages="@(PreviouslySourceBuiltPackages)"
178183
IncludeCreationTimeProperty="true"
179-
OutputPath="$(PackageVersionPropsPath).pre.$(RepositoryName).xml" />
180-
181-
<ReadLinesFromFile File="$(PackageVersionPropsPath)">
182-
<Output TaskParameter="Lines" ItemName="VersionProperties" />
183-
</ReadLinesFromFile>
184+
OutputPath="$(_PackageVersionPropsBackupPath)" />
184185

185-
<Message Importance="High" Text="$(RepositoryName) is using versions $(PackageVersionPropsPath)" />
186-
<Message Importance="High" Text="%(VersionProperties.Identity)" />
186+
<Message Importance="High" Text="$(RepositoryName) using package version properties saved at $(_PackageVersionPropsBackupPath) " />
187187

188-
<ReadNuGetPackageInfos PackagePaths="@(_PreviouslySourceBuiltPackages)">
188+
<ReadNuGetPackageInfos PackagePaths="@(PreviouslySourceBuiltPackages)">
189189
<Output TaskParameter="PackageInfoItems" ItemName="_PreviouslySourceBuiltPackageInfos" />
190190
</ReadNuGetPackageInfos>
191191

@@ -322,6 +322,34 @@
322322
OverwriteDestination="true" />
323323
</Target>
324324

325+
<Target Name="EnsurePackagesCreated"
326+
AfterTargets="CopyPackage"
327+
Condition="'$(SkipEnsurePackagesCreated)' != 'true'">
328+
<ItemGroup>
329+
<JustSourceBuiltPackages
330+
Include="$(SourceBuiltPackagesPath)*.nupkg"
331+
Exclude="
332+
$(SourceBuiltPackagesPath)*.symbols.nupkg;
333+
@(PreviouslySourceBuiltPackages)" />
334+
</ItemGroup>
335+
336+
<ItemGroup>
337+
<_PackagesNotCreatedReason Include="^ There may have been a silent failure in the submodule build. To confirm, check the build log file for undetected errors that may have prevented package creation: $(RepoConsoleLogFile)" />
338+
<_PackagesNotCreatedReason Include="^ This error might be a false positive if $(RepositoryName) intentionally builds no nuget packages. If so, set the SkipEnsurePackagesCreated property to true in $(MSBuildProjectFullPath)" />
339+
<_PackagesNotCreatedReason Include="^ The 'bin' directory might be dirty from a previous build and the package files already existed. If so, perform a clean build, or check which packages were already in 'bin' by opening $(_PackageVersionPropsBackupPath)" />
340+
</ItemGroup>
341+
342+
<Error Condition="'@(JustSourceBuiltPackages)' == ''"
343+
Text="$(RepositoryName) produced no new source-built package identities. Known possible causes:%0A@(_PackagesNotCreatedReason, '%0A')" />
344+
345+
<ReadNuGetPackageInfos PackagePaths="@(JustSourceBuiltPackages)">
346+
<Output TaskParameter="PackageInfoItems" ItemName="_JustSourceBuiltPackageInfos" />
347+
</ReadNuGetPackageInfos>
348+
349+
<Message Importance="High" Text="New NuGet package(s) after building $(RepositoryName):" />
350+
<Message Importance="High" Text=" -> %(_JustSourceBuiltPackageInfos.PackageId) %(_JustSourceBuiltPackageInfos.PackageVersion)" />
351+
</Target>
352+
325353
<Target Name="Clean" Condition="'$(CleanCommand)' != ''" >
326354
<Exec Command="$(CleanCommand) $(RedirectRepoOutputToLog)"
327355
WorkingDirectory="$(ProjectDirectory)"

repos/known-good.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<RepoApiImplemented>false</RepoApiImplemented>
66
<OrchestratedManifestBuildName>N/A</OrchestratedManifestBuildName>
7+
<SkipEnsurePackagesCreated>true</SkipEnsurePackagesCreated>
78
</PropertyGroup>
89

910
<!-- This project file serves a couple of purpose.

0 commit comments

Comments
 (0)