From 6c829c56d3e754517ecaf573aff50fd5fa4b89c1 Mon Sep 17 00:00:00 2001 From: raychen Date: Mon, 29 May 2023 14:42:17 +0800 Subject: [PATCH 1/7] Revert the change and return tsplocation folder --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 3efe62f1d3..6bb46be151 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -119,17 +119,17 @@ 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 { + $tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml" + if (!(Test-Path $tspConfigPath)) { + Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" + exit 1 + } if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { $TypeSpecProjectDirectory = $Matches["path"] } else { Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path." exit 1 } - $tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml" - if (!(Test-Path $tspConfigPath)) { - Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" - exit 1 - } } $tspConfigYaml = Get-Content $tspConfigPath -Raw | ConvertFrom-Yaml @@ -144,4 +144,5 @@ $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDire # call TypeSpec-Project-Sync.ps1 & "$PSScriptRoot/TypeSpec-Project-Sync.ps1" $sdkProjectFolder # call TypeSpec-Project-Generate.ps1 -& "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder \ No newline at end of file +& "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder +return $sdkProjectFolder \ No newline at end of file From be01a2ec3aebe82a9f8dc47f8b0111f2abc30995 Mon Sep 17 00:00:00 2001 From: raychen Date: Mon, 29 May 2023 15:25:54 +0800 Subject: [PATCH 2/7] Out null for the new-item command --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 6bb46be151..89a564dd92 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" } From 1edc376e1f970a03958c8cfe8b40074b604d822a Mon Sep 17 00:00:00 2001 From: raychen Date: Mon, 29 May 2023 15:58:46 +0800 Subject: [PATCH 3/7] exit if return failure when call sync script --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 89a564dd92..f005e7e8fd 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -143,6 +143,9 @@ $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDire # call TypeSpec-Project-Sync.ps1 & "$PSScriptRoot/TypeSpec-Project-Sync.ps1" $sdkProjectFolder +if ($LASTEXITCODE) { exit $LASTEXITCODE } + # call TypeSpec-Project-Generate.ps1 & "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder + return $sdkProjectFolder \ No newline at end of file From 1d8a0b5137c33f06c4532010bbf11ac1fde81ae0 Mon Sep 17 00:00:00 2001 From: raychen Date: Mon, 29 May 2023 17:36:57 +0800 Subject: [PATCH 4/7] Added repo assignment in local path scenario --- .../scripts/TypeSpec-Project-Process.ps1 | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index f005e7e8fd..ab01ccb761 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -87,22 +87,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,6 +110,7 @@ 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 { + # local path scenario $tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml" if (!(Test-Path $tspConfigPath)) { Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" @@ -127,7 +119,22 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-re if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { $TypeSpecProjectDirectory = $Matches["path"] } else { - Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path." + 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 } } From 1e8add987c91a35901fef9dd74c9fa64a586c2d1 Mon Sep 17 00:00:00 2001 From: raychen Date: Tue, 30 May 2023 13:50:21 +0800 Subject: [PATCH 5/7] Added more output --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index ab01ccb761..88ba24d11d 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -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 } @@ -116,7 +120,7 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-re Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" exit 1 } - if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { + if ($TypeSpecProjectDirectory -match "^.*[\\/](?specification[\\/].*)$") { $TypeSpecProjectDirectory = $Matches["path"] } else { Write-Error "$TypeSpecProjectDirectory doesn't have 'specification' in path." @@ -149,10 +153,12 @@ 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 +$generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1 +& $generateScript $sdkProjectFolder return $sdkProjectFolder \ No newline at end of file From 23ddfa4359bcf4f78c8f2bf50ba86cfe73b26e6d Mon Sep 17 00:00:00 2001 From: raychen Date: Tue, 30 May 2023 16:45:32 +0800 Subject: [PATCH 6/7] Fix path processing in windows --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 88ba24d11d..b5c0c24276 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -120,7 +120,8 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-re Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" exit 1 } - if ($TypeSpecProjectDirectory -match "^.*[\\/](?specification[\\/].*)$") { + $TypeSpecProjectDirectory = $TypeSpecProjectDirectory.Replace("\", "/") + if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { $TypeSpecProjectDirectory = $Matches["path"] } else { Write-Error "$TypeSpecProjectDirectory doesn't have 'specification' in path." From 6b692fba2e28effb35ec95b1c5e23352852baff4 Mon Sep 17 00:00:00 2001 From: raychen Date: Wed, 31 May 2023 15:54:26 +0800 Subject: [PATCH 7/7] exit when run generate script with error --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index b5c0c24276..3bff436dca 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -161,5 +161,6 @@ if ($LASTEXITCODE) { exit $LASTEXITCODE } # call TypeSpec-Project-Generate.ps1 $generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1 & $generateScript $sdkProjectFolder +if ($LASTEXITCODE) { exit $LASTEXITCODE } return $sdkProjectFolder \ No newline at end of file