UpdateDependenciesCoreFx.ps1 3.9 KB

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