Fix issues with single-file and hash generation (#1620)
authorJuan Hoyos <juan.hoyos@microsoft.com>
Wed, 30 Sep 2020 17:45:10 +0000 (10:45 -0700)
committerGitHub <noreply@github.com>
Wed, 30 Sep 2020 17:45:10 +0000 (17:45 +0000)
* Fix SHA512 hashes for blobgroups and wrap pipeline logic in script

* Fix single-file tool signing for 5.0-RC1+ SDKs

* CR feedback

diagnostics.yml
eng/AfterSigning.targets [deleted file]
eng/Publishing.props
eng/build.ps1
eng/ci-prepare-artifacts.cmd [new file with mode: 0644]
eng/cipack.cmd [deleted file]
src/Tools/Directory.Build.targets

index ba82f24423c2a83f27a23f247aaacc2f567ce038..bd2a0bbbf0c5218a15310e9e2d8742cfe7d50e40 100644 (file)
@@ -416,36 +416,9 @@ stages:
               condition: succeeded()
 
             # Create nuget packages, sign binaries and publish to blob feed
-            
-            - script: $(Build.SourcesDirectory)\eng\cipack.cmd
-                -configuration Release
-                -prepareMachine
-                -verbosity normal
-                $(_InternalBuildArgs)
-              displayName: Package
-              continueOnError: true
-              condition: succeeded()
-
-            - script: $(Build.SourcesDirectory)\build.cmd
-                -configuration Release
-                -ci
-                -bundletools
-                -verbosity normal
-                $(_InternalBuildArgs)
-              displayName: Create Single File Bundles
-              continueOnError: true
-              condition: succeeded()
-
-            - powershell: $(Build.SourcesDirectory)\eng\common\build.ps1
-                -configuration Release
-                -prepareMachine
-                -verbosity normal
-                -restore -publish -sign
-                -ci -nobl
-                /bl:$(Build.SourcesDirectory)/artifacts/log/Release/SignPublish.binlog
-                $(_InternalBuildArgs)
-              displayName: Sign and generate manifests
-              continueOnError: true
+            - script: $(Build.SourcesDirectory)\eng\ci-prepare-artifacts.cmd $(_InternalBuildArgs)
+              displayName: Package, Sign, and Publish
+              continueOnError: false
               condition: succeeded()
 
             # Publish package and log build artifacts
diff --git a/eng/AfterSigning.targets b/eng/AfterSigning.targets
deleted file mode 100644 (file)
index 3f3418a..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<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
index 78cd0f625de964b58216387f50acaac74dc2b538..7d0e902f78a85a17cc34ad0e3bb7041f33d6c29c 100644 (file)
@@ -1,4 +1,10 @@
 <Project>
+  <PropertyGroup>
+    <!-- Since Arcade SDK's AfterSigning.proj file does not import the Arcade 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>
 
   <PropertyGroup>
     <BundleOutputDir>$(ArtifactsDir)bundledtools/</BundleOutputDir>
 
   </Target>
 
+  <Target Name="GenerateChecksumsForBlobgroups">
+    <ItemGroup>
+      <GenerateChecksumItems Include="%(PackageFile.Identity)"
+                             Condition="$([System.IO.File]::Exists('%(PackageFile.Identity).blobgroup'))" >
+        <DestinationPath>%(FullPath).sha512</DestinationPath>
+      </GenerateChecksumItems>
+    </ItemGroup>
+
+    <GenerateChecksums Items="@(GenerateChecksumItems)" />
+  </Target>
+
   <!-- Run the CollectPackageArtifactFiles target on each PackageFile 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="CollectPackageArtifactFiles"
+          DependsOnTargets="GenerateChecksumsForBlobgroups"
           Inputs="@(PackageFile)"
           Outputs="%(PackageFile.Identity).notexist">
 
     <PropertyGroup>
       <_BlobGroupFilePath>%(PackageFile.FullPath).blobgroup</_BlobGroupFilePath>
       <_ChecksumFilePath>%(PackageFile.FullPath).sha512</_ChecksumFilePath>
-    </PropertyGroup>    
+    </PropertyGroup>
+
+    <Error Condition="Exists('$(_BlobGroupFilePath)') and !Exists('$(_ChecksumFilePath)')"
+        Text="Expected SHA512 hash for %(PackageFile.FullPath) not found at $(_ChecksumFilePath)"/>
 
     <!-- Read in blob group name, if it exists -->
     <ReadLinesFromFile File="$(_BlobGroupFilePath)" Condition="Exists('$(_BlobGroupFilePath)')">
     </ItemGroup>
 
     <!-- Add artifact items to be pushed to blob feed -->
-    <ItemGroup>      
+    <ItemGroup>
       <ItemsToPushToBlobFeed Include="@(_BlobItem)" Condition="'$(_BlobGroupName)' != ''">
         <RelativeBlobPath>diagnostics/$(_BlobGroupName)/%(_BlobItem.Filename)%(_BlobItem.Extension)</RelativeBlobPath>
         <PublishFlatContainer>true</PublishFlatContainer>
     </ItemGroup>
   </Target>
 
-</Project>
\ No newline at end of file
+  <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
+</Project>
index f1f6cfdd9e3ddb3da599d59ba78791db02c0b2da..722f061bcc4a556d86151989ef5a38d77474ba0e 100644 (file)
@@ -59,7 +59,7 @@ if ($cleanupprivatebuild) {
 
 # Install sdk for building, restore and build managed components.
 if (-not $skipmanaged) {
-    Invoke-Expression "& `"$engroot\common\build.ps1`" -build -binaryLog -configuration $configuration -verbosity $verbosity /p:BuildArch=$architecture /p:TestArchitectures=$architecture $remainingargs"
+    Invoke-Expression "& `"$engroot\common\build.ps1`" -build -configuration $configuration -verbosity $verbosity /p:BuildArch=$architecture /p:TestArchitectures=$architecture $remainingargs"
     if ($lastExitCode -ne 0) {
         exit $lastExitCode
     }
diff --git a/eng/ci-prepare-artifacts.cmd b/eng/ci-prepare-artifacts.cmd
new file mode 100644 (file)
index 0000000..23b321c
--- /dev/null
@@ -0,0 +1,22 @@
+@echo off
+setlocal
+
+set "_commonArgs=-restore -ci -prepareMachine -verbosity minimal -configuration Release"
+set "_logDir=%~dp0..\artifacts\log\Release\"
+
+echo Creating packages
+powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0common\Build.ps1""" %_commonArgs% -pack -noBl /bl:'%_logDir%Pack.binlog' %*"
+if NOT '%ERRORLEVEL%' == '0' goto ExitWithCode
+
+echo Creating bundles
+powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Build.ps1""" %_commonArgs% -bundletools %*"
+if NOT '%ERRORLEVEL%' == '0' goto ExitWithCode
+
+echo Signing and publishing manifest
+powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0common\Build.ps1""" %_commonArgs% -sign -publish -noBl /bl:'%_logDir%SignPublish.binlog' %*"
+if NOT '%ERRORLEVEL%' == '0' goto ExitWithCode
+
+exit /b 0
+
+:ExitWithCode
+exit /b !__exitCode!
diff --git a/eng/cipack.cmd b/eng/cipack.cmd
deleted file mode 100644 (file)
index 9e1babf..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-@echo off
-powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0common\Build.ps1""" -restore -pack -ci %*"
-exit /b %ErrorLevel%
index e5470e05ebea9d5a467a618e986ab30478f0d341..ddd6364b6148bd9a734f1aa53799326a2ff0a4e3 100644 (file)
   This uses the private ItemGroup _FilesToBundle that gets populated in the target chain:
       ComputeFilesToPublish -> GenerateSingleFileBundle -> _ComputeFilesToBundle.
   There was no extensibility point to get this, but the single file team confirmed this
-  would be the cleanest way currently and that it allows to easily consume the extension point when added. -->
+  would be the cleanest way currently and that it allows to easily consume the extension point when added.
+
+  The exclusion is to make sure we don't sign the apphost before bundling the final tool.
+  In pre 5.0-rc1 SDK's we have that the single-file host is named after the app. Afterwards
+  we have it's just called apphost with some metadata. Discard both posibilities. -->
   <Target Name="CollectBundleFilesToSign"
           DependsOnTargets="ComputeFilesToPublish"
           AfterTargets="ComputeFilesToPublish"
           Returns="@(FilesInBundleToSign)">
     <ItemGroup>
-      <FilesInBundleToSign Include="@(_FilesToBundle)" Condition="'%(_FilesToBundle.FileName)%(_FilesToBundle.Extension)' != '$(PublishedSingleFileName)'"/>
+      <FilesInBundleToSign 
+            Include="@(_FilesToBundle)"
+            Condition="('%(_FilesToBundle.FileName)%(_FilesToBundle.Extension)' != '$(PublishedSingleFileName)') and 
+                       ('%(_FilesToBundle.RelativePath)' != '$(PublishedSingleFileName)') "/>
     </ItemGroup>
     <Message Importance="Low" Text="@(FilesInBundleToSign)"/>
   </Target>