From 3cb3c0fde2db5bf9c45290a866ee0f636c2a05a6 Mon Sep 17 00:00:00 2001 From: Jevan Saks Date: Tue, 18 Dec 2018 11:27:32 -0800 Subject: [PATCH] Add nuget package test solution to the PR/CI build (#87) Also factor out repetitive yml into a template. This adds jobs to the PR and CI builds that take the just-built nuget package and then build the MUXReleaseTest solution with that new nuget package. --- .../MUX-BuildProject-Steps.yml | 43 +++++++ .../MUX-CreateNugetPackage-Job.yml | 56 ++++++++++ .../MUX-InstallNuget-Steps.yml | 8 ++ .../MUX-NugetReleaseTest-Job.yml | 91 +++++++++++++++ build/MUX-CI.yml | 105 ++++++------------ build/MUX-NugetReleaseTest.yml | 4 + build/MUX-PR.yml | 62 +++++++---- .../NugetPackageTestApp.csproj | 5 +- .../NugetPackageTestAppCX.vcxproj | 4 +- .../NugetPackageTestAppCX/packages.config | 2 +- tools/PostBuild.cmd | 2 +- 11 files changed, 285 insertions(+), 97 deletions(-) create mode 100644 build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml create mode 100644 build/AzurePipelinesTemplates/MUX-CreateNugetPackage-Job.yml create mode 100644 build/AzurePipelinesTemplates/MUX-InstallNuget-Steps.yml create mode 100644 build/AzurePipelinesTemplates/MUX-NugetReleaseTest-Job.yml create mode 100644 build/MUX-NugetReleaseTest.yml diff --git a/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml b/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml new file mode 100644 index 0000000..39cd9d0 --- /dev/null +++ b/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml @@ -0,0 +1,43 @@ +parameters: + solutionPath: '' + nugetConfigPath: '' + buildOutputDir: '$(Build.SourcesDirectory)\BuildOutput' + appxPackageDir: '$(build.artifactStagingDirectory)\$(buildConfiguration)\$(buildPlatform)\AppxPackages' + +steps: + - script: | + echo parameters.solutionPath = '${{ parameters.solutionPath }}' + echo parameters.nugetConfigPath = '${{ parameters.nugetConfigPath }}' + echo parameters.appxPackageDir = '${{ parameters.appxPackageDir }}' + echo parameters.buildOutputDir = '${{ parameters.buildOutputDir }}' + displayName: 'BuildProject: Display parameters' + + - task: CmdLine@1 + displayName: 'Display build machine environment variables' + inputs: + filename: 'set' + + - task: powershell@2 + inputs: + targetType: filePath + filePath: build\Install-WindowsSdkISO.ps1 + arguments: 17763 + displayName: 'Install RS5 SDK (17763)' + + - template: MUX-InstallNuget-Steps.yml + + - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2 + displayName: 'NuGet restore ${{ parameters.solutionPath }}' + inputs: + restoreSolution: ${{ parameters.solutionPath }} + feedsToUse: config + nugetConfigPath: ${{ parameters.nugetConfigPath }} + + - task: VSBuild@1 + displayName: 'Build solution ${{ parameters.solutionPath }}' + inputs: + solution: ${{ parameters.solutionPath }} + vsVersion: 15.0 + platform: '$(buildPlatform)' + configuration: '$(buildConfiguration)' + msbuildArgs: '/p:AppxPackageDir="${{ parameters.appxPackageDir }}" /p:AppxBundle=Never /p:AppxSymbolPackageEnabled=false' diff --git a/build/AzurePipelinesTemplates/MUX-CreateNugetPackage-Job.yml b/build/AzurePipelinesTemplates/MUX-CreateNugetPackage-Job.yml new file mode 100644 index 0000000..bf9a5ad --- /dev/null +++ b/build/AzurePipelinesTemplates/MUX-CreateNugetPackage-Job.yml @@ -0,0 +1,56 @@ +parameters: +# Extract the build revision number from Build.BuildNumber. This is needed to pass to build-nupkg + jobName: '' + dependsOn: '' + buildOutputDir: '$(Build.SourcesDirectory)\BuildOutput' + nupkgdir: '$(build.artifactStagingDirectory)' +# The "primary" build arch is the one that the nuspec gets its winmd, pri, and other neutral files from + primaryBuildArch: x86 + buildFlavor: Release + +jobs: +- job: ${{ parameters.jobName }} + dependsOn: + - ${{ parameters.dependsOn }} + + steps: + # Extract the build revision number from Build.BuildNumber. This is needed to pass to build-nupkg + - powershell: | + $revision = $env:BUILD_BUILDNUMBER.substring($env:BUILD_BUILDNUMBER.length - 3, 3) + Write-Host "##vso[task.setvariable variable=buildrevision]$revision" + displayName: 'Get build revision number' + + - script: | + echo parameters.jobName '${{ parameters.jobName }}' + echo parameters.buildOutputDir '${{ parameters.buildOutputDir }}' + echo parameters.nupkgdir '${{ parameters.nupkgdir }}' + echo parameters.publishPath '${{ parameters.publishPath }}' + echo buildrevision=$(buildrevision) + displayName: 'CreateNugetPackage: Display parameters' + + - task: DownloadBuildArtifacts@0 + inputs: + artifactName: drop + downloadPath: '$(Build.SourcesDirectory)\Artifacts' + + - template: MUX-InstallNuget-Steps.yml + + - task: powershell@2 + displayName: 'build-nupkg.ps1' + inputs: + targetType: filePath + filePath: build\NuSpecs\build-nupkg.ps1 + arguments: > + -BuildOutput '$(Build.SourcesDirectory)\Artifacts\drop' + -OutputDir '${{ parameters.nupkgdir }}' + -prereleaseversion prerelease + -Subversion '$(buildrevision)' + -SkipFrameworkPackage + -BuildArch ${{ parameters.primaryBuildArch }} + -BuildFlavor ${{ parameters.buildFlavor }} + + - task: PublishBuildArtifacts@1 + displayName: 'Publish artifact: nupkg' + inputs: + PathtoPublish: '${{ parameters.nupkgdir }}' + artifactName: 'drop' diff --git a/build/AzurePipelinesTemplates/MUX-InstallNuget-Steps.yml b/build/AzurePipelinesTemplates/MUX-InstallNuget-Steps.yml new file mode 100644 index 0000000..c189385 --- /dev/null +++ b/build/AzurePipelinesTemplates/MUX-InstallNuget-Steps.yml @@ -0,0 +1,8 @@ +parameters: + nugetVersion: 4.9.1 + +steps: + - task: NuGetToolInstaller@0 + displayName: 'Use NuGet ${{ parameters.nugetVersion }}' + inputs: + versionSpec: ${{ parameters.nugetVersion }} diff --git a/build/AzurePipelinesTemplates/MUX-NugetReleaseTest-Job.yml b/build/AzurePipelinesTemplates/MUX-NugetReleaseTest-Job.yml new file mode 100644 index 0000000..82fce63 --- /dev/null +++ b/build/AzurePipelinesTemplates/MUX-NugetReleaseTest-Job.yml @@ -0,0 +1,91 @@ +parameters: + dependsOn: '' + useNupkgFromArtifacts: false + nugetConfigPath: test\MUXControlsReleaseTest\nuget.config + matrix: + Debug_x86: + buildPlatform: 'x86' + buildConfiguration: 'Debug' + +jobs: +- job: BuildNugetTests + dependsOn: + - ${{if parameters.dependsOn }}: + - ${{ parameters.dependsOn }} + + pool: + vmImage: 'VS2017-Win2016' + strategy: + maxParallel: 10 + matrix: ${{ parameters.matrix }} + + variables: + solutionDir: test\MUXControlsReleaseTest + solutionPath: test\MUXControlsReleaseTest\MUXControlsReleaseTest.sln + nugetConfigPath: test\MUXControlsReleaseTest\nuget.config + packageSaveDirectory: $(Build.SourcesDirectory)\packages\muxreleasetest + artifactDownloadPath: $(Build.SourcesDirectory)\Artifacts + currentPackageVersion: 2.1.181217001-prerelease + + steps: + # When using the nupkg from artifacts we need to make a new nuget.config that points the MUXReleaseTest + # projects at the just-built nupkg. The MUXRelease projects use a specific nuget version so we need + # to update nuget.config to include the drop location as well as update the version in the csproj and + # packages.config for the projects. + - ${{ if eq(parameters.useNupkgFromArtifacts, 'true') }}: + - task: DownloadBuildArtifacts@0 + inputs: + artifactName: drop + downloadPath: $(artifactDownloadPath) + + # Rewrite the nuget.config to use drop location. + - powershell: | + $nugetConfigFullPath = "$env:BUILD_SOURCESDIRECTORY\$env:nugetConfigPath" + @" + + + + + + + + + + "@ | Out-File -Encoding UTF8 $nugetConfigFullPath + # Output for debugging + Write-Host (Get-Content $nugetConfigFullPath) + displayName: Rewrite nuget.config to use artifacts + + # Rewrite the project files to use the new version + - powershell: | + # First, get the new version + $candidateNupkgs = Get-ChildItem $env:artifactDownloadPath\drop\Microsoft.UI.Xaml.*.nupkg + $newVersion = $candidateNupkgs[0].Name.Replace("Microsoft.UI.Xaml.", "").Replace(".nupkg", "") + + Write-Host "New version: $newVersion" + + $numFilesReplaced = 0 + Get-ChildItem -r $env:solutionDir -File | + ForEach-Object { + $path = $_.FullName + $contents = [System.IO.File]::ReadAllText($path) + $newContents = $contents.Replace("$env:currentPackageVersion", "$newVersion") + if ($contents -ne $newContents) { + Write-Host "Updating version in $path" + $newContents | Set-Content $path -Encoding UTF8 + $numFilesReplaced += 1 + } + } + + if ($numFilesReplaced -eq 0) + { + Write-Host "##vso[task.logissue type=error]No files found with '$env:currentPackageVersion' in them, make sure to update *.yml files when retargeting ReleaseTest projects" + Exit 1 + } + displayName: Rewrite project files to use new version + + - template: MUX-BuildProject-Steps.yml + parameters: + solutionPath: $(solutionPath) + nugetConfigPath: $(nugetConfigPath) + diff --git a/build/MUX-CI.yml b/build/MUX-CI.yml index 02abe98..7a5b13a 100644 --- a/build/MUX-CI.yml +++ b/build/MUX-CI.yml @@ -24,42 +24,21 @@ jobs: buildConfiguration: 'Release' variables: - appxPackageDir: '$(build.artifactStagingDirectory)\$(buildConfiguration)\$(buildPlatform)\AppxPackages' - buildOutputDir: '$(Build.SourcesDirectory)\BuildOutput' + - name: appxPackageDir + value: $(build.artifactStagingDirectory)\$(buildConfiguration)\$(buildPlatform)\AppxPackages + - name: buildOutputDir + value: $(Build.SourcesDirectory)\BuildOutput + - name: publishDir + value: $(Build.ArtifactStagingDirectory) steps: - - task: CmdLine@1 - displayName: 'Display build machine environment variables' - inputs: - filename: 'set' - - - task: powershell@2 - displayName: 'Install RS5 SDK (17763)' - inputs: - targetType: filePath - filePath: build\Install-WindowsSdkISO.ps1 - arguments: 17763 - - - task: NuGetToolInstaller@0 - displayName: 'Use NuGet 4.9.1' - inputs: - versionSpec: 4.9.1 - - - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2 - displayName: 'NuGet restore MUXControls.sln' - inputs: - restoreSolution: MUXControls.sln - feedsToUse: config + - template: AzurePipelinesTemplates\MUX-BuildProject-Steps.yml + parameters: + solutionPath: MUXControls.sln nugetConfigPath: nuget.config - - - task: VSBuild@1 - displayName: 'Build solution MUXControls.sln' - inputs: - solution: MUXControls.sln - vsVersion: 15.0 - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - msbuildArgs: '/p:AppxPackageDir="$(appxPackageDir)" /p:AppxBundle=Never /p:AppxSymbolPackageEnabled=false' + appxPackageDir: $(appxPackageDir) + buildOutputDir: $(buildOutputDir) + publishDir: $(publishDir) - task: powershell@2 displayName: 'Copy files to staging dir' @@ -74,39 +53,27 @@ jobs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' artifactName: 'drop' - -- job: CreateNuGet - dependsOn: - - Build - variables: - nupkgdir: '$(build.artifactStagingDirectory)' - buildOutputDir: '$(Build.SourcesDirectory)\BuildOutput' - steps: - - task: DownloadBuildArtifacts@0 - inputs: - artifactName: drop - downloadPath: '$(buildOutputDir)' - - - task: NuGetToolInstaller@0 - displayName: 'Use NuGet 4.9.1' - inputs: - versionSpec: 4.9.1 - - # Extract the build revision number from Build.BuildNumber. This is needed to pass to build-nupkg - - powershell: | - $revision = $env:BUILD_BUILDNUMBER.substring($env:BUILD_BUILDNUMBER.length - 3, 3) - Write-Host "##vso[task.setvariable variable=buildrevision]$revision" - displayName: 'Get build revision number' - - - task: powershell@2 - displayName: 'build-nupkg.ps1' - inputs: - targetType: filePath - filePath: build\NuSpecs\build-nupkg.ps1 - arguments: -BuildOutput '$(buildOutputDir)\drop' -OutputDir '$(nupkgdir)' -prereleaseversion prerelease -Subversion '$(buildrevision)' -SkipFrameworkPackage - - - task: PublishBuildArtifacts@1 - displayName: 'Publish artifact: nupkg' - inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' - artifactName: 'drop' +# Create Nuget Package +- template: AzurePipelinesTemplates\MUX-CreateNugetPackage-Job.yml + parameters: + jobName: CreateNugetPackage + dependsOn: Build + +# Build solution that depends on nuget package +- template: AzurePipelinesTemplates\MUX-NugetReleaseTest-Job.yml + parameters: + dependsOn: CreateNugetPackage + useNupkgFromArtifacts: true + matrix: + Debug_x86: + buildPlatform: 'x86' + buildConfiguration: 'Debug' + Debug_x64: + buildPlatform: 'x64' + buildConfiguration: 'Debug' + Release_x64: + buildPlatform: 'x64' + buildConfiguration: 'Release' + Release_arm: + buildPlatform: 'arm' + buildConfiguration: 'Release' diff --git a/build/MUX-NugetReleaseTest.yml b/build/MUX-NugetReleaseTest.yml new file mode 100644 index 0000000..2d8a498 --- /dev/null +++ b/build/MUX-NugetReleaseTest.yml @@ -0,0 +1,4 @@ +name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr) + +jobs: +- template: AzurePipelinesTemplates\MUX-NugetReleaseTest-Job.yml diff --git a/build/MUX-PR.yml b/build/MUX-PR.yml index 8d4cdd6..d9c1d29 100644 --- a/build/MUX-PR.yml +++ b/build/MUX-PR.yml @@ -14,30 +14,52 @@ jobs: buildPlatform: 'x64' buildConfiguration: 'Release' + variables: + - name: appxPackageDir + value: $(build.artifactStagingDirectory)\$(buildConfiguration)\$(buildPlatform)\AppxPackages + - name: buildOutputDir + value: $(Build.SourcesDirectory)\BuildOutput + - name: publishDir + value: $(Build.ArtifactStagingDirectory) + steps: + - template: AzurePipelinesTemplates\MUX-BuildProject-Steps.yml + parameters: + solutionPath: MUXControls.sln + nugetConfigPath: nuget.config + appxPackageDir: $(appxPackageDir) + buildOutputDir: $(buildOutputDir) + publishDir: $(publishDir) + - task: powershell@2 + displayName: 'Copy files to staging dir' inputs: targetType: filePath - filePath: build\Install-WindowsSdkISO.ps1 - arguments: 17763 - displayName: 'Install RS5 SDK (17763)' + filePath: build\CopyFilesToStagingDir.ps1 + arguments: -BuildOutputDir '$(buildOutputDir)' -PublishDir '$(publishDir)' -Platform '$(buildPlatform)' -Configuration '$(buildConfiguration)' - - task: NuGetToolInstaller@0 - displayName: 'Use NuGet 4.9.1' + - task: PublishBuildArtifacts@1 + displayName: 'Publish artifact: drop' inputs: - versionSpec: 4.9.1 - - - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2 - displayName: 'NuGet restore MUXControls.sln' - inputs: - restoreSolution: MUXControls.sln - feedsToUse: config - nugetConfigPath: nuget.config + PathtoPublish: '$(publishDir)' + artifactName: 'drop' - - task: VSBuild@1 - displayName: 'Build solution MUXControls.sln' - inputs: - solution: MUXControls.sln - vsVersion: 15.0 - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' \ No newline at end of file +# Create Nuget Package +- template: AzurePipelinesTemplates\MUX-CreateNugetPackage-Job.yml + parameters: + jobName: CreateNugetPackage + dependsOn: Build + primaryBuildArch: x64 + +# Build solution that depends on nuget package +- template: AzurePipelinesTemplates\MUX-NugetReleaseTest-Job.yml + parameters: + dependsOn: CreateNugetPackage + useNupkgFromArtifacts: true + matrix: + Debug_x64: + buildPlatform: 'x64' + buildConfiguration: 'Debug' + Release_x64: + buildPlatform: 'x64' + buildConfiguration: 'Release' diff --git a/test/MUXControlsReleaseTest/NugetPackageTestApp/NugetPackageTestApp.csproj b/test/MUXControlsReleaseTest/NugetPackageTestApp/NugetPackageTestApp.csproj index 658785c..0ccc160 100644 --- a/test/MUXControlsReleaseTest/NugetPackageTestApp/NugetPackageTestApp.csproj +++ b/test/MUXControlsReleaseTest/NugetPackageTestApp/NugetPackageTestApp.csproj @@ -148,7 +148,7 @@ 6.1.7 - 2.0.180916002-prerelease + 2.1.181217001-prerelease 1.0.38 @@ -167,9 +167,6 @@ --> - - - diff --git a/test/MUXControlsReleaseTest/NugetPackageTestAppCX/NugetPackageTestAppCX.vcxproj b/test/MUXControlsReleaseTest/NugetPackageTestAppCX/NugetPackageTestAppCX.vcxproj index 3c07daf..4db2653 100644 --- a/test/MUXControlsReleaseTest/NugetPackageTestAppCX/NugetPackageTestAppCX.vcxproj +++ b/test/MUXControlsReleaseTest/NugetPackageTestAppCX/NugetPackageTestAppCX.vcxproj @@ -195,12 +195,12 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + diff --git a/test/MUXControlsReleaseTest/NugetPackageTestAppCX/packages.config b/test/MUXControlsReleaseTest/NugetPackageTestAppCX/packages.config index 566e253..ef90cca 100644 --- a/test/MUXControlsReleaseTest/NugetPackageTestAppCX/packages.config +++ b/test/MUXControlsReleaseTest/NugetPackageTestAppCX/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/tools/PostBuild.cmd b/tools/PostBuild.cmd index 8b9f7b4..8c1af09 100644 --- a/tools/PostBuild.cmd +++ b/tools/PostBuild.cmd @@ -56,7 +56,7 @@ echo ++++++++++++++++ ----------- ++++++++++++++++++++++++ pushd %~dp0\..\build\NuSpecs -set NUGETCMD=\\edge-svcs\nuget\v3.5\nuget.exe +set NUGETCMD=%~dp0\NugetWrapper.cmd set BUILDOUTPUT=%XES_DFSDROP% set OUTPUTDIR=%BUILD_BINARIESDIRECTORY%\PostBuild set ECHOON=1