From ca31ac1d5b446fd03f32813d36446a42a89879d8 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:07:19 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 6293 (#20980) * Use local HEAD commit to create tsp-location.yaml * Set default repo value in tsp-location * Update eng/common/scripts/TypeSpec-Project-Process.ps1 Co-authored-by: Wes Haggard * Update eng/common/scripts/TypeSpec-Project-Process.ps1 Co-authored-by: Konrad Jamrozik * Resolve feedback * Fixed git remote repo parsing --------- Co-authored-by: raychen Co-authored-by: Wes Haggard Co-authored-by: Konrad Jamrozik --- .../scripts/TypeSpec-Project-Process.ps1 | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index 87004c9b494e..a27036a80a45 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -165,15 +165,38 @@ if (Test-Path $tmpTspConfigPath) { $sdkProjectFolder = "" if ($generateFromLocalTypeSpec) { + Write-Host "Generating sdk code based on local type specs at specRepoRoot: $specRepoRoot." $sdkProjectFolder = Get-TspLocationFolder $tspConfigYaml $sdkRepoRootPath $tspLocationYamlPath = Join-Path $sdkProjectFolder "tsp-location.yaml" if (!(Test-Path -Path $tspLocationYamlPath)) { - Write-Error "Failed to find tsp-location.yaml in '$sdkProjectFolder', please make sure to provide CommitHash and RepoUrl parameters along with the local path of tspconfig.yaml in order to create tsp-location.yaml." - exit 1 + # try to create tsp-location.yaml using HEAD commit of the local spec repo + Write-Warning "Failed to find tsp-location.yaml in '$sdkProjectFolder'. Trying to create tsp-location.yaml using HEAD commit of the local spec repo then proceed the sdk generation based upon local typespecs at $specRepoRoot. Alternatively, please make sure to provide CommitHash and RepoUrl parameters when running this script." + # set default repo to Azure/azure-rest-api-specs + $repo = "Azure/azure-rest-api-specs" + try { + Push-Location $specRepoRoot + $CommitHash = $(git rev-parse HEAD) + $gitOriginUrl = (git remote get-url origin) + if ($gitOriginUrl -and $gitOriginUrl -match '(.*)?github.com:(?[^/]*/azure-rest-api-specs(-pr)?)(.git)?') { + $repo = $Matches["repo"] + Write-Host "Found git origin repo: $repo" + } + else { + Write-Warning "Failed to find git origin repo of the local spec repo at specRepoRoot: $specRepoRoot. Using default repo: $repo" + } + } + catch { + Write-Error "Failed to get HEAD commit or remote origin of the local spec repo at specRepoRoot: $specRepoRoot." + exit 1 + } + finally { + Pop-Location + } + $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath } } else { # call CreateUpdate-TspLocation function - $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath + $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath } # call TypeSpec-Project-Sync.ps1