UpdateDependenciesCoreFx.ps1 4.2 KB

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