|
| 1 | +<# |
| 2 | +
|
| 3 | +.NOTES |
| 4 | +Copyright (c) Microsoft Corporation. |
| 5 | +Licensed under the MIT License. |
| 6 | +
|
| 7 | +.SYNOPSIS |
| 8 | +Prepares a PR for release |
| 9 | +
|
| 10 | +.DESCRIPTION |
| 11 | +This script is used to do the edits required for preparing a release PR. |
| 12 | +
|
| 13 | +.PARAMETER BaseBranch |
| 14 | +This the branch to use as the base of the release. Defaults to 'main'. |
| 15 | +
|
| 16 | +.PARAMETER TargetBranch |
| 17 | +This is the name of the newly created branch for the release PR. Defaults to '<DATETAG>release'. If set to 'none', then no branch is created. |
| 18 | +
|
| 19 | +.PARAMETER UpdateVersion |
| 20 | +This is a $true or $false value that indicates if the library version number should be incremented. Defaults to $true. |
| 21 | +
|
| 22 | +.LINK |
| 23 | +https://github.com/microsoft/DirectXTex/wiki |
| 24 | +
|
| 25 | +#> |
| 26 | + |
| 27 | +param( |
| 28 | + [string]$BaseBranch = "main", |
| 29 | + [string]$TargetBranch = $null, |
| 30 | + [bool]$UpdateVersion = $true |
| 31 | +) |
| 32 | + |
| 33 | +$reporoot = Split-Path -Path $PSScriptRoot -Parent |
| 34 | +$cmake = $reporoot + "\CMakeLists.txt" |
| 35 | +$header = $reporoot + "\DirectXTex\DirectXTex.h" |
| 36 | +$readme = $reporoot + "\README.md" |
| 37 | +$history = $reporoot + "\CHANGELOG.md" |
| 38 | + |
| 39 | +if ((-Not (Test-Path $cmake)) -Or (-Not (Test-Path $header)) -Or (-Not (Test-Path $readme)) -Or (-Not (Test-Path $history))) { |
| 40 | + Write-Error "ERROR: Unexpected location of script file!" -ErrorAction Stop |
| 41 | +} |
| 42 | + |
| 43 | +$branch = git branch --show-current |
| 44 | +if ($branch -ne $BaseBranch) { |
| 45 | + Write-Error "ERROR: Must be in the $BaseBranch branch!" -ErrorAction Stop |
| 46 | +} |
| 47 | + |
| 48 | +git pull -q |
| 49 | +if ($LastExitCode -ne 0) { |
| 50 | + Write-Error "ERROR: Failed to sync branch!" -ErrorAction Stop |
| 51 | +} |
| 52 | + |
| 53 | +$version = Get-Content ($cmake) | Select-String -Pattern "set\(DIRECTXTEX_VERSION" -CaseSensitive |
| 54 | +if (-Not ($version -match "([0-9]?\.[0-9]?\.[0-9]?)")) { |
| 55 | + Write-Error "ERROR: Failed to current version!" -ErrorAction Stop |
| 56 | +} |
| 57 | +$version = $Matches.0 |
| 58 | +$rawversion = $version.replace('.','') |
| 59 | + |
| 60 | +$newreleasedate = Get-Date -Format "MMMM d, yyyy" |
| 61 | +$newreleasetag = (Get-Date -Format "MMMyyyy").ToLower() |
| 62 | + |
| 63 | +if($UpdateVersion) { |
| 64 | + [string]$newrawversion = ([int]$rawversion + 1) |
| 65 | +} |
| 66 | +else { |
| 67 | + $newrawversion = $rawversion |
| 68 | +} |
| 69 | + |
| 70 | +$newversion = $newrawversion[0] + "." + $newrawversion[1] + "." + $newrawversion[2] |
| 71 | + |
| 72 | +$rawreleasedate = $(Get-Content $readme) | Select-String -Pattern "\*\*[A-Z][a-z]+\S.\d+,?\S.\d\d\d\d\*\*" |
| 73 | +if ([string]::IsNullOrEmpty($rawreleasedate)) { |
| 74 | + Write-Error "ERROR: Failed to current release date!" -ErrorAction Stop |
| 75 | +} |
| 76 | +$releasedate = $rawreleasedate -replace '\*','' |
| 77 | + |
| 78 | +if($releasedate -eq $newreleasedate) { |
| 79 | + Write-Error ("ERROR: Release "+$releasedate+" already exists!") -ErrorAction Stop |
| 80 | +} |
| 81 | + |
| 82 | +if ($TargetBranch -ne 'none') { |
| 83 | + if ([string]::IsNullOrEmpty($TargetBranch)) { |
| 84 | + $TargetBranch = $newreleasetag + "release" |
| 85 | + } |
| 86 | + |
| 87 | + git checkout -b $TargetBranch |
| 88 | + if ($LastExitCode -ne 0) { |
| 89 | + Write-Error "ERROR: Failed to create new topic branch!" -ErrorAction Stop |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +Write-Host " Old Version: " $version |
| 94 | +Write-Host "Old Release Date: " $releasedate |
| 95 | +Write-Host "->" |
| 96 | +Write-Host " Release Date: " $newreleasedate |
| 97 | +Write-Host " Release Tag: " $newreleasetag |
| 98 | +Write-Host " Release Version: " $newversion |
| 99 | + |
| 100 | +if($UpdateVersion) { |
| 101 | + (Get-Content $cmake).Replace("set(DIRECTXTEX_VERSION $version)","set(DIRECTXTEX_VERSION $newversion)") | Set-Content $cmake |
| 102 | + (Get-Content $header).Replace("#define DIRECTX_TEX_VERSION $rawversion","#define DIRECTX_TEX_VERSION $newrawversion") | Set-Content $header |
| 103 | +} |
| 104 | + |
| 105 | +(Get-Content $readme).Replace("$rawreleasedate", "**$newreleasedate**") | Set-Content $readme |
| 106 | + |
| 107 | +Get-ChildItem -Path ($reporoot + "\.nuget") -Filter *.nuspec | Foreach-Object { |
| 108 | + (Get-Content -Path $_.Fullname).Replace("$releasedate", "$newreleasedate") | Set-Content -Path $_.Fullname -Encoding utf8 |
| 109 | + } |
| 110 | + |
| 111 | +[System.Collections.ArrayList]$file = Get-Content $history |
| 112 | +$inserthere = @() |
| 113 | + |
| 114 | +for ($i=0; $i -lt $file.count; $i++) { |
| 115 | + if ($file[$i] -match "## Release History") { |
| 116 | + $inserthere += $i + 1 |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +$file.insert($inserthere[0], "`n### $newreleasedate`n* change history here") |
| 121 | +Set-Content -Path $history -Value $file |
| 122 | + |
| 123 | +code $history $readme |
| 124 | +if ($LastExitCode -ne 0) { |
| 125 | + Write-Error "ERROR: Failed to launch VS Code!" -ErrorAction Stop |
| 126 | +} |
0 commit comments