Skip to content

Commit ca31ac1

Browse files
azure-sdkraych1weshaggardKonrad Jamrozik
authored
Sync eng/common directory with azure-sdk-tools for PR 6293 (Azure#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 <[email protected]> * Update eng/common/scripts/TypeSpec-Project-Process.ps1 Co-authored-by: Konrad Jamrozik <[email protected]> * Resolve feedback * Fixed git remote repo parsing --------- Co-authored-by: raychen <[email protected]> Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: Konrad Jamrozik <[email protected]>
1 parent a688cfe commit ca31ac1

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

eng/common/scripts/TypeSpec-Project-Process.ps1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,38 @@ if (Test-Path $tmpTspConfigPath) {
165165

166166
$sdkProjectFolder = ""
167167
if ($generateFromLocalTypeSpec) {
168+
Write-Host "Generating sdk code based on local type specs at specRepoRoot: $specRepoRoot."
168169
$sdkProjectFolder = Get-TspLocationFolder $tspConfigYaml $sdkRepoRootPath
169170
$tspLocationYamlPath = Join-Path $sdkProjectFolder "tsp-location.yaml"
170171
if (!(Test-Path -Path $tspLocationYamlPath)) {
171-
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."
172-
exit 1
172+
# try to create tsp-location.yaml using HEAD commit of the local spec repo
173+
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."
174+
# set default repo to Azure/azure-rest-api-specs
175+
$repo = "Azure/azure-rest-api-specs"
176+
try {
177+
Push-Location $specRepoRoot
178+
$CommitHash = $(git rev-parse HEAD)
179+
$gitOriginUrl = (git remote get-url origin)
180+
if ($gitOriginUrl -and $gitOriginUrl -match '(.*)?github.com:(?<repo>[^/]*/azure-rest-api-specs(-pr)?)(.git)?') {
181+
$repo = $Matches["repo"]
182+
Write-Host "Found git origin repo: $repo"
183+
}
184+
else {
185+
Write-Warning "Failed to find git origin repo of the local spec repo at specRepoRoot: $specRepoRoot. Using default repo: $repo"
186+
}
187+
}
188+
catch {
189+
Write-Error "Failed to get HEAD commit or remote origin of the local spec repo at specRepoRoot: $specRepoRoot."
190+
exit 1
191+
}
192+
finally {
193+
Pop-Location
194+
}
195+
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath
173196
}
174197
} else {
175198
# call CreateUpdate-TspLocation function
176-
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath
199+
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath
177200
}
178201

179202
# call TypeSpec-Project-Sync.ps1

0 commit comments

Comments
 (0)