From c8ad329c80f17cb76a517d3cb5ac60b66cb19fe1 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:03:23 +0200 Subject: [PATCH 1/2] update deloyment script --- .exp-insertions.yml | 123 +++++++++++++++++++++++++++++++++++++ scripts/Deploy-MSBuild.ps1 | 26 +++++--- 2 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 .exp-insertions.yml diff --git a/.exp-insertions.yml b/.exp-insertions.yml new file mode 100644 index 00000000000..47db437b5c3 --- /dev/null +++ b/.exp-insertions.yml @@ -0,0 +1,123 @@ +# Pipeline creates a dotnet with experimental msbuild dlls. + +trigger: none # Prevents this pipeline from triggering on check-ins +pr: none # don't run this on PR as well + +parameters: + # Dotnet installer channel from where to take the latest dotnet bits. + - name: DotnetInstallerChannel + displayName: Dotnet installer channel + type: string + # Branch from the MSBuild Build CI pipeline. Default: main + # Top run for the branch would be used to create an experimental insertion. + - name: MSBuildBranch + displayName: MSBuild Branch + type: string + default: 'refs/heads/main' + # BuildID from the MSBuild Build CI pipeline. Overrides the choice of MSBuildBranch parameter + - name: MSBuildBuildID + displayName: MSBuild CI Run Override + type: string + default: 'default' + +pool: + vmImage: windows-latest + +steps: +- powershell: | + mkdir '$(System.ArtifactsDirectory)/installer' + + $dotnetChannel = '${{parameters.DotnetInstallerChannel}}' + $sdks = "dotnet-sdk-win-x64.zip", "dotnet-sdk-linux-x64.tar.gz" + + foreach ($sdk in $sdks) + { + Write-Host "Downloading dotnet $sdk from channel $dotnetChannel" + Invoke-WebRequest ` + -Uri "https://aka.ms/dotnet/$dotnetChannel/daily/$sdk" ` + -OutFile "$(System.ArtifactsDirectory)/installer/$sdk" + } + mkdir '$(Pipeline.Workspace)/artifacts' + + displayName: Download latest dotnet sdks + +# Download latest build artifacts for a branch from MSBuild Build CI +- ${{ if eq(parameters.MSBuildBuildID, 'default') }}: + - task: DownloadBuildArtifacts@1 + inputs: + buildType: specific + project: DevDiv + pipeline: 9434 # MSBuild Build CI + buildVersionToDownload: latestFromBranch + branchName: '${{parameters.MSBuildBranch}}' + artifactName: bin + downloadPath: '$(System.ArtifactsDirectory)/msbuild/artifacts/bin' + itemPattern: "MSBuild.Bootstrap/**" + displayName: Download latest msbuild from branch + +# Download build artifacts for MSBuild Build CI specific build +- ${{ if ne(parameters.MSBuildBuildID, 'default') }}: + - task: DownloadBuildArtifacts@1 + inputs: + buildType: specific + project: DevDiv + pipeline: 9434 # MSBuild Build CI + buildVersionToDownload: specific + buildId: ${{parameters.MSBuildBuildID}} + artifactName: bin + downloadPath: '$(System.ArtifactsDirectory)/msbuild/artifacts/bin' + itemPattern: "MSBuild.Bootstrap/**" + displayName: Download specified msbuild build + +- powershell: | + $sdk = "dotnet-sdk-win-x64" + + Write-Host "Extracting $(System.ArtifactsDirectory)/installer/$sdk.zip" + Expand-Archive "$(System.ArtifactsDirectory)/installer/$sdk.zip" -DestinationPath "$(Pipeline.Workspace)/exp-dotnet/$sdk" + + $dotnetDirectory = Get-ChildItem -Directory -Path "$(Pipeline.Workspace)/exp-dotnet/$sdk/sdk" + $dotnetVersion = $dotnetDirectory.Name + Write-Host "Detected dotnet version: $dotnetVersion" + + Write-Host "Updating MSBuild dlls." + $(Build.SourcesDirectory)/scripts/Deploy-MSBuild.ps1 ` + -destination "$(Pipeline.Workspace)/exp-dotnet/$sdk/sdk/$dotnetVersion" ` + -bootstrapDirectory "$(System.ArtifactsDirectory)/msbuild/artifacts/bin/MSBuild.Bootstrap" ` + -configuration Release ` + -makeBackup $false + + Write-Host "Compressing dotnet sdk files" + Get-ChildItem -Path "$(Pipeline.Workspace)/exp-dotnet/$sdk" | Compress-Archive -DestinationPath "$(Pipeline.Workspace)/artifacts/$sdk.zip" + + displayName: Dogfood msbuild dlls to dotnet sdk win-x64 + +- powershell: | + $sdk = "dotnet-sdk-linux-x64" + + mkdir "$(Pipeline.Workspace)/exp-dotnet/$sdk" + + Write-Host "Extracting $(System.ArtifactsDirectory)/installer/$sdk.tar.gz" + tar -xzvf "$(System.ArtifactsDirectory)/installer/$sdk.tar.gz" -C "$(Pipeline.Workspace)/exp-dotnet/$sdk" + + $dotnetDirectory = Get-ChildItem -Directory -Path $(Pipeline.Workspace)/exp-dotnet/$sdk/sdk + $dotnetVersion = $dotnetDirectory.Name + Write-Host "Detected dotnet version: $dotnetVersion" + + Write-Host "Updating MSBuild dlls." + $(Build.SourcesDirectory)/scripts/Deploy-MSBuild.ps1 ` + -destination "$(Pipeline.Workspace)/exp-dotnet/$sdk/sdk/$dotnetVersion" ` + -bootstrapDirectory "$(System.ArtifactsDirectory)/msbuild/artifacts/bin/MSBuild.Bootstrap" ` + -configuration Release ` + -makeBackup $false + + Write-Host "Compressing dotnet sdk files" + tar -czvf "$(Pipeline.Workspace)/artifacts/$sdk.tar.gz" -C "$(Pipeline.Workspace)/exp-dotnet/$sdk" . + displayName: Dogfood msbuild dlls to dotnet sdk linux-x64 + +- task: PublishPipelineArtifact@1 + inputs: + targetPath: '$(Pipeline.Workspace)/artifacts' + artifactName: ExperimentalDotnet + parallel: true + condition: always() + displayName: Publish crank assests artifacts diff --git a/scripts/Deploy-MSBuild.ps1 b/scripts/Deploy-MSBuild.ps1 index 37b65ce9199..58966a34fdf 100644 --- a/scripts/Deploy-MSBuild.ps1 +++ b/scripts/Deploy-MSBuild.ps1 @@ -5,7 +5,9 @@ Param( [ValidateSet('Debug','Release')] [string] $configuration = "Debug", [ValidateSet('Core','Desktop', 'Detect', 'Full')] - [string] $runtime = "Detect" + [string] $runtime = "Detect", + [string] $bootstrapDirectory = "", + [bool] $makeBackup = $true ) Set-StrictMode -Version "Latest" @@ -15,9 +17,9 @@ function Copy-WithBackup ($origin, $destinationSubFolder = "") { $directoryPart = [IO.Path]::Combine($destination, $destinationSubFolder, $origin.IntermediaryDirectories) $destinationPath = Join-Path -Path $directoryPart (Split-Path $origin.SourceFile -leaf) - $backupInto = [IO.Path]::Combine($BackupFolder, $destinationSubFolder) + if (($makeBackup) -and (Test-Path $destinationPath -PathType Leaf)) { + $backupInto = [IO.Path]::Combine($BackupFolder, $destinationSubFolder) - if (Test-Path $destinationPath -PathType Leaf) { # Back up previous copy of the file if (!(Test-Path $backupInto)) { [system.io.directory]::CreateDirectory($backupInto) @@ -45,10 +47,15 @@ function FileToCopy([string] $sourceFileRelativeToRepoRoot, [string] $intermedia # TODO: find most-recently-built MSBuild and make it default $configuration -$BackupFolder = New-Item (Join-Path $destination -ChildPath "Backup-$(Get-Date -Format FileDateTime)") -itemType directory -ErrorAction Stop - Write-Verbose "Copying $configuration MSBuild to $destination" -Write-Host "Existing MSBuild assemblies backed up to $BackupFolder" + +if ($makeBackup) { + $BackupFolder = New-Item (Join-Path $destination -ChildPath "Backup-$(Get-Date -Format FileDateTime)") -itemType directory -ErrorAction Stop + Write-Host "Existing MSBuild assemblies backed up to $BackupFolder" +} +else { + Write-Host "Existing MSBuild assemblies won't be backed up" +} if ($runtime -eq "Detect") { if ($destination -like "*dotnet*sdk*") { @@ -72,7 +79,12 @@ if ($runtime -eq "Desktop") { $targetFramework = "net8.0" } -$bootstrapBinDirectory = "artifacts\bin\MSBuild.Bootstrap\$configuration\$targetFramework" +# If bootstrap directory is not defined in parameters, use the default location +if ($bootstrapDirectory -eq "") { + $bootstrapDirectory = "artifacts\bin\MSBuild.Bootstrap" +} + +$bootstrapBinDirectory = "$bootstrapDirectory\$configuration\$targetFramework" $filesToCopyToBin = @( FileToCopy "$bootstrapBinDirectory\Microsoft.Build.dll" From 6b881cfca644c88c0222323f36afce3b36167ab7 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Wed, 20 Sep 2023 13:19:56 +0200 Subject: [PATCH 2/2] Address PR comments --- .exp-insertions.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.exp-insertions.yml b/.exp-insertions.yml index 47db437b5c3..e3e22653a53 100644 --- a/.exp-insertions.yml +++ b/.exp-insertions.yml @@ -20,6 +20,10 @@ parameters: type: string default: 'default' +variables: + - name: _MsBuildCiPipelineId + value: 9434 + pool: vmImage: windows-latest @@ -47,7 +51,7 @@ steps: inputs: buildType: specific project: DevDiv - pipeline: 9434 # MSBuild Build CI + pipeline: $(_MsBuildCiPipelineId) buildVersionToDownload: latestFromBranch branchName: '${{parameters.MSBuildBranch}}' artifactName: bin @@ -61,7 +65,7 @@ steps: inputs: buildType: specific project: DevDiv - pipeline: 9434 # MSBuild Build CI + pipeline: $(_MsBuildCiPipelineId) buildVersionToDownload: specific buildId: ${{parameters.MSBuildBuildID}} artifactName: bin