Generate checksums for NuGet packages after building/signing. (#1211)
authorJustin Anderson <jander-msft@users.noreply.github.com>
Sat, 13 Jun 2020 16:31:34 +0000 (09:31 -0700)
committerGitHub <noreply@github.com>
Sat, 13 Jun 2020 16:31:34 +0000 (09:31 -0700)
* Generate checksums for NuGet packages after signing.

* Generate package checksums only after that Pack task.
During publish, collect checksum files and calculate blob path.
Have official build publish checksum files.

* Set PublishFlatContainer to true

* Specify if checksum corresponds to shipping package.

* Fix type

* Only generate checksums for packages that declare a blob group.
Upload checksums to blob storage with blob group in relative blob path.

* Use target batching for CollectPackageChecksumFiles to correctly read blob group files.

diagnostics.yml
eng/AfterSigning.targets [new file with mode: 0644]
eng/Publishing.props [new file with mode: 0644]
src/Directory.Build.targets
src/Tools/dotnet-monitor/dotnet-monitor.csproj

index 151d9c15f963b62403a3ea1eb02fb5e4b97eb859..3318e798e0b2af4abd701a0bd2fde57fbce17359 100644 (file)
@@ -454,6 +454,7 @@ stages:
         # The variables get imported from group dotnet-diagnostics-sdl-params
         enableSourceLinkValidation: true
         symbolPublishingAdditionalParameters: '/p:PublishSpecialClrFiles=false'
+        publishInstallersAndChecksums: true
         SDLValidationParameters:
           enable: true
           continueOnError: false
diff --git a/eng/AfterSigning.targets b/eng/AfterSigning.targets
new file mode 100644 (file)
index 0000000..3f3418a
--- /dev/null
@@ -0,0 +1,26 @@
+<Project>
+
+  <PropertyGroup>
+    <!-- Since Arcade SDK's AfterSigning.proj file does not import the Arcard SDK, this
+         setting is necessary because we are manually importing the Arcade SDK targets
+         below in order to get the GenerateChecksums target. -->
+    <_SuppressSdkImports>false</_SuppressSdkImports>
+  </PropertyGroup>
+
+  <Target Name="CollectGenerateChecksumItems">
+    <ItemGroup>
+      <NuGetPackageFile Include="$(ArtifactsPackagesDir)**\*.nupkg" />
+      <GenerateChecksumItems Include="%(NuGetPackageFile.Identity)"
+                             Condition="$([System.IO.File]::Exists('%(NugetPackageFile.Identity).blobgroup'))" >
+        <DestinationPath>%(FullPath).sha512</DestinationPath>
+      </GenerateChecksumItems>
+    </ItemGroup>
+  </Target>
+
+  <Target Name="GenerateSignedPackageChecksums"
+          AfterTargets="Pack"
+          DependsOnTargets="CollectGenerateChecksumItems;GenerateChecksums" />
+
+  <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
+
+</Project>
\ No newline at end of file
diff --git a/eng/Publishing.props b/eng/Publishing.props
new file mode 100644 (file)
index 0000000..19340be
--- /dev/null
@@ -0,0 +1,38 @@
+<Project>
+
+  <PropertyGroup>
+    <PublishDependsOnTargets>$(PublishDependsOnTargets);CollectPackageChecksumFiles</PublishDependsOnTargets>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageChecksumFile Include="$(ArtifactsShippingPackagesDir)**\*.sha512" IsShipping="true" />
+    <PackageChecksumFile Include="$(ArtifactsNonShippingPackagesDir)**\*.sha512" IsShipping="false" />
+  </ItemGroup>
+
+  <!-- Run the CollectPackageChecksumFiles target on each PackageChecksunFile by target batching on a non-existing file.
+       This allows using the ReadLinesFromFile task to read the blob group file, which was written with WriteLinesToFile,
+       thus avoiding erroneously reading in the newline at the end of the blob group file. -->
+  <Target Name="CollectPackageChecksumFiles"
+          Inputs="@(PackageChecksumFile)"
+          Outputs="%(PackageChecksumFile.Identity).notexist">
+    <!-- Find the blob group file next to the checksum file. -->
+    <PropertyGroup>
+      <_BlobGroupFilePath>%(PackageChecksumFile.RootDir)%(PackageChecksumFile.Directory)%(PackageChecksumFile.Filename).blobgroup</_BlobGroupFilePath>
+    </PropertyGroup>
+    <Error Message="Blob group file '$(_BlobGroupFilePath)' does not exist."
+           Condition="!Exists('$(_BlobGroupFilePath)')" />
+    <!-- Read in blob group name -->
+    <ReadLinesFromFile File="$(_BlobGroupFilePath)">
+      <Output TaskParameter="Lines" PropertyName="_BlobGroupName"/>
+    </ReadLinesFromFile>
+    <!-- Add ItemsToPushToBlobFeed for checksum file using blob group in relative blob path. -->
+    <ItemGroup>
+      <ItemsToPushToBlobFeed Include="%(PackageChecksumFile.Identity)">
+        <RelativeBlobPath>diagnostics/$(_BlobGroupName)/%(PackageChecksumFile.Filename)%(PackageChecksumFile.Extension)</RelativeBlobPath>
+        <ManifestArtifactData Condition="'%(PackageChecksumFile.IsShipping)' != 'true'">NonShipping=true</ManifestArtifactData>
+        <PublishFlatContainer>true</PublishFlatContainer>
+      </ItemsToPushToBlobFeed>
+    </ItemGroup>
+  </Target>
+
+</Project>
\ No newline at end of file
index 44e9119b8ed43bdfe52fdbdc17117c0d588ee759..0332f57305cf061d3cfb91bc4721e0cd92813c7c 100644 (file)
           AfterTargets="PostBuildEvent"
           Condition="$(NeedsPublishing) == 'true'"
           DependsOnTargets="$(_BeforePublishNoBuildTargets);$(_CorePublishTargets)" />
+
+  <!-- Creates a file for packaged projects that declare a blog group prefix so that
+      publishing can use it in the blob path calculation. -->
+  <Target Name="GenerateBlobGroupFile"
+          AfterTargets="Pack"
+          Condition="'$(IsPackable)' == 'true' and '$(BlobGroupPrefix)' != ''">
+    <PropertyGroup>
+      <_BlobGroupVersionMajor>$(PackageVersion.Split('.')[0])</_BlobGroupVersionMajor>
+      <_BlobGroupVersionMinor>$(PackageVersion.Split('.')[1])</_BlobGroupVersionMinor>
+      <_BlobGroupName>$(BlobGroupPrefix)$(_BlobGroupVersionMajor).$(_BlobGroupVersionMinor)</_BlobGroupName>
+    </PropertyGroup>
+    <WriteLinesToFile File="$(PackageOutputPath)\$(PackageId).$(PackageVersion).nupkg.blobgroup"
+                      Lines="$(_BlobGroupName)"
+                      Overwrite="true" />
+  </Target>
 </Project>
index c60b5d81e4b49163854766261f50bc0601817fd9..158b068252a074c930dcdf738eb34c758119ec1b 100644 (file)
@@ -10,6 +10,9 @@
     <PackageTags>Diagnostic</PackageTags>
     <IsShipping>false</IsShipping>
     <PackageReleaseNotes>$(Description)</PackageReleaseNotes>
+    <!-- This forces the creation of a checksum file and uploads it to blob storage
+         using this name as part of the blob relative path. -->
+    <BlobGroupPrefix>monitor</BlobGroupPrefix>
   </PropertyGroup>
 
   <ItemGroup>