From 49c952a0352a55f54d77159617849796ac156e8e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 8 Dec 2017 00:05:32 -0800 Subject: [PATCH] Update build tools to 2.0.3-rtm-10005 --- build.ps1 | 12 ++++- build.sh | 9 ++++ build/RepositoryBuild.targets | 5 +- build/Templating.targets | 5 +- build/dependencies.props | 2 +- build/repo.props | 2 + build/repo.targets | 7 +++ korebuild-lock.txt | 4 +- korebuild.json | 4 +- scripts/PatchVersionPrefix.ps1 | 66 +++++++++++++++++++++++ scripts/UpdateBuildTools.ps1 | 96 ++++++++++++++++++++++++++++++++++ 11 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 scripts/PatchVersionPrefix.ps1 create mode 100644 scripts/UpdateBuildTools.ps1 diff --git a/build.ps1 b/build.ps1 index b7081bc1c2..9c8dda267e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -23,6 +23,9 @@ The base url where build tools can be downloaded. Overrides the value from the c .PARAMETER Update Updates KoreBuild to the latest version even if a lock file is present. +.PARAMETER Reinstall +Re-installs KoreBuild + .PARAMETER ConfigFile The path to the configuration file that stores values. Defaults to version.props. @@ -57,6 +60,7 @@ param( [string]$ToolsSource, [Alias('u')] [switch]$Update, + [switch]$Reinstall, [string]$ConfigFile = $null, [Parameter(ValueFromRemainingArguments = $true)] [string[]]$MSBuildArgs @@ -84,6 +88,10 @@ function Get-KoreBuild { $version = $version.TrimStart('version:').Trim() $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version) + if ($Reinstall -and (Test-Path $korebuildPath)) { + Remove-Item -Force -Recurse $korebuildPath + } + if (!(Test-Path $korebuildPath)) { Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version" New-Item -ItemType Directory -Path $korebuildPath | Out-Null @@ -103,11 +111,11 @@ function Get-KoreBuild { } } catch { - remove-item -Recurse -Force $korebuildPath -ErrorAction Ignore + Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore throw } finally { - remove-item $tmpfile -ErrorAction Ignore + Remove-Item $tmpfile -ErrorAction Ignore } } diff --git a/build.sh b/build.sh index 14d84a8773..77169b3d91 100755 --- a/build.sh +++ b/build.sh @@ -15,6 +15,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" config_file="$DIR/korebuild.json" verbose=false update=false +reinstall=false repo_path="$DIR" channel='' tools_source='' @@ -36,6 +37,7 @@ __usage() { echo " --path The directory to build. Defaults to the directory containing the script." echo " -s|--tools-source The base url where build tools can be downloaded. Overrides the value from the config file." echo " -u|--update Update to the latest KoreBuild even if the lock file is present." + echo " --reinstall Reinstall KoreBuild." echo "" echo "Description:" echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." @@ -60,6 +62,10 @@ get_korebuild() { version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" + if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then + rm -rf "$korebuild_path" + fi + { if [ ! -d "$korebuild_path" ]; then mkdir -p "$korebuild_path" @@ -164,6 +170,9 @@ while [[ $# -gt 0 ]]; do -u|--update|-Update) update=true ;; + --reinstall|-[Rr]einstall) + reinstall=true + ;; --verbose|-Verbose) verbose=true ;; diff --git a/build/RepositoryBuild.targets b/build/RepositoryBuild.targets index 9c5cd93425..e46c3a157b 100644 --- a/build/RepositoryBuild.targets +++ b/build/RepositoryBuild.targets @@ -43,10 +43,11 @@ $(RepositoryBuildArguments) /p:DotNetRestoreSourcePropsPath=$(GeneratedRestoreSourcesPropsPath) $(RepositoryBuildArguments) /p:DotNetPackageVersionPropsPath=$(GeneratedPackageVersionPropsPath) - $(RepositoryBuildArguments) /p:BuildNumber=$(BuildNumber) /p:Configuration=$(Configuration) + $(RepositoryBuildArguments) /p:BuildNumber=$(BuildNumber) + $(RepositoryBuildArguments) /p:Configuration=$(Configuration) $(RepositoryBuildArguments) /noconsolelogger '/l:RepoTasks.FlowLogger,$(MSBuildThisFileDirectory)tasks\bin\publish\RepoTasks.dll;Summary;FlowId=$(RepositoryToBuild)' - $(_RepositoryBuildTargets) $(RepositoryBuildArguments) + /t:CleanArtifacts $(_RepositoryBuildTargets) $(RepositoryBuildArguments) $(BuildRepositoryRoot)artifacts $(RepositoryArtifactsRoot)\build\ $(RepositoryArtifactsRoot)\msbuild\ diff --git a/build/Templating.targets b/build/Templating.targets index d7592be916..24dc7eef78 100644 --- a/build/Templating.targets +++ b/build/Templating.targets @@ -11,6 +11,7 @@ DotNetRestoreSourcesPropsPath=$(GeneratedRestoreSourcesPropsPath); BuildNumber=$(BuildNumber); Configuration=$(Configuration); + SkipBillOfMaterials=true; $(TemplateProjCommmonProperties); @@ -26,7 +27,7 @@ @@ -55,7 +56,7 @@ diff --git a/build/dependencies.props b/build/dependencies.props index c7caac4ed3..9acba29f63 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -89,7 +89,7 @@ https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json - 2.0.2-rc1-16007 + $(KoreBuildVersion) diff --git a/build/repo.props b/build/repo.props index 180925e696..2e60df02b8 100644 --- a/build/repo.props +++ b/build/repo.props @@ -2,6 +2,8 @@ true + + true diff --git a/build/repo.targets b/build/repo.targets index fdbc47fecd..3ddc0bc4a1 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -106,6 +106,13 @@ + + + + +[CmdletBinding()] +param( + [Parameter(Mandatory = $true)] + [string[]]$Repos, +) + +$ErrorActionPreference = 'Stop' + +function SaveXml($xml, [string]$path) { + Write-Verbose "Saving to $path" + $ErrorActionPreference = 'stop' + + $settings = New-Object System.XML.XmlWriterSettings + $settings.OmitXmlDeclaration = $true + $settings.Encoding = New-Object System.Text.UTF8Encoding( $true ) + $writer = [System.XML.XMLTextWriter]::Create($path, $settings) + $xml.Save($writer) + $writer.Close() +} + +function LoadXml([string]$path) { + Write-Verbose "Reading to $path" + + $ErrorActionPreference = 'stop' + $obj = new-object xml + $obj.PreserveWhitespace = $true + $obj.Load($path) + return $obj +} + +function BumpPatch([System.Xml.XmlNode]$node) { + if (-not $node) { + return + } + [version] $version = $node.InnerText + $node.InnerText = "{0}.{1}.{2}" -f $version.Major, $version.Minor, ($version.Build + 1) +} + +foreach ($repo in $Repos) { + $path = "$PSScriptRoot/../modules/$repo/version.props" + if (-not (Test-Path $path)) { + Write-Warning "$path does not exist" + continue + } + $path = Resolve-Path $path + Write-Verbose "$path" + [xml] $xml = LoadXml $path + + $suffix = $xml.SelectSingleNode('/Project/PropertyGroup/VersionSuffix') + if (-not $suffix) { + write-error "$path does not have VersionSuffix" + } + + $versionPrefix = $xml.SelectSingleNode('/Project/PropertyGroup/VersionPrefix') + $epxVersionPrefix = $xml.SelectSingleNode('/Project/PropertyGroup/ExperimentalProjectVersionPrefix') + BumpPatch $epxVersionPrefix + BumpPatch $versionPrefix + SaveXml $xml $path +} + diff --git a/scripts/UpdateBuildTools.ps1 b/scripts/UpdateBuildTools.ps1 new file mode 100644 index 0000000000..6f2e4ad3c5 --- /dev/null +++ b/scripts/UpdateBuildTools.ps1 @@ -0,0 +1,96 @@ +#!/usr/bin/env pwsh + +<# +.SYNOPSIS + Updates the build tools version and generates a commit message with the list of changes +.PARAMETER RepoRoot + The directory containing the repo +.PARAMETER GitAuthorName + The author name to use in the commit message. (Optional) +.PARAMETER GitAuthorEmail + The author email to use in the commit message. (Optional) +.PARAMETER GitCommitArgs + Additional arguments to pass into git-commit +.PARAMETER NoCommit + Make changes without executing git-commit +.PARAMETER Force + Specified this to make a commit with any changes +#> +[cmdletbinding(SupportsShouldProcess = $true)] +param( + [string]$RepoRoot, + [string]$GitAuthorName = $null, + [string]$GitAuthorEmail = $null, + [string[]]$GitCommitArgs = @(), + [switch]$NoCommit, + [switch]$Force +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2 + +if (-not $RepoRoot) { + $RepoRoot = Resolve-Path "$PSScriptRoot\.." +} + +Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force + +function Get-KoreBuildVersion { + $lockFile = "$RepoRoot/korebuild-lock.txt" + if (!(Test-Path $lockFile)) { + return '' + } + $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1 + if (!$version) { + Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'" + } + $version = $version.TrimStart('version:').Trim() + return $version +} + +Push-Location $RepoRoot +try { + Assert-Git + + $oldVersion = Get-KoreBuildVersion + + # Executes a command that no-ops. The only thing we really need is the updated version of korebuild-lock.txt + & "$RepoRoot/build.ps1" -Update '-t:Noop' | Out-Null + + $newVersion = Get-KoreBuildVersion + + if ($oldVersion -eq $newVersion) { + Write-Host -ForegroundColor Magenta 'No changes to build tools' + exit 0 + } + + Invoke-Block { git add "$RepoRoot/korebuild-lock.txt" } + Invoke-Block { git add "$RepoRoot/build/dependencies.props" } + + $shortMessage = "Updating BuildTools from $oldVersion to $newVersion" + # add this to the commit message to make it possible to filter commit triggers based on message + $message = "$shortMessage`n`n[auto-updated: buildtools]" + + if (-not $NoCommit -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Create a new commit with these changes?')))) { + + $gitConfigArgs = @() + if ($GitAuthorName) { + $gitConfigArgs += '-c', "user.name=$GitAuthorName" + } + + if ($GitAuthorEmail) { + $gitConfigArgs += '-c', "user.email=$GitAuthorEmail" + } + + Invoke-Block { git @gitConfigArgs commit -m $message @GitCommitArgs } + } + else { + # If composing this script with others, return the message that would have been used + return @{ + message = $message + } + } +} +finally { + Pop-Location +}