Skip to content
Draft
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
50 changes: 22 additions & 28 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 48 additions & 56 deletions eng/scripts/Pack-Crates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
49 changes: 22 additions & 27 deletions eng/scripts/Test-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
15 changes: 6 additions & 9 deletions eng/scripts/Update-TspClients.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 - $_"
}
}

Expand Down
71 changes: 31 additions & 40 deletions sdk/core/azure_core_amqp/Test-Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,47 @@ 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"
$cloneDir = [System.IO.Path]::Combine($WorkingDirectory, "azure-amqp")
$cloneCommand = "git clone $repositoryUrl --revision $repositoryHash '$cloneDir'"

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 = [System.IO.Path]::Combine($cloneDir, "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 = [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
$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
}
11 changes: 7 additions & 4 deletions sdk/identity/test-resources-post.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,25 @@ 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 = [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 . --root 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 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 .
CMD ["./deployed_live_test"]
"@
docker build -t $image .
docker build -t $image $testAppDir
docker push $image
Write-Host "##[endgroup]"

Expand Down