Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions eng/scripts/Automation-Update-Metadata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Automation-Update-Metadata.ps1
# This script is used to update metadata for the Azure SDK automation process

param(
[Parameter(Mandatory = $true)]
[string]$sdkRepoPath, # Absolute path to the root folder of the local SDK repository.

[Parameter(Mandatory = $true)]
[string]$packagePath # Absolute path to the root folder of the local SDK project.
)

# Step 1: Resolve both paths to absolute paths
try {
$resolvedPackage = Resolve-Path -Path $packagePath -ErrorAction Stop
$fullPackagePath = $resolvedPackage.ProviderPath
} catch {
# If it's not resolvable (e.g., path doesn't exist), fall back to raw input
$fullPackagePath = $packagePath
}

try {
$resolvedRepo = Resolve-Path -Path $sdkRepoPath -ErrorAction Stop
$fullRepoPath = $resolvedRepo.ProviderPath
} catch {
$fullRepoPath = $sdkRepoPath
}

# Step 2: Remove repo root from package path to get relative path
$fullRepoPath = $fullRepoPath.TrimEnd('\', '/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to use some of the existing helpers we have instead of parsing the paths independently. See https://github.com/Azure/azure-sdk-for-net/blob/main/eng/scripts/Language-Settings.ps1#L12 which depends on msbuild properties like https://github.com/Azure/azure-sdk-for-net/blob/main/eng/Directory.Build.Common.targets#L387, we could even call msbuild on the project path to get the service directory if we need it.

if (-not $fullPackagePath.StartsWith($fullRepoPath, [System.StringComparison]::OrdinalIgnoreCase)) {
Write-Error "Package path '$fullPackagePath' does not start with repo path '$fullRepoPath'"
exit 1
}

$relativePath = $fullPackagePath.Substring($fullRepoPath.Length).TrimStart('\', '/')

# Step 3: Split relative path and find 'sdk' segment
$parts = $relativePath -split '[\\/]+'

$sdkIndex = $parts.IndexOf('sdk')
if ($sdkIndex -lt 0 -or $sdkIndex -ge ($parts.Count - 1)) {
Write-Error "The relative path does not contain a valid 'sdk' segment: $relativePath"
exit 1
}

# Extract everything after 'sdk'
$slugParts = $parts[($sdkIndex + 1)..($parts.Count - 1)]
$packagePath = ($slugParts -join '/')

Write-Host "Extracted package path: $packagePath"

# Call Export-API.ps1 script with the package path
$exportApiScript = Join-Path $sdkRepoPath "eng" "scripts" "Export-API.ps1"
Write-Host "Calling Export-API.ps1 with package path: $packagePath"

try {
& $exportApiScript $packagePath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this script looking for the service directory? It is kind of hard to figure out what the parsing code is doing but if it is the service directory then we should update the variable. We should also explicitly list the script parameter name here, so it is clear what we are passing.

Write-Host "Export-API.ps1 completed successfully"
} catch {
Write-Error "Failed to execute Export-API.ps1: $($_.Exception.Message)"
exit 1
}
3 changes: 3 additions & 0 deletions eng/swagger_to_sdk_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"packageFolderFromFileSearch": false,
"buildScript": {
"command": "dotnet build {packagePath}"
},
"updateMetadataScript": {
"path": "pwsh ./eng/scripts/Automation-Update-Metadata.ps1"
}
}
}
Loading