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 # Make a nicely formatted string of the dir props version elements. Short names, joined by commas.
26 $DirPropsVersionNames = ($DirPropsVersionElements | %{ $_ -replace 'ExpectedPrerelease', '' }) -join ', '
28 # Updates the dir.props file with the latest build number
29 function UpdateValidDependencyVersionsFile
33 Write-Error "Unable to find latest dependency version at $VersionFileUrl ($DirPropsVersionNames)"
37 $DirPropsPath = "$PSScriptRoot\dir.props"
39 $DirPropsContent = Get-Content $DirPropsPath | % {
41 $DirPropsVersionElements | % {
42 $line = $line -replace `
44 "<$_>$LatestVersion</$_>"
48 Set-Content $DirPropsPath $DirPropsContent
53 # Creates a Pull Request for the updated version numbers
54 function CreatePullRequest
56 $GitStatus = git status --porcelain
57 if ([string]::IsNullOrWhiteSpace($GitStatus))
59 Write-Warning "Dependencies are currently up to date"
63 $CommitMessage = "Updating $DirPropsVersionNames dependencies to $LatestVersion"
65 $env:GIT_COMMITTER_NAME = $GitHubUser
66 $env:GIT_COMMITTER_EMAIL = $GitHubEmail
67 git commit -a -m "$CommitMessage" --author "$GitHubUser <$GitHubEmail>" | Out-Host
69 $RemoteUrl = "github.com/$GitHubOriginOwner/$GitHubProject.git"
70 $RemoteBranchName = "UpdateDependencies$([DateTime]::UtcNow.ToString('yyyyMMddhhmmss'))"
71 $RefSpec = "HEAD:refs/heads/$RemoteBranchName"
73 Write-Host "git push https://$RemoteUrl $RefSpec"
74 # pipe this to null so the password secret isn't in the logs
75 git push "https://$($GitHubUser):$GitHubPassword@$RemoteUrl" $RefSpec 2>&1 | Out-Null
77 if ($GitHubPullRequestNotifications)
79 $PRNotifications = $GitHubPullRequestNotifications.Split(';', [StringSplitOptions]::RemoveEmptyEntries) -join ' @'
80 $PRBody = "/cc @$PRNotifications"
89 "title": "$CommitMessage",
91 "head": "$($GitHubOriginOwner):$RemoteBranchName",
92 "base": "$GitHubUpstreamBranch"
96 $CreatePRHeaders = @{'Accept'='application/vnd.github.v3+json'; 'Authorization'="token $GitHubPassword"}
100 Invoke-WebRequest https://api.github.com/repos/$GitHubUpstreamOwner/$GitHubProject/pulls -UseBasicParsing -Method Post -Body $CreatePRBody -Headers $CreatePRHeaders
104 Write-Error $_.ToString()
111 if (!(UpdateValidDependencyVersionsFile))
116 if (!(CreatePullRequest))
121 Write-Host -ForegroundColor Green "Successfully updated dependencies from the latest build numbers"