Skip to content

Commit fd60f58

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 6250 (Azure#35218)
* Revert the change and return tsplocation folder * Out null for the new-item command * exit if return failure when call sync script * Added repo assignment in local path scenario * Added more output * Fix path processing in windows * exit when run generate script with error --------- Co-authored-by: raychen <[email protected]>
1 parent 3067eaf commit fd60f58

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

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

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr
3636
# Create service-dir if not exist
3737
$serviceDir = Join-Path $repoRoot $serviceDir
3838
if (!(Test-Path -Path $serviceDir)) {
39-
New-Item -Path $serviceDir -ItemType Directory
39+
New-Item -Path $serviceDir -ItemType Directory | Out-Null
4040
Write-Host "created service folder $serviceDir"
4141
}
4242

4343
# Create package-dir if not exist
4444
$packageDir = Join-Path $serviceDir $packageDir
4545
if (!(Test-Path -Path $packageDir)) {
46-
New-Item -Path $packageDir -ItemType Directory
46+
New-Item -Path $packageDir -ItemType Directory | Out-Null
4747
Write-Host "created package folder $packageDir"
4848
}
4949

@@ -59,11 +59,15 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr
5959

6060
# Update tsp-location.yaml
6161
$tspLocationYaml["commit"] = $CommitHash
62+
Write-Host "updated tsp-location.yaml commit to $CommitHash"
6263
$tspLocationYaml["repo"] = $repo
64+
Write-Host "updated tsp-location.yaml repo to $repo"
6365
$tspLocationYaml["directory"] = $TypeSpecProjectDirectory
66+
Write-Host "updated tsp-location.yaml directory to $TypeSpecProjectDirectory"
6467
$tspLocationYaml["additionalDirectories"] = $additionalDirs
68+
Write-Host "updated tsp-location.yaml additionalDirectories to $additionalDirs"
6569
$tspLocationYaml |ConvertTo-Yaml | Out-File $tspLocationYamlPath
66-
Write-Host "updated tsp-location.yaml in $packageDir"
70+
Write-Host "finished updating tsp-location.yaml in $packageDir"
6771
return $packageDir
6872
}
6973

@@ -87,22 +91,13 @@ function Get-PackageDir([System.Object]$tspConfig) {
8791
return $packageDir
8892
}
8993

90-
$repo = ""
91-
if ($RepoUrl) {
92-
if ($RepoUrl -match "^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
93-
$repo = $Matches["repo"]
94-
}
95-
else {
96-
Write-Host "Parameter 'RepoUrl' has incorrect value: $RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'"
97-
exit 1
98-
}
99-
}
100-
10194
$repoRootPath = (Join-Path $PSScriptRoot .. .. ..)
10295
$repoRootPath = Resolve-Path $repoRootPath
10396
$repoRootPath = $repoRootPath -replace "\\", "/"
10497
$tspConfigPath = Join-Path $repoRootPath 'tspconfig.yaml'
10598
$tmpTspConfigPath = $tspConfigPath
99+
$repo = ""
100+
# remote url scenario
106101
# example url of tspconfig.yaml: https://github.com/Azure/azure-rest-api-specs-pr/blob/724ccc4d7ef7655c0b4d5c5ac4a5513f19bbef35/specification/containerservice/Fleet.Management/tspconfig.yaml
107102
if ($TypeSpecProjectDirectory -match '^https://github.com/(?<repo>Azure/azure-rest-api-specs(-pr)?)/blob/(?<commit>[0-9a-f]{40})/(?<path>.*)/tspconfig.yaml$') {
108103
try {
@@ -119,15 +114,32 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?<repo>Azure/azure-re
119114
$CommitHash = $Matches["commit"]
120115
# TODO support the branch name in url then get the commithash from branch name
121116
} else {
117+
# local path scenario
118+
$tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml"
119+
if (!(Test-Path $tspConfigPath)) {
120+
Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'"
121+
exit 1
122+
}
123+
$TypeSpecProjectDirectory = $TypeSpecProjectDirectory.Replace("\", "/")
122124
if ($TypeSpecProjectDirectory -match "^.*/(?<path>specification/.*)$") {
123125
$TypeSpecProjectDirectory = $Matches["path"]
124126
} else {
125-
Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path."
127+
Write-Error "$TypeSpecProjectDirectory doesn't have 'specification' in path."
126128
exit 1
127129
}
128-
$tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml"
129-
if (!(Test-Path $tspConfigPath)) {
130-
Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'"
130+
if (!$CommitHash) {
131+
Write-Error "Parameter of Commithash is not provided in the local path scenario."
132+
exit 1
133+
}
134+
if (!$RepoUrl) {
135+
Write-Error "Parameter of RepoUrl:$RepoUrl is not provided in the local path scenario."
136+
exit 1
137+
}
138+
if ($RepoUrl -match "^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
139+
$repo = $Matches["repo"]
140+
}
141+
else {
142+
Write-Error "Parameter 'RepoUrl' has incorrect value:$RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'"
131143
exit 1
132144
}
133145
}
@@ -142,6 +154,13 @@ if (Test-Path $tmpTspConfigPath) {
142154
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $repoRootPath
143155

144156
# call TypeSpec-Project-Sync.ps1
145-
& "$PSScriptRoot/TypeSpec-Project-Sync.ps1" $sdkProjectFolder
157+
$syncScript = Join-Path $PSScriptRoot TypeSpec-Project-Sync.ps1
158+
& $syncScript $sdkProjectFolder
159+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
160+
146161
# call TypeSpec-Project-Generate.ps1
147-
& "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder
162+
$generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1
163+
& $generateScript $sdkProjectFolder
164+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
165+
166+
return $sdkProjectFolder

0 commit comments

Comments
 (0)