PatchVersionPrefix.ps1 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env pwsh
  2. <#
  3. .SYNOPSIS
  4. Updates the version.props file in repos to a newer patch version
  5. .PARAMETER Repos
  6. A list of the repositories that should be patched
  7. #>
  8. [CmdletBinding()]
  9. param(
  10. [Parameter(Mandatory = $true)]
  11. [string[]]$Repos,
  12. [switch]$NoCommit
  13. )
  14. $ErrorActionPreference = 'Stop'
  15. Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
  16. function BumpPatch([System.Xml.XmlNode]$node) {
  17. if (-not $node) {
  18. return
  19. }
  20. [version] $version = $node.InnerText
  21. $node.InnerText = "{0}.{1}.{2}" -f $version.Major, $version.Minor, ($version.Build + 1)
  22. return "Bumping version from $version to $($node.InnerText)"
  23. }
  24. foreach ($repo in $Repos) {
  25. $repoPath = "$PSScriptRoot/../modules/$repo"
  26. Push-Location $repoPath
  27. try
  28. {
  29. $path = "$repoPath/version.props"
  30. Write-Host -ForegroundColor Magenta "Updating $repo"
  31. if (-not (Test-Path $path)) {
  32. Write-Warning "$path does not exist"
  33. continue
  34. }
  35. $path = Resolve-Path $path
  36. Write-Verbose "$path"
  37. [xml] $xml = LoadXml $path
  38. $suffix = $xml.SelectSingleNode('/Project/PropertyGroup/VersionSuffix')
  39. if (-not $suffix) {
  40. write-error "$path does not have VersionSuffix"
  41. }
  42. $versionPrefix = $xml.SelectSingleNode('/Project/PropertyGroup/VersionPrefix')
  43. $epxVersionPrefix = $xml.SelectSingleNode('/Project/PropertyGroup/ExperimentalProjectVersionPrefix')
  44. $exVersionPrefix = $xml.SelectSingleNode('/Project/PropertyGroup/ExperimentalVersionPrefix')
  45. BumpPatch $epxVersionPrefix | write-host
  46. BumpPatch $exVersionPrefix | write-host
  47. $message = BumpPatch $versionPrefix
  48. Write-Host $message
  49. SaveXml $xml $path
  50. if (-not $NoCommit) {
  51. Invoke-Block { & git add $path }
  52. Invoke-Block { & git commit -m $message }
  53. }
  54. }
  55. finally
  56. {
  57. Pop-Location
  58. }
  59. }