Skip to content

Commit c82eb8a

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 6468 (Azure#21130)
* Update typespec common scripts * Revert change of specCloneDir variable --------- Co-authored-by: raychen <raychen@microsoft.com>
1 parent a2ba93f commit c82eb8a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ param (
1616
. $PSScriptRoot/Helpers/PSModule-Helpers.ps1
1717
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
1818

19-
function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecProjectDirectory, [string]$CommitHash, [string]$repo, [string]$repoRoot) {
19+
function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecProjectDirectory, [string]$CommitHash, [string]$repo, [string]$repoRoot, [ref]$isNewSdkProject) {
2020
$additionalDirs = @()
2121
if ($tspConfig["parameters"]["dependencies"] -and $tspConfig["parameters"]["dependencies"]["additionalDirectories"]) {
2222
$additionalDirs = $tspConfig["parameters"]["dependencies"]["additionalDirectories"];
@@ -35,6 +35,7 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr
3535
if (!(Test-Path -Path $packageDir)) {
3636
New-Item -Path $packageDir -ItemType Directory | Out-Null
3737
Write-Host "created package folder $packageDir"
38+
$isNewSdkProject.Value = $true
3839
}
3940

4041
# Load tsp-location.yaml if exist
@@ -110,6 +111,7 @@ $tmpTspConfigPath = $tspConfigPath
110111
$repo = ""
111112
$specRepoRoot = ""
112113
$generateFromLocalTypeSpec = $false
114+
$isNewSdkProject = $false
113115
# remote url scenario
114116
# example url of tspconfig.yaml: https://github.com/Azure/azure-rest-api-specs-pr/blob/724ccc4d7ef7655c0b4d5c5ac4a5513f19bbef35/specification/containerservice/Fleet.Management/tspconfig.yaml
115117
if ($TypeSpecProjectDirectory -match '^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?)/blob/(?<commit>[0-9a-f]{40})/(?<path>.*)/tspconfig.yaml$') {
@@ -147,7 +149,7 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?<repo>[^/]*/azure-re
147149
}
148150

149151
if ($RepoUrl) {
150-
if ($RepoUrl -match "^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
152+
if ($RepoUrl -match "^(https://github.com/|git@github.com:)(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
151153
$repo = $Matches["repo"]
152154
}
153155
else {
@@ -193,26 +195,34 @@ if ($generateFromLocalTypeSpec) {
193195
finally {
194196
Pop-Location
195197
}
196-
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath
198+
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath -isNewSdkProject ([ref]$isNewSdkProject)
197199
}
198200
} else {
199201
# call CreateUpdate-TspLocation function
200-
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath
202+
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $sdkRepoRootPath -isNewSdkProject ([ref]$isNewSdkProject)
201203
}
202204

203-
# checking skip switch
204-
if ($SkipSyncAndGenerate) {
205+
# checking skip switch, only skip when it's not a new sdk project as project scaffolding is supported by emitter
206+
if ($SkipSyncAndGenerate -and !$isNewSdkProject) {
205207
Write-Host "Skip calling TypeSpec-Project-Sync.ps1 and TypeSpec-Project-Generate.ps1."
206208
} else {
207209
# call TypeSpec-Project-Sync.ps1
208210
$syncScript = Join-Path $PSScriptRoot TypeSpec-Project-Sync.ps1
209-
& $syncScript $sdkProjectFolder $specRepoRoot
210-
if ($LASTEXITCODE) { exit $LASTEXITCODE }
211+
Write-Host "Calling TypeSpec-Project-Sync.ps1"
212+
& $syncScript $sdkProjectFolder $specRepoRoot | Out-Null
213+
if ($LASTEXITCODE) {
214+
Write-Error "Failed to sync sdk project from $specRepoRoot to $sdkProjectFolder"
215+
exit $LASTEXITCODE
216+
}
211217

212218
# call TypeSpec-Project-Generate.ps1
219+
Write-Host "Calling TypeSpec-Project-Generate.ps1"
213220
$generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1
214-
& $generateScript $sdkProjectFolder
215-
if ($LASTEXITCODE) { exit $LASTEXITCODE }
221+
& $generateScript $sdkProjectFolder | Out-Null
222+
if ($LASTEXITCODE) {
223+
Write-Error "Failed to generate sdk project at $sdkProjectFolder"
224+
exit $LASTEXITCODE
225+
}
216226
}
217227

218228
return $sdkProjectFolder

0 commit comments

Comments
 (0)