Skip to content

Commit

Permalink
Use local HEAD commit to create tsp-location.yaml (#6293)
Browse files Browse the repository at this point in the history
* 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: Wes Haggard <[email protected]>
Co-authored-by: Konrad Jamrozik <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2023
1 parent 89cab83 commit 9136fcd
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions eng/common/scripts/TypeSpec-Project-Process.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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:(?<repo>[^/]*/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
Expand Down

0 comments on commit 9136fcd

Please sign in to comment.