-
Notifications
You must be signed in to change notification settings - Fork 313
Sync eng/common directory with azure-sdk-tools for PR 12410 #3144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,56 +3,132 @@ | |
param ( | ||
[Parameter(mandatory = $true)] | ||
[string]$BuildID, | ||
[Parameter(mandatory = $true)] | ||
[string]$PackageNames, | ||
[Parameter(mandatory = $false)] | ||
[string]$PackageNames = "", | ||
[Parameter(mandatory = $true)] | ||
[string]$ServiceDirectory, | ||
[Parameter(mandatory = $false)] | ||
[string]$TagSeparator = "_" | ||
[string]$TagSeparator = "_", | ||
[Parameter(mandatory = $false)] | ||
[string]$ArtifactsJson = "" | ||
) | ||
|
||
. (Join-Path $PSScriptRoot common.ps1) | ||
|
||
Write-Host "PackageNames: $PackageNames" | ||
Write-Host "ServiceDirectory: $ServiceDirectory" | ||
Write-Host "BuildID: $BuildID" | ||
Write-Host "ArtifactsJson: $ArtifactsJson" | ||
|
||
$packageNamesArray = @() | ||
$artifacts = $null | ||
|
||
if ([String]::IsNullOrWhiteSpace($PackageNames)) { | ||
LogError "PackageNames cannot be empty." | ||
exit 1 | ||
# If ArtifactsJson is provided, extract package names from it | ||
if (![String]::IsNullOrWhiteSpace($ArtifactsJson)) { | ||
Write-Host "Using ArtifactsJson to determine package names" | ||
try { | ||
$artifacts = $ArtifactsJson | ConvertFrom-Json | ||
$packageNamesArray = $artifacts | ForEach-Object { $_.name } | ||
Write-Host "Extracted package names from ArtifactsJson: $($packageNamesArray -join ', ')" | ||
} | ||
catch { | ||
LogError "Failed to parse ArtifactsJson: $($_.Exception.Message)" | ||
exit 1 | ||
} | ||
} | ||
else { | ||
elseif (![String]::IsNullOrWhiteSpace($PackageNames)) { | ||
$packageNamesArray = $PackageNames.Split(',') | ||
} | ||
else { | ||
LogError "Either PackageNames or ArtifactsJson must be provided." | ||
exit 1 | ||
} | ||
|
||
foreach ($packageName in $packageNamesArray) { | ||
Write-Host "Processing $packageName" | ||
$newVersion = [AzureEngSemanticVersion]::new("1.0.0") | ||
$prefix = "$packageName$TagSeparator" | ||
Write-Host "Get Latest Tag : git tag -l $prefix*" | ||
$latestTags = git tag -l "$prefix*" | ||
if ($artifacts) { | ||
# When using ArtifactsJson, process each artifact with its name and groupId (if applicable) | ||
try { | ||
foreach ($artifact in $artifacts) { | ||
$packageName = $artifact.name | ||
$newVersion = [AzureEngSemanticVersion]::new("1.0.0") | ||
$prefix = "$packageName$TagSeparator" | ||
Comment on lines
+47
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The version/tag resolution logic (initializing newVersion, computing prefix, fetching tags, sorting, setting prerelease fields, and calling SetPackageVersion) is duplicated between the artifacts branch and the fallback loop; this increases maintenance overhead and risk of divergence. Extract the shared logic into a helper function (e.g., Resolve-And-SetPackageVersion -PackageName [-GroupId]) and invoke it from both branches. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
$semVars = @() | ||
if ($Language -eq "java") { | ||
$groupId = $artifact.groupId | ||
Write-Host "Processing $packageName with groupId $groupId" | ||
if ([String]::IsNullOrWhiteSpace($groupId)) { | ||
LogError "GroupId is missing for package $packageName." | ||
exit 1 | ||
} | ||
# Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_") | ||
$prefix = "$groupId+$packageName$TagSeparator" | ||
} | ||
|
||
if ($latestTags -and ($latestTags.Length -gt 0)) { | ||
foreach ($tag in $latestTags) { | ||
$semVars += $tag.Substring($prefix.Length) | ||
} | ||
Write-Host "Get Latest Tag : git tag -l $prefix*" | ||
$latestTags = git tag -l "$prefix*" | ||
|
||
$semVars = @() | ||
|
||
$semVarsSorted = [AzureEngSemanticVersion]::SortVersionStrings($semVars) | ||
Write-Host "Last Published Version $($semVarsSorted[0])" | ||
$newVersion = [AzureEngSemanticVersion]::new($semVarsSorted[0]) | ||
if ($latestTags -and ($latestTags.Length -gt 0)) { | ||
foreach ($tag in $latestTags) { | ||
$semVars += $tag.Substring($prefix.Length) | ||
} | ||
Comment on lines
+66
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When git returns a single matching tag, $latestTags is a [string]; iterating it with foreach enumerates characters, producing incorrect substrings. Wrap the command in an array cast to normalize: $latestTags = @(git tag -l "$prefix*") and iterate over @($latestTags) to ensure tag-level enumeration. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
$semVarsSorted = [AzureEngSemanticVersion]::SortVersionStrings($semVars) | ||
Write-Host "Last Published Version $($semVarsSorted[0])" | ||
$newVersion = [AzureEngSemanticVersion]::new($semVarsSorted[0]) | ||
} | ||
|
||
$newVersion.PrereleaseLabel = $newVersion.DefaultPrereleaseLabel | ||
$newVersion.PrereleaseNumber = $BuildID | ||
$newVersion.IsPrerelease = $True | ||
|
||
Write-Host "Version to publish [ $($newVersion.ToString()) ]" | ||
|
||
if ($Language -ne "java") { | ||
SetPackageVersion -PackageName $packageName ` | ||
-Version $newVersion.ToString() ` | ||
-ServiceDirectory $ServiceDirectory | ||
} else { | ||
SetPackageVersion -PackageName $packageName ` | ||
-Version $newVersion.ToString() ` | ||
-ServiceDirectory $ServiceDirectory ` | ||
-GroupId $groupId | ||
} | ||
} | ||
} | ||
catch { | ||
LogError "Failed to process ArtifactsJson: $ArtifactsJson, exception: $($_.Exception.Message)" | ||
exit 1 | ||
} | ||
} else { | ||
# Fallback to original logic when using PackageNames string | ||
foreach ($packageName in $packageNamesArray) { | ||
Write-Host "Processing $packageName" | ||
$newVersion = [AzureEngSemanticVersion]::new("1.0.0") | ||
$prefix = "$packageName$TagSeparator" | ||
Write-Host "Get Latest Tag : git tag -l $prefix*" | ||
$latestTags = git tag -l "$prefix*" | ||
|
||
$newVersion.PrereleaseLabel = $newVersion.DefaultPrereleaseLabel | ||
$newVersion.PrereleaseNumber = $BuildID | ||
$newVersion.IsPrerelease = $True | ||
$semVars = @() | ||
|
||
Write-Host "Version to publish [ $($newVersion.ToString()) ]" | ||
if ($latestTags -and ($latestTags.Length -gt 0)) { | ||
foreach ($tag in $latestTags) { | ||
$semVars += $tag.Substring($prefix.Length) | ||
} | ||
|
||
SetPackageVersion -PackageName $packageName ` | ||
-Version $newVersion.ToString() ` | ||
-ServiceDirectory $ServiceDirectory | ||
$semVarsSorted = [AzureEngSemanticVersion]::SortVersionStrings($semVars) | ||
Write-Host "Last Published Version $($semVarsSorted[0])" | ||
$newVersion = [AzureEngSemanticVersion]::new($semVarsSorted[0]) | ||
} | ||
|
||
$newVersion.PrereleaseLabel = $newVersion.DefaultPrereleaseLabel | ||
$newVersion.PrereleaseNumber = $BuildID | ||
$newVersion.IsPrerelease = $True | ||
|
||
Write-Host "Version to publish [ $($newVersion.ToString()) ]" | ||
|
||
SetPackageVersion -PackageName $packageName ` | ||
-Version $newVersion.ToString() ` | ||
-ServiceDirectory $ServiceDirectory | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter TestPipeline is now declared as a boolean (type: boolean) but the condition compares it to the string 'true'; this can lead to unintended evaluation or brittleness. Change to - ${{ if eq(parameters.TestPipeline, true) }}: or simply - ${{ if parameters.TestPipeline }}: for a proper boolean check.
Copilot uses AI. Check for mistakes.