UpdateDependenciesCoreFx.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. [CmdletBinding()]
  2. param(
  3. [switch]$NoCommit,
  4. [string]$GithubEmail,
  5. [string]$GithubUsername,
  6. [string]$GithubToken
  7. )
  8. # This script only works against master at the moment because only master prod-con builds allow you to access their results before the entire chain is finished.
  9. $ErrorActionPreference = 'Stop'
  10. Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
  11. Set-StrictMode -Version 1
  12. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  13. $githubRaw = "https://raw.githubusercontent.com"
  14. $versionsRepo = "dotnet/versions"
  15. $versionsBranch = "master"
  16. $coreSetupRepo = "dotnet/core-setup"
  17. $coreFxRepo = "dotnet/corefx"
  18. $coreSetupVersions = "$githubRaw/$versionsRepo/$versionsBranch/build-info/$coreSetupRepo/master/Latest_Packages.txt"
  19. $tempDir = "$PSScriptRoot/../obj"
  20. mkdir -Path $tempDir -ErrorAction Ignore
  21. $localCoreSetupVersions = "$tempDir/coresetup.packages"
  22. Write-Host "Downloading $coreSetupVersions to $localCoreSetupVersions"
  23. Invoke-WebRequest -OutFile $localCoreSetupVersions -Uri $coreSetupVersions
  24. $msNetCoreAppPackageVersion = $null
  25. $msNetCoreAppPackageName = "Microsoft.NETCore.App"
  26. Set-GitHubInfo $GithubToken $GithubUsername $GithubEmail
  27. $variables = @{}
  28. foreach ($line in Get-Content $localCoreSetupVersions) {
  29. if ($line.StartsWith("$msNetCoreAppPackageName ")) {
  30. $msNetCoreAppPackageVersion = $line.Trim("$msNetCoreAppPackageName ")
  31. }
  32. $parts = $line.Split(' ')
  33. $packageName = $parts[0]
  34. $varName = "$packageName" + "PackageVersion"
  35. $varName = $varName.Replace('.', '')
  36. $packageVersion = $parts[1]
  37. if ($variables[$varName]) {
  38. if ($variables[$varName].Where( {$_ -eq $packageVersion}, 'First').Count -eq 0) {
  39. $variables[$varName] += $packageVersion
  40. }
  41. }
  42. else {
  43. $variables[$varName] = @($packageVersion)
  44. }
  45. }
  46. if (!$msNetCoreAppPackageVersion) {
  47. throw "$msNetCoreAppPackageName was not in $coreSetupVersions"
  48. }
  49. $coreAppDownloadLink = "https://dotnet.myget.org/F/dotnet-core/api/v2/package/$msNetCoreAppPackageName/$msNetCoreAppPackageVersion"
  50. $netCoreAppNupkg = "$tempDir/microsoft.netcore.app.zip"
  51. Invoke-WebRequest -OutFile $netCoreAppNupkg -Uri $coreAppDownloadLink
  52. $expandedNetCoreApp = "$tempDir/microsoft.netcore.app/"
  53. Expand-Archive -Path $netCoreAppNupkg -DestinationPath $expandedNetCoreApp -Force
  54. $versionsTxt = "$expandedNetCoreApp/$msNetCoreAppPackageName.versions.txt"
  55. $versionsCoreFxCommit = $null
  56. foreach ($line in Get-Content $versionsTxt) {
  57. if ($line.StartsWith("dotnet/versions/corefx")) {
  58. $versionsCoreFxCommit = $line.Split(' ')[1]
  59. break
  60. }
  61. }
  62. if (!$versionsCoreFxCommit) {
  63. Throw "no 'dotnet/versions/corefx' in versions.txt of Microsoft.NETCore.App"
  64. }
  65. $coreFxVersionsUrl = "$githubRaw/$versionsRepo/$versionsCoreFxCommit/build-info/$coreFxRepo/$versionsBranch/Latest_Packages.txt"
  66. $localCoreFxVersions = "$tempDir/$corefx.packages"
  67. Invoke-WebRequest -OutFile $localCoreFxVersions -Uri $coreFxVersionsUrl
  68. foreach ($line in Get-Content $localCoreFxVersions) {
  69. $parts = $line.Split(' ')
  70. $packageName = $parts[0]
  71. $varName = "$packageName" + "PackageVersion"
  72. $varName = $varName.Replace('.', '')
  73. $packageVersion = $parts[1]
  74. if ($variables[$varName]) {
  75. if ($variables[$varName].Where( {$_ -eq $packageVersion}, 'First').Count -eq 0) {
  76. $variables[$varName] += $packageVersion
  77. }
  78. }
  79. else {
  80. $variables[$varName] = @($packageVersion)
  81. }
  82. }
  83. $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props"
  84. Write-Host "Loading deps from $depsPath"
  85. [xml] $dependencies = LoadXml $depsPath
  86. if (-not $NoCommit) {
  87. $baseBranch = "master"
  88. Invoke-Block { & git fetch origin }
  89. $currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD }
  90. $destinationBranch = "upgrade-netcore-deps"
  91. Invoke-Block { & git checkout -tb $destinationBranch "origin/$baseBranch" }
  92. }
  93. try {
  94. $updatedVars = UpdateVersions $variables $dependencies $depsPath
  95. if (-not $NoCommit) {
  96. $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath "Upgrade to .NET Core $msNetCoreAppPackageVersion"
  97. if ($body) {
  98. CreatePR "aspnet" $GithubUsername $baseBranch $destinationBranch $body $GithubToken
  99. }
  100. }
  101. }
  102. finally {
  103. if (-not $NoCommit) {
  104. Invoke-Block { & git checkout $currentBranch }
  105. }
  106. }