From 14ced821c94547ae1d5c66840c4bdd560224b04e Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 3 Sep 2021 15:18:50 -0700 Subject: [PATCH] Fix the GitHub Action for updating .NET daily builds (#16042) --- .github/workflows/daily.yml | 5 +++-- tools/UpdateDotnetRuntime.ps1 | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 6e3a38ac1b..a1c883c98f 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -34,7 +34,7 @@ jobs: Write-Verbose "OLD_VERSION=$currentVersion" -Verbose "OLD_VERSION=$currentVersion" | Out-File $env:GITHUB_ENV -Append - ./tools/UpdateDotnetRuntime.ps1 -UpdateMSIPackaging + ./tools/UpdateDotnetRuntime.ps1 -UpdateMSIPackaging -UseInternalFeed $newVersion = (Get-Content .\global.json | ConvertFrom-Json).sdk.version Write-Verbose "NEW_VERSION=$newVersion" -Verbose "NEW_VERSION=$newVersion" | Out-File $env:GITHUB_ENV -Append @@ -48,8 +48,9 @@ jobs: if: failure() with: webhook_url: ${{ secrets.PS_BUILD_TEAMS_CHANNEL }} + overwrite: "{title: `Failure in updating .NET build. Look at ${workflow_link}`}" - name: Create Pull Request - uses: peter-evans/create-pull-request@v2 + uses: peter-evans/create-pull-request@v3 id: cpr if: env.CREATE_PR == 'true' with: diff --git a/tools/UpdateDotnetRuntime.ps1 b/tools/UpdateDotnetRuntime.ps1 index 15c482ba63..5126d10999 100644 --- a/tools/UpdateDotnetRuntime.ps1 +++ b/tools/UpdateDotnetRuntime.ps1 @@ -187,17 +187,23 @@ function Get-DotnetUpdate { try { - $latestSDKVersionString = Invoke-RestMethod -Uri "http://aka.ms/dotnet/$channel/$quality/sdk-productVersion.txt" -ErrorAction Stop | ForEach-Object { $_.Trim() } - $selectedQuality = $quality + try { + $latestSDKVersionString = Invoke-RestMethod -Uri "http://aka.ms/dotnet/$channel/$quality/sdk-productVersion.txt" -ErrorAction Stop | ForEach-Object { $_.Trim() } + $selectedQuality = $quality + } catch { + if ($_.exception.Response.StatusCode -eq 'NotFound') { + Write-Verbose "Build not found for Channel: $Channel and Quality: $Quality" -Verbose + } else { + throw $_ + } + } - if (-not $latestSDKVersionString.StartsWith($sdkImageVersion)) - { + if (-not $latestSDKVersionString -or -not $latestSDKVersionString.StartsWith($sdkImageVersion)) { # we did not get a version number so fall back to daily $latestSDKVersionString = Invoke-RestMethod -Uri "http://aka.ms/dotnet/$channel/$qualityFallback/sdk-productVersion.txt" -ErrorAction Stop | ForEach-Object { $_.Trim() } $selectedQuality = $qualityFallback - if (-not $latestSDKVersionString.StartsWith($sdkImageVersion)) - { + if (-not $latestSDKVersionString.StartsWith($sdkImageVersion)) { throw "No build found!" } } @@ -272,8 +278,15 @@ if ($dotnetUpdate.ShouldUpdate) { if ($feedname -eq 'dotnet-internal') { # This NuGet feed is for internal to Microsoft use only. $dotnetInternalFeed = $dotnetMetadataJson.internalfeed.url - $updatedNugetFile = $nugetFileContent -replace "", " `r`n " + + $updatedNugetFile = if ($nugetFileContent.Contains('dotnet-internal')) { + $nugetFileContent -replace ".`r`n " + } else { + $nugetFileContent -replace "", " `r`n " + } + $updatedNugetFile | Out-File "$PSScriptRoot/../nuget.config" -Force + Register-PackageSource -Name 'dotnet-internal' -Location $dotnetInternalFeed -ProviderName NuGet Write-Verbose -Message "Register new package source 'dotnet-internal'" -verbose }