From 5a63fd855de5d38d8429b68c50c08b8f00973d22 Mon Sep 17 00:00:00 2001 From: Davis Goodin Date: Mon, 8 Aug 2016 18:45:59 -0500 Subject: [PATCH] Use versions repo tooling from BuildTools. Sets up dependencies.props config. Removes UpdateDependencies powershell script, to be replaced by a call into VersionTools in Maestro automation. Changes UpdatePublishedVersions to pass through to VersionTools for backward compatibility. --- UpdateDependencies.ps1 | 157 ------------------------------------ UpdatePublishedVersions.ps1 | 138 +++---------------------------- dependencies.props | 94 +++++++++++++++++++++ dir.props | 6 +- tests/build.proj | 19 +---- tests/dir.props | 36 +-------- 6 files changed, 112 insertions(+), 338 deletions(-) delete mode 100644 UpdateDependencies.ps1 create mode 100644 dependencies.props diff --git a/UpdateDependencies.ps1 b/UpdateDependencies.ps1 deleted file mode 100644 index 51f24c5c144b..000000000000 --- a/UpdateDependencies.ps1 +++ /dev/null @@ -1,157 +0,0 @@ -# -# Copyright (c) .NET Foundation and contributors. All rights reserved. -# Licensed under the MIT license. See LICENSE file in the project root for full license information. -# - -# This script updates dir.props with the current version of CoreCLR -# dependencies, and then creates a Pull Request for the change. - -param( - [Parameter(Mandatory=$true)][string]$GitHubUser, - [Parameter(Mandatory=$true)][string]$GitHubEmail, - [Parameter(Mandatory=$true)][string]$GitHubPassword, - [Parameter(Mandatory=$true)][string]$VersionFileUrl, - [string[]]$DirPropsVersionElements = 'CoreClrExpectedPrerelease', - [string]$GitHubUpstreamOwner='dotnet', - [string]$GitHubOriginOwner=$GitHubUser, - [string]$GitHubProject='coreclr', - [string]$GitHubUpstreamBranch='master', - # a semi-colon delimited list of GitHub users to notify on the PR - [string]$GitHubPullRequestNotifications='') - -$LatestVersion = Invoke-WebRequest $VersionFileUrl -UseBasicParsing -$LatestVersion = $LatestVersion.ToString().Trim() - -if ($DirPropsVersionElements -contains 'CoreClrExpectedPrerelease') -{ - # Also get list of all package versions, relative to the given prerelease version url. - $LatestPackagesListUrl = $VersionFileUrl -Replace 'Latest.txt', 'Latest_Packages.txt' - $LatestPackagesList = Invoke-WebRequest $LatestPackagesListUrl -UseBasicParsing - $LatestCoreCLRPackage = $LatestPackagesList -split "`n" | ?{ $_.StartsWith('Microsoft.NETCore.Runtime.CoreCLR') } - $LatestCoreCLRVersion = ($LatestCoreCLRPackage -split ' ')[1].Trim() -} - - -# Make a nicely formatted string of the dir props version elements. Short names, joined by commas. -$DirPropsVersionNames = ($DirPropsVersionElements | %{ $_ -replace 'ExpectedPrerelease', '' }) -join ', ' - -# Updates the dir.props file with the latest build number -function UpdateValidDependencyVersionsFile -{ - if (!$LatestVersion) - { - Write-Error "Unable to find latest dependency version at $VersionFileUrl ($DirPropsVersionNames)" - return $false - } - - $DirPropsPaths = @("$PSScriptRoot\dir.props", "$PSScriptRoot\tests\dir.props") - - $DirPropsPaths | %{ - $DirPropsContent = Get-Content $_ | %{ - $line = $_ - - $DirPropsVersionElements | %{ - $line = $line -replace ` - "<$_>.*", ` - "<$_>$LatestVersion" - } - - if ($LatestCoreCLRVersion) - { - $line = $line -replace ` - ".*<", ` - "$LatestCoreCLRVersion<" - } - - $line - } - Set-Content $_ $DirPropsContent - } - - return $true -} - -# Updates all the project.json files with out of date version numbers -function RunUpdatePackageDependencyVersions -{ - cmd /c $PSScriptRoot\build-test.cmd updateinvalidpackages | Out-Host - - return $LASTEXITCODE -eq 0 -} - -# Creates a Pull Request for the updated version numbers -function CreatePullRequest -{ - $GitStatus = git status --porcelain - if ([string]::IsNullOrWhiteSpace($GitStatus)) - { - Write-Warning "Dependencies are currently up to date" - return $true - } - - $CommitMessage = "Updating $DirPropsVersionNames dependencies to $LatestVersion" - - $env:GIT_COMMITTER_NAME = $GitHubUser - $env:GIT_COMMITTER_EMAIL = $GitHubEmail - git commit -a -m "$CommitMessage" --author "$GitHubUser <$GitHubEmail>" | Out-Host - - $RemoteUrl = "github.com/$GitHubOriginOwner/$GitHubProject.git" - $RemoteBranchName = "UpdateDependencies$([DateTime]::UtcNow.ToString('yyyyMMddhhmmss'))" - $RefSpec = "HEAD:refs/heads/$RemoteBranchName" - - Write-Host "git push https://$RemoteUrl $RefSpec" - # pipe this to null so the password secret isn't in the logs - git push "https://$($GitHubUser):$GitHubPassword@$RemoteUrl" $RefSpec 2>&1 | Out-Null - - if ($GitHubPullRequestNotifications) - { - $PRNotifications = $GitHubPullRequestNotifications.Split(';', [StringSplitOptions]::RemoveEmptyEntries) -join ' @' - $PRBody = "/cc @$PRNotifications" - } - else - { - $PRBody = '' - } - - $CreatePRBody = @" - { - "title": "$CommitMessage", - "body": "$PRBody", - "head": "$($GitHubOriginOwner):$RemoteBranchName", - "base": "$GitHubUpstreamBranch" - } -"@ - - $CreatePRHeaders = @{'Accept'='application/vnd.github.v3+json'; 'Authorization'="token $GitHubPassword"} - - try - { - Invoke-WebRequest https://api.github.com/repos/$GitHubUpstreamOwner/$GitHubProject/pulls -UseBasicParsing -Method Post -Body $CreatePRBody -Headers $CreatePRHeaders - } - catch - { - Write-Error $_.ToString() - return $false - } - - return $true -} - -if (!(UpdateValidDependencyVersionsFile)) -{ - Exit -1 -} - -if (!(RunUpdatePackageDependencyVersions)) -{ - Exit -1 -} - -if (!(CreatePullRequest)) -{ - Exit -1 -} - -Write-Host -ForegroundColor Green "Successfully updated dependencies from the latest build numbers" - -exit $LastExitCode diff --git a/UpdatePublishedVersions.ps1 b/UpdatePublishedVersions.ps1 index 5de7c17bfbe1..4c9bd85966a0 100644 --- a/UpdatePublishedVersions.ps1 +++ b/UpdatePublishedVersions.ps1 @@ -14,131 +14,13 @@ param( [Parameter(Mandatory=$true)][string]$versionsRepo, [Parameter(Mandatory=$true)][string]$versionsRepoPath, # A pattern matching all packages in the set that the versions repository should be set to. - [Parameter(Mandatory=$true)][string]$nupkgPath, - # Print out the new file contents, but don't change the versions repository. - [switch]$dryRun) - -function ConvertPathTo-Package([string]$path) -{ - # Find the package ID and version using a regex. This matches the semantic version - # and assumes everything to the left is the id or a path to the package directory. - $matched = $path -match '^(.*\\)?(.*?)\.(([0-9]+\.)?[0-9]+\.[0-9]+(-([A-z0-9-]+))?)\.(symbols\.)?nupkg$' - if ($matched) - { - $packageInfo = @{ - Path = $path - Name = $matches[2] - Version = $matches[3] - Prerelease = $matches[6] - } - $packageInfo.NameVersion = "$($packageInfo.Name) $($packageInfo.Version)" - return $packageInfo - } - else - { - throw "Couldn't find name and version from path $path." - } -} - -# Updates a GitHub file with the specified file contents -function Update-GitHub-File( - [string]$user = $gitHubUser, - [string]$email = $gitHubEmail, - [string]$authToken = $gitHubAuthToken, - [string]$owner = $versionsRepoOwner, - [string]$repo = $versionsRepo, - [string]$path, - [string]$newFileContent, - [string]$commitMessage) -{ - function message([string]$message) - { - Write-Host -ForegroundColor Green "*** $message ***" - } - - $headers = @{ - 'Accept' = 'application/vnd.github.v3+json' - 'Authorization' = "token $authToken" - } - - $fileUrl = "https://api.github.com/repos/$owner/$repo/contents/$path" - - message "Getting the `"sha`" of the current contents of file '$owner/$repo/$path'" - - $currentFile = Invoke-WebRequest $fileUrl -UseBasicParsing -Headers $headers - $currentSha = (ConvertFrom-Json $currentFile.Content).sha - - message "Got `"sha`" value of '$currentSha'" - - message "Request to update file '$owner/$repo/$path' contents to:" - Write-Host $newFileContent - - if ($dryRun) - { - message 'Not sending request: dry run.' - return - } - - # Base64 encode the string - function ToBase64([string]$value) - { - return [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($value)) - } - - $updateFileBody = -@" -{ - "message": "$commitMessage", - "committer": { - "name": "$user", - "email": "$email" - }, - "content": "$(ToBase64 $newFileContent)", - "sha": "$currentSha" -} -"@ - - message 'Sending request...' - $putResponse = Invoke-WebRequest $fileUrl -UseBasicParsing -Method PUT -Body $updateFileBody -Headers $headers - - if ($putResponse.StatusCode -ge 200 -and $putResponse.StatusCode -lt 300) - { - message 'Successfully updated the file' - } -} - -# Store result of Get-ChildItem before piping to ConvertPathTo-Package. When directly piping, exceptions are ignored. -$packagePaths = Get-ChildItem $nupkgPath -$packages = $packagePaths | %{ ConvertPathTo-Package $_ } - -$prereleaseVersion = '' -foreach ($package in $packages) -{ - if ($package.Prerelease) - { - $prereleaseVersion = $package.Prerelease - break - } -} - -if (!$prereleaseVersion) -{ - throw "Could not find a Prerelease version in '$newPackages'" -} - -$versionFilePath = "$versionsRepoPath/Latest.txt" -$versionFileContent = "$prereleaseVersion`n" - -Update-GitHub-File ` - -path $versionFilePath ` - -newFileContent $versionFileContent ` - -commitMessage "Update '$versionFilePath' with $prereleaseVersion" - -$packageInfoFilePath = "$versionsRepoPath/Latest_Packages.txt" -$packageInfoFileContent = ($packages | %{ $_.NameVersion } | Sort-Object) -join "`r`n" - -Update-GitHub-File ` - -path $packageInfoFilePath ` - -newFileContent $packageInfoFileContent ` - -commitMessage "Adding package info to '$packageInfoFilePath' for $prereleaseVersion" - \ No newline at end of file + [Parameter(Mandatory=$true)][string]$nupkgPath) + +& "$PSScriptRoot\run.cmd" build -- tests\build.proj /t:UpdatePublishedVersions ` + /p:GitHubUser="$gitHubUser" ` + /p:GitHubEmail="$gitHubEmail" ` + /p:GitHubAuthToken="$gitHubAuthToken" ` + /p:VersionsRepoOwner="$versionsRepoOwner" ` + /p:VersionsRepo="$versionsRepo" ` + /p:VersionsRepoPath="$versionsRepoPath" ` + /p:ShippedNuGetPackageGlobPath="$nupkgPath" diff --git a/dependencies.props b/dependencies.props new file mode 100644 index 000000000000..5464e95ccda7 --- /dev/null +++ b/dependencies.props @@ -0,0 +1,94 @@ + + + + afe7fab6bb2a2cd82d381eab880d290b23ed5214 + 5adc811e2d62ae1543bc3e88748476d088532d2a + 039e8532657c2599e2f8baf2c3dcd95265f28645 + + + + + beta-24328-05 + beta-24417-00 + + + + + 1.0.4-beta-24325-02 + 2.1.0 + + + + + build-info/dotnet/ + master + $(MSBuildThisFileFullPath) + + + + + $(BaseDotNetBuildInfo)corefx/$(DependencyBranch) + $(CoreFxCurrentRef) + + + $(BaseDotNetBuildInfo)coreclr/$(DependencyBranch) + $(CoreClrCurrentRef) + + + $(BaseDotNetBuildInfo)projectk-tfs/$(DependencyBranch) + $(ExternalCurrentRef) + + + + https://raw.githubusercontent.com/dotnet/versions + + + + $(MSBuildThisFileFullPath) + CoreFxExpectedPrerelease + CoreFx + + + $(MSBuildThisFileFullPath) + CoreClrPackageVersion + Microsoft.NETCore.Runtime.CoreCLR + + + $(MSBuildThisFileFullPath) + ExternalExpectedPrerelease + External + + + + + + + + + + + + + $(XunitPackageVersion) + + + + + + + + + + 1.0.0-alpha-build0035 + + + + 1.0.2-prerelease-00101 + + + + %(Identity) + true + + + diff --git a/dir.props b/dir.props index 7f164fd1605e..e5cac55a8f46 100644 --- a/dir.props +++ b/dir.props @@ -134,6 +134,9 @@ + + + beta @@ -149,9 +152,6 @@ https://dot.net - - beta-24417-00 - diff --git a/tests/build.proj b/tests/build.proj index 70029f19e310..6d5e456dbbc2 100644 --- a/tests/build.proj +++ b/tests/build.proj @@ -2,6 +2,8 @@ + + @@ -12,13 +14,12 @@ - ValidateAllProjectDependencies; BatchRestorePackages; $(TraversalBuildDependsOn); - + @@ -31,20 +32,6 @@ - - - - - - - - diff --git a/tests/dir.props b/tests/dir.props index 178c9fab5880..8d7c8b82a6c7 100644 --- a/tests/dir.props +++ b/tests/dir.props @@ -21,11 +21,6 @@ true - - - 2.1.0 - - false @@ -38,35 +33,8 @@ true - - - true - true - - beta-24328-05 - 1.0.4-beta-24325-02 - - ^(?i)((System\..*)|(Microsoft\.CSharp)|(Microsoft\.NETCore.*)|(Microsoft\.Win32\..*)|(Microsoft\.VisualBasic))(?<!TestData)$ - - - - - $(CoreFxVersionsIdentityRegex) - $(CoreFxExpectedPrerelease) - - - ^(?i)(xunit(\.assert|\.core|\.runner\.(utility|msbuild))?)$ - $(XunitPackageVersion) - - - ^(?i)(xunit\.console\.netcore)$ - 1.0.2-prerelease-00101 - - - ^(?i)Microsoft\.DotNet\.xunit\.performance.*$ - 1.0.0-alpha-build0035 - - + +