Skip to content
47 changes: 44 additions & 3 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,30 @@ class PackageProps {
# Returns important properties of the package relative to the language repo
# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
# Note: python is required for parsing python package properties.
# GroupId is optional and is used to filter packages for languages that support group identifiers (e.g., Java).
# When GroupId is provided, the function will match both the package name and the group ID.
function Get-PkgProperties {
Param
(
[Parameter(Mandatory = $true)]
[string]$PackageName,
[string]$ServiceDirectory
[string]$ServiceDirectory,
[string]$GroupId
)

Write-Host "Get-PkgProperties called with PackageName: [$PackageName], ServiceDirectory: [$ServiceDirectory], GroupId: [$GroupId]"

$allPkgProps = Get-AllPkgProperties -ServiceDirectory $ServiceDirectory
$pkgProps = $allPkgProps.Where({ $_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName });

if ([string]::IsNullOrEmpty($GroupId)) {
$pkgProps = $allPkgProps.Where({ $_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName });
}
else {
$pkgProps = $allPkgProps.Where({
($_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName) -and
($_.PSObject.Properties.Name -contains "Group" -and $_.Group -eq $GroupId)
});
}

if ($pkgProps.Count -ge 1) {
if ($pkgProps.Count -gt 1) {
Expand All @@ -237,7 +251,12 @@ function Get-PkgProperties {
return $pkgProps[0]
}

LogError "Failed to retrieve Properties for [$PackageName]"
if ([string]::IsNullOrEmpty($GroupId)) {
LogError "Failed to retrieve Properties for [$PackageName]"
}
else {
LogError "Failed to retrieve Properties for [$PackageName] with GroupId [$GroupId]. Ensure the package has a Group property matching the specified GroupId."
}
return $null
}

Expand Down Expand Up @@ -557,3 +576,25 @@ function Get-PkgPropsForEntireService ($serviceDirectoryPath) {

return $projectProps
}

# Get the full package name based on packageInfo properties
# Returns Group+ArtifactName if Group exists and has a value, otherwise returns Name
# If UseColonSeparator switch is enabled, returns Group:ArtifactName format (colon separator)
function Get-FullPackageName {
param (
[Parameter(Mandatory=$true)]
[PSCustomObject]$PackageInfo,
[switch]$UseColonSeparator
)

if ($PackageInfo.PSObject.Members.Name -contains "Group") {
$groupId = $PackageInfo.Group
if ($groupId) {
if ($UseColonSeparator) {
return "${groupId}:$($PackageInfo.Name)"
}
return "${groupId}+$($PackageInfo.Name)"
}
}
return $PackageInfo.Name
}
31 changes: 25 additions & 6 deletions eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ If one isn't provided, then it will compute the next ship date or today's date i
.PARAMETER ReleaseTrackingOnly
Optional: If this switch is passed then the script will only update the release work items and not update the versions in the local repo or validate the changelog.

.PARAMETER GroupId
Optional: The group ID for the package. For Java packages, if not provided, the script will prompt for input with 'com.azure' as the default.

.EXAMPLE
PS> ./eng/common/scripts/Prepare-Release.ps1 <PackageName>

Expand All @@ -49,14 +52,27 @@ param(
[string]$PackageName,
[string]$ServiceDirectory,
[string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy"
[switch]$ReleaseTrackingOnly = $false
[switch]$ReleaseTrackingOnly = $false,
[string]$GroupId
)
Set-StrictMode -Version 3

. ${PSScriptRoot}\common.ps1
. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1
. ${PSScriptRoot}\Helpers\DevOps-WorkItem-Helpers.ps1

# Prompt for GroupId if language is Java and GroupId is not provided
if ($Language -eq 'java' -and [string]::IsNullOrEmpty($GroupId)) {
$userInput = Read-Host "Input the group id, or press Enter to use 'com.azure' as the group id"
if ([string]::IsNullOrWhiteSpace($userInput)) {
$GroupId = "com.azure"
}
else {
$GroupId = $userInput.Trim()
}
Write-Host "Using GroupId: $GroupId" -ForegroundColor Green
}

function Get-ReleaseDay($baseDate)
{
# Find first friday
Expand All @@ -74,7 +90,7 @@ function Get-ReleaseDay($baseDate)
$ErrorPreference = 'Stop'

$packageProperties = $null
$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory -GroupId $GroupId

if (!$packageProperties)
{
Expand Down Expand Up @@ -128,7 +144,7 @@ if (Test-Path "Function:GetExistingPackageVersions")
}

$currentProjectVersion = $packageProperties.Version
$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use use current project version '$currentProjectVersion'"
$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use current project version '$currentProjectVersion'"

if (!$newVersion)
{
Expand All @@ -142,8 +158,10 @@ if ($null -eq $newVersionParsed)
exit 1
}

$fullPackageName = Get-FullPackageName -PackageInfo $packageProperties

$result = Update-DevOpsReleaseWorkItem -language $LanguageDisplayName `
-packageName $packageProperties.Name `
-packageName $fullPackageName `
-version $newVersion `
-plannedDate $releaseDateString `
-packageRepoPath $packageProperties.serviceDirectory `
Expand All @@ -166,7 +184,8 @@ try
}
$url = az keyvault secret show --name "APIURL" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv"
$apiKey = az keyvault secret show --name "APIKEY" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv"
Check-ApiReviewStatus -PackageName $packageProperties.Name -packageVersion $newVersion -Language $LanguageDisplayName -url $url -apiKey $apiKey
$fullPackageNameInApiView = Get-FullPackageName -PackageInfo $packageProperties -UseColonSeparator
Check-ApiReviewStatus -PackageName $fullPackageNameInApiView -packageVersion $newVersion -Language $LanguageDisplayName -url $url -apiKey $apiKey
}
catch
{
Expand Down Expand Up @@ -194,7 +213,7 @@ if (Test-Path "Function:SetPackageVersion")
}
SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion `
-ServiceDirectory $packageProperties.ServiceDirectory -ReleaseDate $releaseDateString `
-PackageProperties $packageProperties -ReplaceLatestEntryTitle $replaceLatestEntryTitle
-PackageProperties $packageProperties -ReplaceLatestEntryTitle $replaceLatestEntryTitle -GroupId $packageProperties.Group
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Version : Version to add or replace in change log
# Unreleased: Default is true. If it is set to false, then today's date will be set in verion title. If it is True then title will show "Unreleased"
# ReplaceLatestEntryTitle: Replaces the latest changelog entry title.
# GroupId: Optional. The group ID for the package. Used for filtering packages in languages that support group identifiers (e.g., Java).

[CmdletBinding()]
param (
Expand All @@ -14,7 +15,8 @@ param (
[Boolean]$Unreleased = $true,
[Boolean]$ReplaceLatestEntryTitle = $false,
[String]$ChangelogPath,
[String]$ReleaseDate
[String]$ReleaseDate,
[String]$GroupId
)
Set-StrictMode -Version 3

Expand Down Expand Up @@ -59,7 +61,7 @@ if ($null -eq [AzureEngSemanticVersion]::ParseVersionString($Version))

if ([string]::IsNullOrEmpty($ChangelogPath))
{
$pkgProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
$pkgProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory -GroupId $GroupId
$ChangelogPath = $pkgProperties.ChangeLogPath
}

Expand Down
26 changes: 13 additions & 13 deletions eng/common/scripts/Validate-All-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function IsVersionShipped($packageName, $packageVersion)
function CreateUpdatePackageWorkItem($pkgInfo)
{
# This function will create or update package work item in Azure DevOps
$fullPkgNameInRemoteFeed = Get-FullPackageName -PackageInfo $pkgInfo
$versionString = $pkgInfo.Version
$packageName = $pkgInfo.Name
$plannedDate = $pkgInfo.ReleaseStatus
$setReleaseState = $true
if (!$plannedDate -or $plannedDate -eq "Unreleased")
Expand All @@ -147,7 +147,7 @@ function CreateUpdatePackageWorkItem($pkgInfo)

# Create or update package work item
$result = Update-DevOpsReleaseWorkItem -language $LanguageDisplayName `
-packageName $packageName `
-packageName $fullPkgNameInRemoteFeed `
-version $versionString `
-plannedDate $plannedDate `
-packageRepoPath $pkgInfo.serviceDirectory `
Expand Down Expand Up @@ -175,13 +175,17 @@ function ProcessPackage($packageInfo)
$changeLogPath = $packageInfo.ChangeLogPath
$versionString = $packageInfo.Version
Write-Host "Checking if we need to create or update work item for package $pkgName with version $versionString."
$isShipped = IsVersionShipped $pkgName $versionString

# If there's a groupId that means this is Java and pkgName = GroupId+ArtifactName
Write-Host "Package name before checking groupId: $pkgName"
$fullPkgNameInRemoteFeed = Get-FullPackageName -PackageInfo $packageInfo
$isShipped = IsVersionShipped $fullPkgNameInRemoteFeed $versionString
if ($isShipped) {
Write-Host "Package work item already exists for version [$versionString] that is marked as shipped. Skipping the update of package work item."
return
}

Write-Host "Validating package $pkgName with version $versionString."
Write-Host "Validating package $fullPkgNameInRemoteFeed with version $versionString."

# Change log validation
$changeLogStatus = [PSCustomObject]@{
Expand All @@ -196,19 +200,14 @@ function ProcessPackage($packageInfo)

# If there's a groupId that means this is Java and pkgName = GroupId+ArtifactName
# but the VerifyAPIReview requires GroupId:ArtifactName
Write-Host "Package name before checking groupId: $fullPackageName"
if ($packageInfo.PSObject.Members.Name -contains "Group") {
$groupId = $packageInfo.Group
if ($groupId){
$fullPackageName = "${groupId}:$($packageInfo.ArtifactName)"
}
}

# Technically we can use groupId+artifactName format in api view,
# however it will need to migrate the existing data and Java parser also needs the change.
$fullPackageName = Get-FullPackageName -PackageInfo $packageInfo -UseColonSeparator
Write-Host "Checking API review status for package $fullPackageName"
$apireviewDetails = VerifyAPIReview $fullPackageName $packageInfo.Version $Language

$pkgValidationDetails= [PSCustomObject]@{
Name = $pkgName
Name = $fullPkgNameInRemoteFeed
Version = $packageInfo.Version
ChangeLogValidation = $changeLogStatus
APIReviewValidation = $apireviewDetails.ApiviewApproval
Expand All @@ -219,6 +218,7 @@ function ProcessPackage($packageInfo)
Write-Host "Output: $($output)"

# Create json token file in artifact path
# Does the following validation file name also need to use full package name with groupId?
$tokenFile = Join-Path $ArtifactPath "$($packageInfo.ArtifactName)-Validation.json"
$output | Out-File -FilePath $tokenFile -Encoding utf8

Expand Down