Sync eng/common directory with azure-sdk-tools repository (#234)

This commit is contained in:
Azure SDK Bot 2020-07-01 22:53:51 -07:00 committed by GitHub
parent e61c3ff51a
commit 1c9b932b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 80 deletions

View File

@ -1,65 +0,0 @@
# given a CHANGELOG.md file, extract the relevant info we need to decorate a release
param (
[Parameter(Mandatory = $true)]
[String]$ChangeLogLocation,
[String]$VersionString
)
$ErrorActionPreference = 'Stop'
$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+.*(?<version>\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?))"
$releaseNotes = @{}
$contentArrays = @{}
if ($ChangeLogLocation.Length -eq 0)
{
return $releaseNotes
}
try
{
$contents = Get-Content $ChangeLogLocation
# walk the document, finding where the version specifiers are and creating lists
$version = ""
foreach($line in $contents){
if ($line -match $RELEASE_TITLE_REGEX)
{
$version = $matches["version"]
$contentArrays[$version] = @()
}
$contentArrays[$version] += $line
}
# resolve each of discovered version specifier string arrays into real content
foreach($key in $contentArrays.Keys)
{
$releaseNotes[$key] = New-Object PSObject -Property @{
ReleaseVersion = $key
ReleaseContent = $contentArrays[$key] -join [Environment]::NewLine
}
}
}
catch
{
Write-Host "Error parsing $ChangeLogLocation."
Write-Host $_.Exception.Message
}
if ([System.String]::IsNullOrEmpty($VersionString))
{
return $releaseNotes
}
else
{
if ($releaseNotes.ContainsKey($VersionString))
{
$releaseNotesForVersion = $releaseNotes[$VersionString].ReleaseContent
$processedNotes = $releaseNotesForVersion -Split [Environment]::NewLine | where { $_ -notmatch $RELEASE_TITLE_REGEX }
return $processedNotes -Join [Environment]::NewLine
}
Write-Error "Release Notes for the Specified version ${VersionString} was not found"
exit 1
}

View File

@ -12,14 +12,14 @@ parameters:
steps:
- task: Powershell@2
inputs:
filePath: /eng/common/scripts/Verify-ChangeLog.ps1
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Verify-ChangeLog.ps1
arguments: >
-PackageName ${{ parameters.PackageName }}
-ServiceName ${{ parameters.ServiceName }}
-RepoRoot $(Build.SourcesDirectory)
-RepoName $(Build.Repository.Name)
-ForRelease ${{ parameters.ForRelease }}
-ForRelease $${{ parameters.ForRelease }}
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Verify ChangeLog / Release Notes
displayName: Verify ChangeLogEntry for ${{ parameters.PackageName }}
continueOnError: false

View File

@ -1,8 +1,8 @@
# Wrapper Script for ChangeLog Verification
param (
[Parameter(Mandatory=$true)]
[String]$ChangeLogLocation,
[String]$VersionString,
[string]$PackageName,
[Parameter(Mandatory=$true)]
[string]$ServiceName,
[string]$RepoRoot,
[ValidateSet("net","java","js","python")]
@ -11,12 +11,21 @@ param (
[boolean]$ForRelease=$False
)
Import-Module "${PSScriptRoot}/modules/common-manifest.psd1"
. (Join-Path $PSScriptRoot SemVer.ps1)
Import-Module (Join-Path $PSScriptRoot modules ChangeLog-Operations.psm1)
if ([System.String]::IsNullOrEmpty($Language))
if ((Test-Path $ChangeLogLocation) -and -not([System.String]::IsNullOrEmpty($VersionString)))
{
$Language = $RepoName.Substring($RepoName.LastIndexOf('-') + 1)
Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease
}
else
{
Import-Module (Join-Path $PSScriptRoot modules Package-Properties.psm1)
if ([System.String]::IsNullOrEmpty($Language))
{
$Language = $RepoName.Substring($RepoName.LastIndexOf('-') + 1)
}
$PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot
Confirm-ChangeLog -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgReadMePath -ForRelease $ForRelease
$PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot
Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgVersion -ForRelease $ForRelease
}

View File

@ -85,9 +85,9 @@ function Confirm-ChangeLogEntry {
[boolean]$ForRelease = $false
)
$changeLogEntries = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
if ([System.String]::IsNullOrEmpty($changeLogEntries.ReleaseStatus)) {
if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) {
Write-Host ("##[error]Changelog '{0}' has wrong release note title" -f $ChangeLogLocation)
Write-Host "##[info]Ensure the release date is included i.e. (yyyy-MM-dd) or (Unreleased) if not yet released"
exit 1
@ -95,19 +95,20 @@ function Confirm-ChangeLogEntry {
if ($ForRelease -eq $True) {
$CurrentDate = Get-Date -Format "yyyy-MM-dd"
if ($changeLogEntries.ReleaseStatus -ne "($CurrentDate)") {
if ($changeLogEntry.ReleaseStatus -ne "($CurrentDate)") {
Write-Host ("##[warning]Incorrect Date: Please use the current date in the Changelog '{0}' before releasing the package" -f $ChangeLogLocation)
exit 1
}
if ([System.String]::IsNullOrWhiteSpace($changeLogEntries.ReleaseContent)) {
if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) {
Write-Host ("##[error]Empty Release Notes for '{0}' in '{1}'" -f $VersionString, $ChangeLogLocation)
Write-Host "##[info]Please ensure there is a release notes entry before releasing the package."
exit 1
}
}
Write-Host ($changeLogEntries | Format-Table | Out-String)
Write-Host $changeLogEntry.ReleaseTitle
Write-Host $changeLogEntry.ReleaseContent
}
Export-ModuleMember -Function 'Get-ChangeLogEntries'