From 1968789169faf29a481b638cf560b4aadf34b378 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 11 May 2020 16:44:31 -0700 Subject: [PATCH 1/6] Update files.wxs when needed with the UpdateMSIPackaging switch --- tools/UpdateDotnetRuntime.ps1 | 29 ++++++++++++++++++++++++++++- tools/packaging/packaging.psm1 | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index dd1b168d91c..230bc6bd3ad 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -4,7 +4,10 @@ [CmdletBinding()] param ( [Parameter()] - [string]$SDKVersionOverride + [string]$SDKVersionOverride, + + [Parameter()] + [switch]$UpdateMSIPackaging ) <# @@ -173,3 +176,27 @@ Write-Verbose -Message "Updating global.json completed." -Verbose Update-PackageVersion Write-Verbose -Message "Updating project files completed." -Verbose + +if ($UpdateMSIPackaging) { + if (-not $IsWindows) { + throw "UpdateMSIPackaging can only be done on Windows" + } + + Import-Module "$PSScriptRoot/../build.psm1" -Force + Import-Module "$PSScriptRoot/packaging" -Force + Start-PSBootstrap -Package + Start-PSBuild -Clean -Configuration Release -CrossGen + + try { + Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData + } + catch { + if ($_.Exception.Message -like "Current files to not match *") { + Copy-Item -Path $($wxsData.MessageData.NewFile) -Destination ($wxsData.MessageData.FilesWxsPath) + Write-Verbose -Message "Updating files.wxs file completed." -Verbose + } + else { + throw $_ + } + } +} diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 507d8fe902b..1673abf4095 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -3383,6 +3383,7 @@ function Test-FileWxs $newXml | Out-File -FilePath $newXmlFileName -Encoding ascii Write-Log -message "Updated xml saved to $newXmlFileName." Write-Log -message "If component files were intentionally changed, such as due to moving to a newer .NET Core runtime, update '$FilesWxsPath' with the content from '$newXmlFileName'." + Write-Information -MessageData @{FilesWxsPath = $FilesWxsPath; NewFile = $newXmlFileName} -Tags 'PackagingWxs' if ($env:TF_BUILD) { Write-Host "##vso[artifact.upload containerfolder=wix;artifactname=wix]$newXmlFileName" From be4f2a44c9440c288036b1601e85ed9b6f21b05b Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 12 May 2020 15:00:57 -0700 Subject: [PATCH 2/6] Add function to get the latest SDK version --- tools/UpdateDotnetRuntime.ps1 | 122 ++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 42 deletions(-) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 230bc6bd3ad..9a7a853be78 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -64,7 +64,7 @@ function Update-PackageVersion { "$PSScriptRoot/../test/tools/" ) - Get-ChildItem -Path $paths -Recurse -Filter "*.csproj" -Exclude 'PSGalleryModules.csproj','PSGalleryTestModules.csproj' | ForEach-Object { + Get-ChildItem -Path $paths -Recurse -Filter "*.csproj" -Exclude 'PSGalleryModules.csproj', 'PSGalleryTestModules.csproj' | ForEach-Object { Write-Verbose -Message "Reading - $($_.FullName)" -Verbose $prj = [xml] (Get-Content $_.FullName -Raw) $pkgRef = $prj.Project.ItemGroup.PackageReference @@ -73,8 +73,7 @@ function Update-PackageVersion { if ($null -ne $p -and -not $skipModules.Contains($p.Include)) { if (-not $packages.ContainsKey($p.Include)) { $packages.Add($p.Include, @([PkgVer]::new($p.Include, $p.Version, $null, $_.FullName))) - } - else { + } else { $packages[$p.Include] += [PkgVer]::new($p.Include, $p.Version, $null, $_.FullName) } } @@ -130,73 +129,112 @@ function Update-CsprojFile([string] $path, $values) { } } -$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json" -$dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json +function Get-DotnetUpdate { + try { + $dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json" + $nextChannel = (Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json).sdk.nextChannel + $latestSDKversion = [System.Management.Automation.SemanticVersion] (Invoke-RestMethod -Uri "http://aka.ms/dotnet/$nextChannel/Sdk/productVersion.txt" -ErrorAction Stop | ForEach-Object { $_.Trim() }) + $currentVersion = [System.Management.Automation.SemanticVersion] (( Get-Content -Path "$PSScriptRoot/../global.json" -Raw | ConvertFrom-Json).sdk.version) + + if ($latestSDKversion -gt $currentVersion) { + $shouldUpdate = $true + $newVersion = $latestSDKversion + } else { + $shouldUpdate = $false + $newVersion = $null + } + } catch { + Write-Verbose -Verbose "Error occured: $_.message" + $shouldUpdate = $false + $newVersion = $null + Write-Error "Error while checking .NET SDK update: $($_.message)" + } -# Channel is like: $Channel = "5.0.1xx-preview2" -$Channel = $dotnetMetadataJson.sdk.channel + return @{ + ShouldUpdate = $shouldUpdate + NewVersion = $newVersion + Message = $Message + } +} -Import-Module "$PSScriptRoot/../build.psm1" -Force +$dotnetUpdate = Get-DotnetUpdate -Find-Dotnet +if ($dotnetUpdate.ShouldUpdate) { +<<<<<<< HEAD if(-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) { $nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet Write-Verbose -Message "Register new package source 'dotnet5'" -Verbose } +======= + $dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json" + $dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json +>>>>>>> Add function to get the latest SDK version -## Install latest version from the channel + # Channel is like: $Channel = "5.0.1xx-preview2" + $Channel = $dotnetMetadataJson.sdk.channel -$sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { "latest" } + Import-Module "$PSScriptRoot/../build.psm1" -Force -Install-Dotnet -Channel "$Channel" -Version $sdkVersion + Find-Dotnet -Write-Verbose -Message "Installing .NET SDK completed." -Verbose + if (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) { + $nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value + Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet + Write-Verbose -Message "Register new package source 'dotnet5'" -verbose + } -$isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT + ## Install latest version from the channel -$dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" } + $sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { $dotnetUpdate.NewVersion } -$pathSep = [System.IO.Path]::PathSeparator + Install-Dotnet -Channel "$Channel" -Version $sdkVersion -if (-not (($ENV:PATH -split $pathSep) -contains "$dotnetPath")) { - $env:PATH = "$dotnetPath" + $pathSep + "$ENV:PATH" -} + Write-Verbose -Message "Installing .NET SDK completed." -Verbose -$latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1 + $isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT -Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose + $dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" } -Update-GlobalJson -Version $latestSdkVersion + $pathSep = [System.IO.Path]::PathSeparator -Write-Verbose -Message "Updating global.json completed." -Verbose + if (-not (($ENV:PATH -split $pathSep) -contains "$dotnetPath")) { + $env:PATH = "$dotnetPath" + $pathSep + "$ENV:PATH" + } -Update-PackageVersion + $latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1 -Write-Verbose -Message "Updating project files completed." -Verbose + Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose -if ($UpdateMSIPackaging) { - if (-not $IsWindows) { - throw "UpdateMSIPackaging can only be done on Windows" - } + Update-GlobalJson -Version $latestSdkVersion - Import-Module "$PSScriptRoot/../build.psm1" -Force - Import-Module "$PSScriptRoot/packaging" -Force - Start-PSBootstrap -Package - Start-PSBuild -Clean -Configuration Release -CrossGen + Write-Verbose -Message "Updating global.json completed." -Verbose - try { - Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData - } - catch { - if ($_.Exception.Message -like "Current files to not match *") { - Copy-Item -Path $($wxsData.MessageData.NewFile) -Destination ($wxsData.MessageData.FilesWxsPath) - Write-Verbose -Message "Updating files.wxs file completed." -Verbose + Update-PackageVersion + + Write-Verbose -Message "Updating project files completed." -Verbose + + if ($UpdateMSIPackaging) { + if (-not $isWindowsEnv) { + throw "UpdateMSIPackaging can only be done on Windows" } - else { - throw $_ + + Import-Module "$PSScriptRoot/../build.psm1" -Force + Import-Module "$PSScriptRoot/packaging" -Force + Start-PSBootstrap -Package + Start-PSBuild -Clean -Configuration Release -CrossGen + + try { + Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData + } catch { + if ($_.Exception.Message -like "Current files to not match *") { + Copy-Item -Path $($wxsData.MessageData.NewFile) -Destination ($wxsData.MessageData.FilesWxsPath) + Write-Verbose -Message "Updating files.wxs file completed." -Verbose + } else { + throw $_ + } } } } From c88e74594848a8dc072753bef59b290725c333dc Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 21 May 2020 11:11:28 -0700 Subject: [PATCH 3/6] Fix merge --- tools/UpdateDotnetRuntime.ps1 | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 9a7a853be78..91b8b05c98f 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -161,17 +161,8 @@ $dotnetUpdate = Get-DotnetUpdate if ($dotnetUpdate.ShouldUpdate) { -<<<<<<< HEAD -if(-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) -{ - $nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value - Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet - Write-Verbose -Message "Register new package source 'dotnet5'" -Verbose -} -======= $dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json" $dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json ->>>>>>> Add function to get the latest SDK version # Channel is like: $Channel = "5.0.1xx-preview2" $Channel = $dotnetMetadataJson.sdk.channel From 88950a99469a4d95931f5891686cd259e06a251f Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 21 May 2020 11:34:05 -0700 Subject: [PATCH 4/6] Address feedback --- tools/UpdateDotnetRuntime.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 91b8b05c98f..b9ea0add9b9 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -185,9 +185,9 @@ if ($dotnetUpdate.ShouldUpdate) { Write-Verbose -Message "Installing .NET SDK completed." -Verbose - $isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT + $environment = Get-EnvironmentInformation - $dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" } + $dotnetPath = if ($environment.IsWindows) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" } $pathSep = [System.IO.Path]::PathSeparator @@ -208,7 +208,7 @@ if ($dotnetUpdate.ShouldUpdate) { Write-Verbose -Message "Updating project files completed." -Verbose if ($UpdateMSIPackaging) { - if (-not $isWindowsEnv) { + if (-not $environment.IsWindows) { throw "UpdateMSIPackaging can only be done on Windows" } From 47a8f031e5743648feabb04223700f414b30bedf Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 21 May 2020 15:08:39 -0700 Subject: [PATCH 5/6] GitHub Action --- .github/workflows/daily.yml | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/daily.yml diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml new file mode 100644 index 00000000000..8393b868f16 --- /dev/null +++ b/.github/workflows/daily.yml @@ -0,0 +1,53 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +name: PowerShell Daily +on: + schedule: + # At 13:00 UTC every day. + - cron: '0 13 * * *' + +defaults: + run: + shell: pwsh + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + POWERSHELL_TELEMETRY_OPTOUT: 1 + +jobs: + update-dotnet-preview: + name: Update .NET preview + timeout-minutes: 15 + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Sync tags + run: | + git fetch --prune --unshallow --tags + - name: Execute Update .NET script + run: | + $currentVersion = (Get-Content .\global.json | ConvertFrom-Json).sdk.version + Write-Verbose "name=OLD_VERSION::$currentVersion" -Verbose + Write-Host "::set-env name=OLD_VERSION::$currentVersion" + + ./tools/UpdateDotnetRuntime.ps1 -UpdateMSIPackaging + $newVersion = (Get-Content .\global.json | ConvertFrom-Json).sdk.version + Write-Verbose "name=NEW_VERSION::$newVersion" -Verbose + Write-Host "::set-env name=NEW_VERSION::$newVersion" + + if ($currentVersion -ne $newVersion) { + Write-Verbose "name=CREATE_PR::true" -Verbose + Write-Host "::set-env name=CREATE_PR::true" + } + - name: Create Pull Request + uses: peter-evans/create-pull-request@v2 + id: cpr + if: env.CREATE_PR == 'true' + with: + commit-message: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" + title: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" + base: master + + From 1fac23873f4ce1c1d9c2ac41c6b5eb2f2feff300 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 21 May 2020 18:15:12 -0700 Subject: [PATCH 6/6] Update branch name --- .github/workflows/daily.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 8393b868f16..a8e5e563425 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -49,5 +49,6 @@ jobs: commit-message: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" title: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" base: master + branch: dotnet_update