From fa81b4984acb5242140e8078e4875d42e118c3eb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:33:32 +0000 Subject: [PATCH 1/3] Initial plan From b761c93dc03f01b4679ea9e2fb83bae547154f89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:43:27 +0000 Subject: [PATCH 2/3] Remove Set-Location and Push-Location usage from PowerShell scripts Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com> --- eng/scripts/Language-Settings.ps1 | 50 +++++------- eng/scripts/Pack-Crates.ps1 | 104 +++++++++++------------- eng/scripts/Test-Packages.ps1 | 49 +++++------ eng/scripts/Update-TspClients.ps1 | 15 ++-- sdk/core/azure_core_amqp/Test-Setup.ps1 | 70 +++++++--------- sdk/identity/test-resources-post.ps1 | 9 +- 6 files changed, 133 insertions(+), 164 deletions(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index d085a398fc5..9489f90707b 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -36,38 +36,32 @@ function GetExistingPackageVersions ($PackageName, $GroupId = $null) { function Get-AllPackageInfoFromRepo ([string] $ServiceDirectory) { $allPackageProps = @() - Push-Location $RepoRoot - try { - $searchPath = Join-Path $RepoRoot 'sdk' -Resolve + $searchPath = Join-Path $RepoRoot 'sdk' -Resolve - if ($ServiceDirectory -and $ServiceDirectory -ne 'auto') { - $searchPath = Join-Path $searchPath $ServiceDirectory -Resolve - } + if ($ServiceDirectory -and $ServiceDirectory -ne 'auto') { + $searchPath = Join-Path $searchPath $ServiceDirectory -Resolve + } - # when a package is marked `publish = false` in the Cargo.toml, `cargo metadata` returns an empty array for - # `publish`, otherwise it returns null. We only want to include packages where `publish` is null. - $packages = Invoke-LoggedCommand "cargo metadata --format-version 1 --no-deps" -GroupOutput - | ConvertFrom-Json -AsHashtable - | Select-Object -ExpandProperty packages - | Where-Object { $_.manifest_path.StartsWith($searchPath) -and $null -eq $_.publish } - - $packageManifests = @{} - foreach ($package in $packages) { - if ($package.manifest_path -replace '\\', '/' -match '/sdk/([^/]+)/') { - $package.ServiceDirectoryName = $Matches[1] - } - else { - # ignore manifests that are not in a service directory - continue - } + # when a package is marked `publish = false` in the Cargo.toml, `cargo metadata` returns an empty array for + # `publish`, otherwise it returns null. We only want to include packages where `publish` is null. + $packages = Invoke-LoggedCommand "cargo metadata --manifest-path '$RepoRoot/Cargo.toml' --format-version 1 --no-deps" -GroupOutput + | ConvertFrom-Json -AsHashtable + | Select-Object -ExpandProperty packages + | Where-Object { $_.manifest_path.StartsWith($searchPath) -and $null -eq $_.publish } - $package.DirectoryPath = Split-Path $package.manifest_path -Parent - $package.DependentPackages = @() - $packageManifests[$package.name] = $package + $packageManifests = @{} + foreach ($package in $packages) { + if ($package.manifest_path -replace '\\', '/' -match '/sdk/([^/]+)/') { + $package.ServiceDirectoryName = $Matches[1] } - } - finally { - Pop-Location + else { + # ignore manifests that are not in a service directory + continue + } + + $package.DirectoryPath = Split-Path $package.manifest_path -Parent + $package.DependentPackages = @() + $packageManifests[$package.name] = $package } # Invert the manifest dependency graph diff --git a/eng/scripts/Pack-Crates.ps1 b/eng/scripts/Pack-Crates.ps1 index 72323370a9d..0d1d2216733 100755 --- a/eng/scripts/Pack-Crates.ps1 +++ b/eng/scripts/Pack-Crates.ps1 @@ -95,73 +95,65 @@ function Create-ApiViewFile($package) { "$packagePath/review/$packageName.rust.json" } -$originalLocation = Get-Location -try { - Set-Location $RepoRoot - - [array]$packages = Get-PackagesToBuild - $packageParams = @() - foreach ($package in $packages) { - $packageParams += "--package", $package.name - } +[array]$packages = Get-PackagesToBuild +$packageParams = @("--manifest-path", "$RepoRoot/Cargo.toml") +foreach ($package in $packages) { + $packageParams += "--package", $package.name +} - if ($NoVerify) { - $packageParams += "--no-verify" - } +if ($NoVerify) { + $packageParams += "--no-verify" +} - LogGroupStart "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" - Write-Host "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" - & cargo publish --locked --dry-run --allow-dirty @packageParams 2>&1 ` - | Tee-Object -Variable packResult ` - | ForEach-Object { Write-Host $_ -ForegroundColor Gray } - LogGroupEnd - - Write-Host "Finished packing crates" - if ($LASTEXITCODE) { - Write-Host "cargo publish failed with exit code $LASTEXITCODE" - exit $LASTEXITCODE - } +LogGroupStart "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" +Write-Host "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" +& cargo publish --locked --dry-run --allow-dirty @packageParams 2>&1 ` +| Tee-Object -Variable packResult ` +| ForEach-Object { Write-Host $_ -ForegroundColor Gray } +LogGroupEnd + +Write-Host "Finished packing crates" +if ($LASTEXITCODE) { + Write-Host "cargo publish failed with exit code $LASTEXITCODE" + exit $LASTEXITCODE +} - if ($OutputPath) { - $OutputPath = New-Item -ItemType Directory -Path $OutputPath -Force | Select-Object -ExpandProperty FullName +if ($OutputPath) { + $OutputPath = New-Item -ItemType Directory -Path $OutputPath -Force | Select-Object -ExpandProperty FullName - foreach ($package in $packages) { - $sourcePath = [System.IO.Path]::Combine($RepoRoot, "target", "package", "$($package.name)-$($package.version)") - $targetPath = [System.IO.Path]::Combine($OutputPath, $package.name) - $targetContentsPath = [System.IO.Path]::Combine($targetPath, "contents") - $targetApiReviewFile = [System.IO.Path]::Combine($targetPath, "$($package.name).rust.json") + foreach ($package in $packages) { + $sourcePath = [System.IO.Path]::Combine($RepoRoot, "target", "package", "$($package.name)-$($package.version)") + $targetPath = [System.IO.Path]::Combine($OutputPath, $package.name) + $targetContentsPath = [System.IO.Path]::Combine($targetPath, "contents") + $targetApiReviewFile = [System.IO.Path]::Combine($targetPath, "$($package.name).rust.json") - if (Test-Path -Path $targetContentsPath) { - Remove-Item -Path $targetContentsPath -Recurse -Force - } + if (Test-Path -Path $targetContentsPath) { + Remove-Item -Path $targetContentsPath -Recurse -Force + } - Write-Host "Copying package contents '$($package.name)' to '$targetContentsPath'" - New-Item -ItemType Directory -Path $targetContentsPath -Force | Out-Null - Copy-Item -Path $sourcePath/* -Destination $targetContentsPath -Recurse + Write-Host "Copying package contents '$($package.name)' to '$targetContentsPath'" + New-Item -ItemType Directory -Path $targetContentsPath -Force | Out-Null + Copy-Item -Path $sourcePath/* -Destination $targetContentsPath -Recurse - Write-Host "Copying .crate file for '$($package.name)' to '$targetPath'" - Copy-Item -Path "$sourcePath.crate" -Destination $targetPath -Force + Write-Host "Copying .crate file for '$($package.name)' to '$targetPath'" + Copy-Item -Path "$sourcePath.crate" -Destination $targetPath -Force - Write-Host "Creating API review file" - $apiReviewFile = Create-ApiViewFile $package + Write-Host "Creating API review file" + $apiReviewFile = Create-ApiViewFile $package - Write-Host "Copying API review file to '$targetApiReviewFile'" - Copy-Item -Path $apiReviewFile -Destination $targetApiReviewFile -Force - } + Write-Host "Copying API review file to '$targetApiReviewFile'" + Copy-Item -Path $apiReviewFile -Destination $targetApiReviewFile -Force } +} - if ($OutBuildOrderFile) { - $buildOrder = @() - foreach ($line in $packResult) { - if ($line -match '^\s*Packaging (\w*) ([\w\d\.-]*)') { - $buildOrder += $matches[1] - } +if ($OutBuildOrderFile) { + $buildOrder = @() + foreach ($line in $packResult) { + if ($line -match '^\s*Packaging (\w*) ([\w\d\.-]*)') { + $buildOrder += $matches[1] } - - Write-Host "Build Order: $($buildOrder -join ', ')" - ConvertTo-Json $buildOrder -Depth 100 | Set-Content $OutBuildOrderFile } -} -finally { - Set-Location $originalLocation + + Write-Host "Build Order: $($buildOrder -join ', ')" + ConvertTo-Json $buildOrder -Depth 100 | Set-Content $OutBuildOrderFile } diff --git a/eng/scripts/Test-Packages.ps1 b/eng/scripts/Test-Packages.ps1 index a9515d9f8dd..44bdccdbf66 100755 --- a/eng/scripts/Test-Packages.ps1 +++ b/eng/scripts/Test-Packages.ps1 @@ -40,39 +40,34 @@ foreach ($package in $packagesToTest) { } foreach ($package in $packagesToTest) { - Push-Location ([System.IO.Path]::Combine($RepoRoot, $package.DirectoryPath)) - try { - $packageDirectory = ([System.IO.Path]::Combine($RepoRoot, $package.DirectoryPath)) + $packageDirectory = ([System.IO.Path]::Combine($RepoRoot, $package.DirectoryPath)) + $manifestPath = Join-Path $packageDirectory "Cargo.toml" - $setupScript = Join-Path $packageDirectory "Test-Setup.ps1" - if (Test-Path $setupScript) { - Write-Host "`n`nRunning test setup script for package: '$($package.Name)'`n" - Invoke-LoggedCommand $setupScript -GroupOutput - if (!$? -ne 0) { - Write-Error "Test setup script failed for package: '$($package.Name)'" - exit 1 - } + $setupScript = Join-Path $packageDirectory "Test-Setup.ps1" + if (Test-Path $setupScript) { + Write-Host "`n`nRunning test setup script for package: '$($package.Name)'`n" + Invoke-LoggedCommand $setupScript -GroupOutput + if (!$? -ne 0) { + Write-Error "Test setup script failed for package: '$($package.Name)'" + exit 1 } + } - Write-Host "`n`nTesting package: '$($package.Name)'`n" + Write-Host "`n`nTesting package: '$($package.Name)'`n" - Invoke-LoggedCommand "cargo build --keep-going" -GroupOutput - Write-Host "`n`n" + Invoke-LoggedCommand "cargo build --manifest-path '$manifestPath' --keep-going" -GroupOutput + Write-Host "`n`n" - Invoke-LoggedCommand "cargo test --doc --no-fail-fast" -GroupOutput - Write-Host "`n`n" + Invoke-LoggedCommand "cargo test --manifest-path '$manifestPath' --doc --no-fail-fast" -GroupOutput + Write-Host "`n`n" - Invoke-LoggedCommand "cargo test --all-targets --no-fail-fast" -GroupOutput - Write-Host "`n`n" + Invoke-LoggedCommand "cargo test --manifest-path '$manifestPath' --all-targets --no-fail-fast" -GroupOutput + Write-Host "`n`n" - $cleanupScript = Join-Path $packageDirectory "Test-Cleanup.ps1" - if (Test-Path $cleanupScript) { - Write-Host "`n`nRunning test cleanup script for package: '$($package.Name)'`n" - Invoke-LoggedCommand $cleanupScript -GroupOutput - # We ignore the exit code of the cleanup script. - } - } - finally { - Pop-Location + $cleanupScript = Join-Path $packageDirectory "Test-Cleanup.ps1" + if (Test-Path $cleanupScript) { + Write-Host "`n`nRunning test cleanup script for package: '$($package.Name)'`n" + Invoke-LoggedCommand $cleanupScript -GroupOutput + # We ignore the exit code of the cleanup script. } } diff --git a/eng/scripts/Update-TspClients.ps1 b/eng/scripts/Update-TspClients.ps1 index 6976c04b143..47f6d770840 100755 --- a/eng/scripts/Update-TspClients.ps1 +++ b/eng/scripts/Update-TspClients.ps1 @@ -43,25 +43,22 @@ foreach ($file in $tspFiles) { if ([string]::IsNullOrEmpty($dir)) { $dir = "." } + $fullDir = Join-Path $Path $dir - Write-Host "`nRunning tsp-client update in: $dir" -ForegroundColor Cyan + Write-Host "`nRunning tsp-client update in: $fullDir" -ForegroundColor Cyan try { - Push-Location $dir - tsp-client update + tsp-client update --output-dir $fullDir if ($LASTEXITCODE -ne 0) { - Write-Warning "tsp-client update failed in directory: $dir (exit code: $LASTEXITCODE)" + Write-Warning "tsp-client update failed in directory: $fullDir (exit code: $LASTEXITCODE)" } else { - Write-Host "Successfully updated: $dir" -ForegroundColor Green + Write-Host "Successfully updated: $fullDir" -ForegroundColor Green } } catch { - Write-Error "Error running tsp-client update in directory: $dir - $_" - } - finally { - Pop-Location + Write-Error "Error running tsp-client update in directory: $fullDir - $_" } } diff --git a/sdk/core/azure_core_amqp/Test-Setup.ps1 b/sdk/core/azure_core_amqp/Test-Setup.ps1 index df711456398..287535f3b3f 100644 --- a/sdk/core/azure_core_amqp/Test-Setup.ps1 +++ b/sdk/core/azure_core_amqp/Test-Setup.ps1 @@ -22,56 +22,46 @@ if (-not (Test-Path $WorkingDirectory)) { New-Item -ItemType Directory -Path $WorkingDirectory } -Write-Host "Setting current directory to working directory: $WorkingDirectory" -Push-Location -Path $WorkingDirectory - # Clone and build the Test Amqp Broker. -try { - - $repositoryUrl = "https://github.com/Azure/azure-amqp.git" - $repositoryHash = "d82a86455c3459c5628bc95b25511f6e8a065598" - $cloneCommand = "git clone $repositoryUrl --revision $repositoryHash" - +$repositoryUrl = "https://github.com/Azure/azure-amqp.git" +$repositoryHash = "d82a86455c3459c5628bc95b25511f6e8a065598" +$cloneCommand = "git -C '$WorkingDirectory' clone $repositoryUrl --revision $repositoryHash" - Write-Host "Cloning repository from $repositoryUrl..." - Invoke-LoggedCommand $cloneCommand +Write-Host "Cloning repository from $repositoryUrl..." +Invoke-LoggedCommand $cloneCommand - Set-Location -Path "./azure-amqp/test/TestAmqpBroker" +$testBrokerDir = "$WorkingDirectory/azure-amqp/test/TestAmqpBroker" - Invoke-LoggedCommand "dotnet build --framework net8.0" - if (-not $?) { - Write-Error "Failed to build TestAmqpBroker." - exit 1 - } +Invoke-LoggedCommand "dotnet build '$testBrokerDir' --framework net8.0" +if (-not $?) { + Write-Error "Failed to build TestAmqpBroker." + exit 1 +} - Write-Host "Test broker built successfully." +Write-Host "Test broker built successfully." - # now that the Test broker has been built, launch the broker on a local address. - $env:TEST_BROKER_ADDRESS = 'amqp://127.0.0.1:25672' +# now that the Test broker has been built, launch the broker on a local address. +$env:TEST_BROKER_ADDRESS = 'amqp://127.0.0.1:25672' - Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..." +Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..." - # Note that we cannot use `dotnet run -f` here because the TestAmqpBroker relies on args[0] being the broker address. - # If we use `dotnet run -f`, the first argument is the csproj file. - # Instead, we use `dotnet exec` to run the compiled DLL directly. - # This allows us to pass the broker address as the first argument. - Set-Location -Path $WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net8.0 - $job = dotnet exec ./TestAmqpBroker.dll ${env:TEST_BROKER_ADDRESS} /headless & +# Note that we cannot use `dotnet run -f` here because the TestAmqpBroker relies on args[0] being the broker address. +# If we use `dotnet run -f`, the first argument is the csproj file. +# Instead, we use `dotnet exec` to run the compiled DLL directly. +# This allows us to pass the broker address as the first argument. +$brokerDll = "$WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net8.0/TestAmqpBroker.dll" +$job = dotnet exec $brokerDll ${env:TEST_BROKER_ADDRESS} /headless & - $env:TEST_BROKER_JOBID = $job.Id +$env:TEST_BROKER_JOBID = $job.Id - Write-Host "Waiting for test broker to start..." - Start-Sleep -Seconds 3 +Write-Host "Waiting for test broker to start..." +Start-Sleep -Seconds 3 - Write-Host "Job Output after wait:" - Receive-Job $job.Id +Write-Host "Job Output after wait:" +Receive-Job $job.Id - $job = Get-Job -Id $env:TEST_BROKER_JOBID - if ($job.State -ne "Running") { - Write-Host "Test broker failed to start." - exit 1 - } -} -finally { - Pop-Location +$job = Get-Job -Id $env:TEST_BROKER_JOBID +if ($job.State -ne "Running") { + Write-Host "Test broker failed to start." + exit 1 } diff --git a/sdk/identity/test-resources-post.ps1 b/sdk/identity/test-resources-post.ps1 index f585e80e7e7..b59bba10df0 100644 --- a/sdk/identity/test-resources-post.ps1 +++ b/sdk/identity/test-resources-post.ps1 @@ -41,22 +41,23 @@ if ($CI) { az account set --subscription $SubscriptionId } -Set-Location "$(git rev-parse --show-toplevel)/sdk/identity/azure_identity/tests/tools/deployed_live_test" +$repoRoot = git rev-parse --show-toplevel +$testAppDir = "$repoRoot/sdk/identity/azure_identity/tests/tools/deployed_live_test" Write-Host "##[group]Building test app" -cargo install --path . --root target +cargo install --path $testAppDir --root "$testAppDir/target" Write-Host "##[endgroup]" Write-Host "##[group]Building container image" az acr login -n $DeploymentOutputs['IDENTITY_ACR_NAME'] $image = "$($DeploymentOutputs['IDENTITY_ACR_LOGIN_SERVER'])/live-test" -Set-Content -Path Dockerfile -Value @" +Set-Content -Path "$testAppDir/Dockerfile" -Value @" FROM mcr.microsoft.com/mirror/docker/library/ubuntu:24.04 RUN apt update && apt install ca-certificates --no-install-recommends -y COPY target/bin/deployed_live_test . CMD ["./deployed_live_test"] "@ -docker build -t $image . +docker build -t $image $testAppDir docker push $image Write-Host "##[endgroup]" From c74b5260739ec99b597067d10e0e697cc081a7c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:46:50 +0000 Subject: [PATCH 3/3] Fix code review feedback: Use correct git clone syntax and cross-platform path handling Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com> --- sdk/core/azure_core_amqp/Test-Setup.ps1 | 7 ++++--- sdk/identity/test-resources-post.ps1 | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sdk/core/azure_core_amqp/Test-Setup.ps1 b/sdk/core/azure_core_amqp/Test-Setup.ps1 index 287535f3b3f..109b86fecba 100644 --- a/sdk/core/azure_core_amqp/Test-Setup.ps1 +++ b/sdk/core/azure_core_amqp/Test-Setup.ps1 @@ -25,12 +25,13 @@ if (-not (Test-Path $WorkingDirectory)) { # Clone and build the Test Amqp Broker. $repositoryUrl = "https://github.com/Azure/azure-amqp.git" $repositoryHash = "d82a86455c3459c5628bc95b25511f6e8a065598" -$cloneCommand = "git -C '$WorkingDirectory' clone $repositoryUrl --revision $repositoryHash" +$cloneDir = [System.IO.Path]::Combine($WorkingDirectory, "azure-amqp") +$cloneCommand = "git clone $repositoryUrl --revision $repositoryHash '$cloneDir'" Write-Host "Cloning repository from $repositoryUrl..." Invoke-LoggedCommand $cloneCommand -$testBrokerDir = "$WorkingDirectory/azure-amqp/test/TestAmqpBroker" +$testBrokerDir = [System.IO.Path]::Combine($cloneDir, "test", "TestAmqpBroker") Invoke-LoggedCommand "dotnet build '$testBrokerDir' --framework net8.0" if (-not $?) { @@ -49,7 +50,7 @@ Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..." # If we use `dotnet run -f`, the first argument is the csproj file. # Instead, we use `dotnet exec` to run the compiled DLL directly. # This allows us to pass the broker address as the first argument. -$brokerDll = "$WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net8.0/TestAmqpBroker.dll" +$brokerDll = [System.IO.Path]::Combine($cloneDir, "bin", "Debug", "TestAmqpBroker", "net8.0", "TestAmqpBroker.dll") $job = dotnet exec $brokerDll ${env:TEST_BROKER_ADDRESS} /headless & $env:TEST_BROKER_JOBID = $job.Id diff --git a/sdk/identity/test-resources-post.ps1 b/sdk/identity/test-resources-post.ps1 index b59bba10df0..c4c30aa986e 100644 --- a/sdk/identity/test-resources-post.ps1 +++ b/sdk/identity/test-resources-post.ps1 @@ -42,16 +42,18 @@ if ($CI) { } $repoRoot = git rev-parse --show-toplevel -$testAppDir = "$repoRoot/sdk/identity/azure_identity/tests/tools/deployed_live_test" +$testAppDir = [System.IO.Path]::Combine($repoRoot, "sdk", "identity", "azure_identity", "tests", "tools", "deployed_live_test") +$targetDir = [System.IO.Path]::Combine($testAppDir, "target") Write-Host "##[group]Building test app" -cargo install --path $testAppDir --root "$testAppDir/target" +cargo install --path $testAppDir --root $targetDir Write-Host "##[endgroup]" Write-Host "##[group]Building container image" az acr login -n $DeploymentOutputs['IDENTITY_ACR_NAME'] $image = "$($DeploymentOutputs['IDENTITY_ACR_LOGIN_SERVER'])/live-test" -Set-Content -Path "$testAppDir/Dockerfile" -Value @" +$dockerfilePath = [System.IO.Path]::Combine($testAppDir, "Dockerfile") +Set-Content -Path $dockerfilePath -Value @" FROM mcr.microsoft.com/mirror/docker/library/ubuntu:24.04 RUN apt update && apt install ca-certificates --no-install-recommends -y COPY target/bin/deployed_live_test .