From 1cda5b99f5a788d98f6771a4a35448aa14bd974d Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 31 May 2023 01:50:29 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 6250 (#4675) * Revert the change and return tsplocation folder * Out null for the new-item command * exit if return failure when call sync script * Added repo assignment in local path scenario * Added more output * Fix path processing in windows * exit when run generate script with error --------- Co-authored-by: raychen --- .../scripts/TypeSpec-Project-Process.ps1 | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 3efe62f1d..3bff436dc 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -36,14 +36,14 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr # Create service-dir if not exist $serviceDir = Join-Path $repoRoot $serviceDir if (!(Test-Path -Path $serviceDir)) { - New-Item -Path $serviceDir -ItemType Directory + New-Item -Path $serviceDir -ItemType Directory | Out-Null Write-Host "created service folder $serviceDir" } # Create package-dir if not exist $packageDir = Join-Path $serviceDir $packageDir if (!(Test-Path -Path $packageDir)) { - New-Item -Path $packageDir -ItemType Directory + New-Item -Path $packageDir -ItemType Directory | Out-Null Write-Host "created package folder $packageDir" } @@ -59,11 +59,15 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr # Update tsp-location.yaml $tspLocationYaml["commit"] = $CommitHash + Write-Host "updated tsp-location.yaml commit to $CommitHash" $tspLocationYaml["repo"] = $repo + Write-Host "updated tsp-location.yaml repo to $repo" $tspLocationYaml["directory"] = $TypeSpecProjectDirectory + Write-Host "updated tsp-location.yaml directory to $TypeSpecProjectDirectory" $tspLocationYaml["additionalDirectories"] = $additionalDirs + Write-Host "updated tsp-location.yaml additionalDirectories to $additionalDirs" $tspLocationYaml |ConvertTo-Yaml | Out-File $tspLocationYamlPath - Write-Host "updated tsp-location.yaml in $packageDir" + Write-Host "finished updating tsp-location.yaml in $packageDir" return $packageDir } @@ -87,22 +91,13 @@ function Get-PackageDir([System.Object]$tspConfig) { return $packageDir } -$repo = "" -if ($RepoUrl) { - if ($RepoUrl -match "^https://github.com/(?[^/]*/azure-rest-api-specs(-pr)?).*") { - $repo = $Matches["repo"] - } - else { - Write-Host "Parameter 'RepoUrl' has incorrect value: $RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'" - exit 1 - } -} - $repoRootPath = (Join-Path $PSScriptRoot .. .. ..) $repoRootPath = Resolve-Path $repoRootPath $repoRootPath = $repoRootPath -replace "\\", "/" $tspConfigPath = Join-Path $repoRootPath 'tspconfig.yaml' $tmpTspConfigPath = $tspConfigPath +$repo = "" +# remote url scenario # example url of tspconfig.yaml: https://github.com/Azure/azure-rest-api-specs-pr/blob/724ccc4d7ef7655c0b4d5c5ac4a5513f19bbef35/specification/containerservice/Fleet.Management/tspconfig.yaml if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-rest-api-specs(-pr)?)/blob/(?[0-9a-f]{40})/(?.*)/tspconfig.yaml$') { try { @@ -119,17 +114,34 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-re $CommitHash = $Matches["commit"] # TODO support the branch name in url then get the commithash from branch name } else { - if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { - $TypeSpecProjectDirectory = $Matches["path"] - } else { - Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path." - exit 1 - } + # local path scenario $tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml" if (!(Test-Path $tspConfigPath)) { Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" exit 1 } + $TypeSpecProjectDirectory = $TypeSpecProjectDirectory.Replace("\", "/") + if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { + $TypeSpecProjectDirectory = $Matches["path"] + } else { + Write-Error "$TypeSpecProjectDirectory doesn't have 'specification' in path." + exit 1 + } + if (!$CommitHash) { + Write-Error "Parameter of Commithash is not provided in the local path scenario." + exit 1 + } + if (!$RepoUrl) { + Write-Error "Parameter of RepoUrl:$RepoUrl is not provided in the local path scenario." + exit 1 + } + if ($RepoUrl -match "^https://github.com/(?[^/]*/azure-rest-api-specs(-pr)?).*") { + $repo = $Matches["repo"] + } + else { + Write-Error "Parameter 'RepoUrl' has incorrect value:$RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'" + exit 1 + } } $tspConfigYaml = Get-Content $tspConfigPath -Raw | ConvertFrom-Yaml @@ -142,6 +154,13 @@ if (Test-Path $tmpTspConfigPath) { $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $repoRootPath # call TypeSpec-Project-Sync.ps1 -& "$PSScriptRoot/TypeSpec-Project-Sync.ps1" $sdkProjectFolder +$syncScript = Join-Path $PSScriptRoot TypeSpec-Project-Sync.ps1 +& $syncScript $sdkProjectFolder +if ($LASTEXITCODE) { exit $LASTEXITCODE } + # call TypeSpec-Project-Generate.ps1 -& "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder \ No newline at end of file +$generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1 +& $generateScript $sdkProjectFolder +if ($LASTEXITCODE) { exit $LASTEXITCODE } + +return $sdkProjectFolder \ No newline at end of file