2 # Copyright (c) .NET Foundation and contributors. All rights reserved.
3 # Licensed under the MIT license. See LICENSE file in the project root for full license information.
6 # This script updates dir.props with the current version of CoreCLR
7 # dependencies, and then creates a Pull Request for the change.
10 [Parameter(Mandatory=$true)][string]$GitHubUser,
11 [Parameter(Mandatory=$true)][string]$GitHubEmail,
12 [Parameter(Mandatory=$true)][string]$GitHubPassword,
13 [Parameter(Mandatory=$true)][string]$VersionFileUrl,
14 [string[]]$DirPropsVersionElements = 'CoreClrExpectedPrerelease',
15 [string]$GitHubUpstreamOwner='dotnet',
16 [string]$GitHubOriginOwner=$GitHubUser,
17 [string]$GitHubProject='coreclr',
18 [string]$GitHubUpstreamBranch='master',
19 # a semi-colon delimited list of GitHub users to notify on the PR
20 [string]$GitHubPullRequestNotifications='')
22 $LatestVersion = Invoke-WebRequest $VersionFileUrl -UseBasicParsing
23 $LatestVersion = $LatestVersion.ToString().Trim()
25 if ($DirPropsVersionElements -contains 'CoreClrExpectedPrerelease')
27 # Also get list of all package versions, relative to the given prerelease version url.
28 $LatestPackagesListUrl = $VersionFileUrl -Replace 'Latest.txt', 'Latest_Packages.txt'
29 $LatestPackagesList = Invoke-WebRequest $LatestPackagesListUrl -UseBasicParsing
30 $LatestCoreCLRPackage = $LatestPackagesList -split "`n" | ?{ $_.StartsWith('Microsoft.NETCore.Runtime.CoreCLR') }
31 $LatestCoreCLRVersion = ($LatestCoreCLRPackage -split ' ')[1].Trim()
35 # Make a nicely formatted string of the dir props version elements. Short names, joined by commas.
36 $DirPropsVersionNames = ($DirPropsVersionElements | %{ $_ -replace 'ExpectedPrerelease', '' }) -join ', '
38 # Updates the dir.props file with the latest build number
39 function UpdateValidDependencyVersionsFile
43 Write-Error "Unable to find latest dependency version at $VersionFileUrl ($DirPropsVersionNames)"
47 $DirPropsPaths = @("$PSScriptRoot\dir.props", "$PSScriptRoot\tests\dir.props")
50 $DirPropsContent = Get-Content $_ | %{
53 $DirPropsVersionElements | %{
54 $line = $line -replace `
56 "<$_>$LatestVersion</$_>"
59 if ($LatestCoreCLRVersion)
61 $line = $line -replace `
62 "<CoreClrPackageVersion>.*<", `
63 "<CoreClrPackageVersion>$LatestCoreCLRVersion<"
68 Set-Content $_ $DirPropsContent
74 # Updates all the project.json files with out of date version numbers
75 function RunUpdatePackageDependencyVersions
77 cmd /c $PSScriptRoot\tests\buildtest.cmd updateinvalidpackages | Out-Host
79 return $LASTEXITCODE -eq 0
82 # Creates a Pull Request for the updated version numbers
83 function CreatePullRequest
85 $GitStatus = git status --porcelain
86 if ([string]::IsNullOrWhiteSpace($GitStatus))
88 Write-Warning "Dependencies are currently up to date"
92 $CommitMessage = "Updating $DirPropsVersionNames dependencies to $LatestVersion"
94 $env:GIT_COMMITTER_NAME = $GitHubUser
95 $env:GIT_COMMITTER_EMAIL = $GitHubEmail
96 git commit -a -m "$CommitMessage" --author "$GitHubUser <$GitHubEmail>" | Out-Host
98 $RemoteUrl = "github.com/$GitHubOriginOwner/$GitHubProject.git"
99 $RemoteBranchName = "UpdateDependencies$([DateTime]::UtcNow.ToString('yyyyMMddhhmmss'))"
100 $RefSpec = "HEAD:refs/heads/$RemoteBranchName"
102 Write-Host "git push https://$RemoteUrl $RefSpec"
103 # pipe this to null so the password secret isn't in the logs
104 git push "https://$($GitHubUser):$GitHubPassword@$RemoteUrl" $RefSpec 2>&1 | Out-Null
106 if ($GitHubPullRequestNotifications)
108 $PRNotifications = $GitHubPullRequestNotifications.Split(';', [StringSplitOptions]::RemoveEmptyEntries) -join ' @'
109 $PRBody = "/cc @$PRNotifications"
118 "title": "$CommitMessage",
120 "head": "$($GitHubOriginOwner):$RemoteBranchName",
121 "base": "$GitHubUpstreamBranch"
125 $CreatePRHeaders = @{'Accept'='application/vnd.github.v3+json'; 'Authorization'="token $GitHubPassword"}
129 Invoke-WebRequest https://api.github.com/repos/$GitHubUpstreamOwner/$GitHubProject/pulls -UseBasicParsing -Method Post -Body $CreatePRBody -Headers $CreatePRHeaders
133 Write-Error $_.ToString()
140 if (!(UpdateValidDependencyVersionsFile))
145 if (!(RunUpdatePackageDependencyVersions))
150 if (!(CreatePullRequest))
155 Write-Host -ForegroundColor Green "Successfully updated dependencies from the latest build numbers"