Skip to content

Commit 4cb5637

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 13267 (#2075)
* Updated artifactJson input to artifacts input * Prioritized service directory from artifact object over the parameter input * Returned error when service directory is not provided for the old usage * Removed redudant line * Initilized the variable in a loop --------- Co-authored-by: ray chen <[email protected]>
1 parent 618c3ae commit 4cb5637

File tree

2 files changed

+67
-38
lines changed

2 files changed

+67
-38
lines changed

eng/common/pipelines/templates/steps/set-test-pipeline-version.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ parameters:
1414
- name: TestPipeline
1515
type: boolean
1616
default: false
17-
- name: ArtifactsJson
18-
type: string
19-
default: ''
17+
- name: Artifacts
18+
type: object
19+
default: []
2020

2121
steps:
2222
- ${{ if eq(parameters.TestPipeline, true) }}:
@@ -31,5 +31,5 @@ steps:
3131
-PackageNames '${{ coalesce(parameters.PackageName, parameters.PackageNames) }}'
3232
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
3333
-TagSeparator '${{ parameters.TagSeparator }}'
34-
-ArtifactsJson '${{ parameters.ArtifactsJson }}'
34+
-Artifacts @('${{ replace(convertToJson(parameters.Artifacts), '''', '`''') }}' | ConvertFrom-Json)
3535
pwsh: true

eng/common/scripts/SetTestPipelineVersion.ps1

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,83 @@ param (
55
[string]$BuildID,
66
[Parameter(mandatory = $false)]
77
[string]$PackageNames = "",
8-
[Parameter(mandatory = $true)]
8+
[Parameter(mandatory = $false)]
9+
# ServiceDirectory is required when using PackageNames,
10+
# or when Artifacts do not include their own ServiceDirectory property.
911
[string]$ServiceDirectory,
1012
[Parameter(mandatory = $false)]
1113
[string]$TagSeparator = "_",
1214
[Parameter(mandatory = $false)]
13-
[string]$ArtifactsJson = ""
15+
[object[]]$Artifacts = @()
1416
)
1517

1618
. (Join-Path $PSScriptRoot common.ps1)
1719

20+
# Ensure Artifacts is always an array
21+
$Artifacts = @($Artifacts)
22+
1823
Write-Host "PackageNames: $PackageNames"
1924
Write-Host "ServiceDirectory: $ServiceDirectory"
2025
Write-Host "BuildID: $BuildID"
21-
Write-Host "ArtifactsJson: $ArtifactsJson"
26+
Write-Host "Artifacts count: $($Artifacts.Count)"
2227

