Skip to content

Commit

Permalink
added a script to generate relaese notes with user input on which cat…
Browse files Browse the repository at this point in the history
…egory each commit is in #2703
  • Loading branch information
corranrogue9 committed Sep 20, 2023
1 parent 10b737e commit 85fb889
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Increment the version number referenced during build in [`Versioning.props`](tools/CustomMSBuild/Versioning.props) by using [semantic versioning](https://semver.org/).
* Update the Public API files by copying the contents of any `PublicAPI.Unshipped.txt` file that has changed since the last release into its corresponding `PublicAPI.Shipped.txt` file.
2. Generate release notes in the [change log](https://github.com/MicrosoftDocs/OData-docs/blob/main/Odata-docs/changelog/odatalib-7x.md) to be published on release of the new version. Then create a pull request with these changes in the [Docs](https://github.com/MicrosoftDocs/OData-docs/) repo and merge it.
* Generate new release notes by referencing the PRs that have been merged into `master` since the last version increment. In GitHub, each commit should have a link to the PR that was merged to generate that commit, so you can use GitHub history to generate the changelog.
* Generate new release notes by referencing the PRs that have been merged into `master` since the last version increment. In GitHub, each commit should have a link to the PR that was merged to generate that commit, so you can use GitHub history to generate the changelog. The release notes can also be generated with some user input by running the script `tools\Release\GenerateReleaseNotes.cmd {last_release_commit_id} {current_release_version_number}`. `{last_release_commit_id}` and `{current_release_version_number}` can be found from the output of `IncrementVersion.cmd`.

### Create the NuGet Packages
3. A [nightly build](https://identitydivision.visualstudio.com/OData/_build?definitionId=1104) was kicked off whenever your version increment PR was merged. Download the build artifacts from the nightly build to your local machine.
Expand Down
25 changes: 15 additions & 10 deletions tools/IncrementVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ($lastReleaseCommit -eq "")
$lastReleaseCommit = git log -n 1 --pretty=format:%H -- $versionPath
}

Write-Host "The last release's commit was $lastReleaseCommit"
Write-Host -ForegroundColor Green "The last release's commit was $lastReleaseCommit"

# use git to find the list of file paths that have been changed since the last commit
$changedFiles = git diff --name-only HEAD $lastReleaseCommit
Expand Down Expand Up @@ -77,29 +77,34 @@ foreach ($propertyGroup in $versions.Project.PropertyGroup)
{
if ($propertyGroup.VersionRelease -ne $null)
{
$versionMajor = [int] $propertyGroup.VersionMajor.'#text'
$versionMinor = [int] $propertyGroup.VersionMinor.'#text'
$versionBuildNumber = [int] $propertyGroup.VersionBuildNumber.'#text'

# if there are api changes or the caller requested a minor version increment
if ($apiChanges -or $forceMinorIncrement)
{
[int] $currentVersion = $propertyGroup.VersionMinor.'#text';
$currentVersion = $currentVersion + 1
Write-Host "Incrementing the VersionMinor in $versionPath to $currentVersion"
$nextVersion = $versionMinor + 1
Write-Host "Because there were API changes, incrementing the VersionMinor in $versionPath to $nextVersion"

$propertyGroup.VersionMinor.'#text' = [string] $currentVersion
$propertyGroup.VersionMinor.'#text' = [string] $nextVersion
$propertyGroup.VersionBuildNumber.'#text' = '0'
}

# if there are not api changes or the caller requested a revision version increment
if ((-not $apiChanges -and $breaks.Length -eq 0) -or $forceRevisionIncrement)
{
[int] $currentVersion = $propertyGroup.VersionBuildNumber.'#text';
$currentVersion = $currentVersion + 1
Write-Host "Incrementing the VersionBuildNumber in $versionPath to $currentVersion"
$nextVersion = $versionBuildNumber + 1
Write-Host "Because there were no API changes, incrementing the VersionBuildNumber in $versionPath to $nextVersion"
Write-Host

$propertyGroup.VersionBuildNumber.'#text' = [string] $currentVersion
$propertyGroup.VersionBuildNumber.'#text' = [string] $nextVersion
}

break;
}
}

$versions.Save($versionPath)
$versions.Save($versionPath)

Write-Host -ForegroundColor Green "The previous version number was '$versionMajor.$versionMinor.$versionBuildNumber'. The new version number is '$($propertyGroup.VersionMajor.'#text').$($propertyGroup.VersionMinor.'#text').$($propertyGroup.VersionBuildNumber.'#text')'"
3 changes: 3 additions & 0 deletions tools/Release/GenerateReleaseNotes.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

powershell.exe -executionpolicy remotesigned -File %~dpn0.ps1 %*
164 changes: 164 additions & 0 deletions tools/Release/GenerateReleaseNotes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<#
.PARAMETER lastReleaseCommitId
The path to the msbuild props file where the version number is specified
#>

Param(
[string]
$lastReleaseCommitId,
[System.Version]
$currentReleaseVersionNumber
)

Write-Host "Retrieving all commits since $lastReleaseCommitId"

$lastReleaseCommit = $lastReleaseCommitId + "..HEAD"
$commits = git log $lastReleaseCommit --pretty=format:%H

function ParseCommitDescription
{
param
(
[string] $commitId
)

$description = git --no-pager log --format=%B -n 1 $commitId
$description = ($description -split "`r`n")[0]

$commitDescription = New-Object PSObject | Select-Object Description, CommitId
$commitDescription.Description = $description
$commitDescription.CommitId = $commitId

return $commitDescription
}

Write-Host "Parsing commit descriptions"

$allChanges = @()
ForEach ($commit in $($commits -split "`r`n"))
{
$allChanges += ParseCommitDescription -CommitId $commit
}

function ParsePrMetadata
{
param
(
[string] $commitDescription
)

$prStart = $commitDescription.LastIndexOf('(')
$prEnd = $commitDescription.LastIndexOf(')')
if ($prStart -eq -1 -or $prEnd -eq -1)
{
return $null
}

$prMetadata = New-Object PSObject | Select-Object PrId, PrDescription
$prMetadata.PrId = $commitDescription.Substring($prStart + 2, $prEnd - $prStart - 2)
$prMetadata.PrDescription = $commitDescription.Substring(0, $prStart)

return $prMetadata
}

Write-Host "Categorizing commits into features, bug fixes, or improvements"
Write-Host

$features = @()
$bugs = @()
$improvements = @()
ForEach ($change in $allChanges)
{
$prMetadata = ParsePrMetadata -CommitDescription $change.Description

Write-Host -NoNewLine "Found a commit with ID $($change.CommitId). "
if ($prMetadata -eq $null)
{
Write-Host -ForegroundColor Yellow "Could not parse a pull request ID from the description '$($change.Description)'"
}
else
{
Write-Host "The PR can be found at https://github.com/OData/odata.net/pull/$($prMetadata.PrId)"
Write-Host "It had a PR description of '$($prMetadata.PrDescription)'."
}

$category = $null
while ($category -eq $null)
{
Write-Host "Is this change a feature, bug fix, or improvement, or should it be ignored? (for 'feature', enter 'feature', 'f', or '1'; for 'bug fix', enter 'bug fix', 'b', '2'; for 'improvement', enter 'improvement', 'i', or '3'; to ignore, enter '4'"
$category = Read-Host
switch ($category)
{
{($_ -eq "feature") -or ($_ -eq "f") -or ($_ -eq "1")} { $features += $prMetadata }
{($_ -eq "bug fix") -or ($_ -eq "b") -or ($_ -eq "2")} { $bugs += $prMetadata }
{($_ -eq "improvement") -or ($_ -eq "i") -or ($_ -eq "3")} { $improvements += $prMetadata }
{($_ -eq "4")} { }
default
{
Write-Host "$category is not a valid category."
$category = $null
Write-Host
}
}
}

Write-Host
}

Write-Host -ForegroundColor Green "The release notes are:"
Write-Host
Write-Host

Write-Host "## ODataLib $currentReleaseVersionNumber"
Write-Host

Write-Host "***Features***"
Write-Host

if ($features.Length -eq 0)
{
Write-Host "N/A"
Write-Host
}
else
{
ForEach ($change in $features)
{
Write-Host "[[#$($change.PrId)]](https://github.com/OData/odata.net/pull/$($change.PrId)) $($change.PrDescription)"
Write-Host
}
}

Write-Host "***Fixed Bugs***"
Write-Host

if ($bugs.Length -eq 0)
{
Write-Host "N/A"
Write-Host
}
else
{
ForEach ($change in $bugs)
{
Write-Host "[[#$($change.PrId)]](https://github.com/OData/odata.net/pull/$($change.PrId)) $($change.PrDescription)"
Write-Host
}
}

Write-Host "***Improvements***"
Write-Host

if ($improvements.Length -eq 0)
{
Write-Host "N/A"
Write-Host
}
else
{
ForEach ($change in $improvements)
{
Write-Host "[[#$($change.PrId)]](https://github.com/OData/odata.net/pull/$($change.PrId)) $($change.PrDescription)"
Write-Host
}
}

0 comments on commit 85fb889

Please sign in to comment.