23-
$packageNamesArray = @()
24-
$artifacts = $null
25-
26-
# If ArtifactsJson is provided, extract package names from it
27-
if (![String]::IsNullOrWhiteSpace($ArtifactsJson)) {
28-
Write-Host "Using ArtifactsJson to determine package names"
28+
if ($Artifacts -and $Artifacts.Count -gt 0) {
29+
# When using Artifacts, process each artifact with its name and groupId (if applicable)
2930
try {
30-
$artifacts = $ArtifactsJson | ConvertFrom-Json
31-
$packageNamesArray = $artifacts | ForEach-Object { $_.name }
32-
Write-Host "Extracted package names from ArtifactsJson: $($packageNamesArray -join ', ')"
33-
}
34-
catch {
35-
LogError "Failed to parse ArtifactsJson: $($_.Exception.Message)"
36-
exit 1
37-
}
38-
}
39-
elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
40-
$packageNamesArray = $PackageNames.Split(',')
41-
}
42-
else {
43-
LogError "Either PackageNames or ArtifactsJson must be provided."
44-
exit 1
45-
}
31+
foreach ($artifact in $Artifacts) {
32+
# Validate required properties
33+
if (-not (Get-Member -InputObject $artifact -Name 'name' -MemberType Properties)) {
34+
LogError "Artifact is missing required 'name' property."
35+
exit 1
36+
}
4637

47-
if ($artifacts) {
48-
# When using ArtifactsJson, process each artifact with its name and groupId (if applicable)
49-
try {
50-
foreach ($artifact in $artifacts) {
5138
$packageName = $artifact.name
39+
if ([String]::IsNullOrWhiteSpace($packageName)) {
40+
LogError "Artifact 'name' property is null or empty."
41+
exit 1
42+
}
43+
44+
$artifactServiceDirectory = $null
45+
# Check for ServiceDirectory property
46+
if (Get-Member -InputObject $artifact -Name 'ServiceDirectory' -MemberType Properties) {
47+
if (![String]::IsNullOrWhiteSpace($artifact.ServiceDirectory)) {
48+
$artifactServiceDirectory = $artifact.ServiceDirectory
49+
}
50+
}
51+
52+
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
53+
$artifactServiceDirectory = $ServiceDirectory
54+
}
55+
56+
# Validate ServiceDirectory is available
57+
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
58+
LogError "ServiceDirectory is required but not provided for artifact '$packageName'. Provide it via script parameter or artifact property."
59+
exit 1
60+
}
61+
5262
$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
5363
$prefix = "$packageName$TagSeparator"
5464

5565
if ($Language -eq "java") {
66+
# Check for groupId property
67+
if (-not (Get-Member -InputObject $artifact -Name 'groupId' -MemberType Properties)) {
68+
LogError "Artifact '$packageName' is missing required 'groupId' property for Java language."
69+
exit 1
70+
}
71+
5672
$groupId = $artifact.groupId
57-
Write-Host "Processing $packageName with groupId $groupId"
5873
if ([String]::IsNullOrWhiteSpace($groupId)) {
5974
LogError "GroupId is missing for package $packageName."
6075
exit 1
6176
}
77+
78+
Write-Host "Processing $packageName with groupId $groupId"
6279
# Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_")
6380
$prefix = "$groupId+$packageName$TagSeparator"
6481
}
82+
else {
83+
Write-Host "Processing $packageName"
84+
}
6585

6686
Write-Host "Get Latest Tag : git tag -l $prefix*"
6787
$latestTags = git tag -l "$prefix*"
@@ -87,21 +107,27 @@ if ($artifacts) {
87107
if ($Language -ne "java") {
88108
SetPackageVersion -PackageName $packageName `
89109
-Version $newVersion.ToString() `
90-
-ServiceDirectory $ServiceDirectory
110+
-ServiceDirectory $artifactServiceDirectory
91111
} else {
92112
SetPackageVersion -PackageName $packageName `
93113
-Version $newVersion.ToString() `
94-
-ServiceDirectory $ServiceDirectory `
114+
-ServiceDirectory $artifactServiceDirectory `
95115
-GroupId $groupId
96116
}
97117
}
98118
}
99119
catch {
100-
LogError "Failed to process ArtifactsJson: $ArtifactsJson, exception: $($_.Exception.Message)"
120+
LogError "Failed to process Artifacts: exception: $($_.Exception.Message)"
101121
exit 1
102122
}
103-
} else {
123+
} elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
104124
# Fallback to original logic when using PackageNames string
125+
if ([String]::IsNullOrWhiteSpace($ServiceDirectory)) {
126+
LogError "ServiceDirectory is required when using PackageNames."
127+
exit 1
128+
}
129+
130+
$packageNamesArray = $PackageNames.Split(',')
105131
foreach ($packageName in $packageNamesArray) {
106132
Write-Host "Processing $packageName"
107133
$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
@@ -131,4 +157,7 @@ if ($artifacts) {
131157
-Version $newVersion.ToString() `
132158
-ServiceDirectory $ServiceDirectory
133159
}
160+
} else {
161+
LogError "Either PackageNames or Artifacts must be provided."
162+
exit 1
134163
}

0 commit comments

Comments
 (0)