Skip to content

Commit 4e7fcab

Browse files
Improve PowerShell command execution for tsp-client usage
Co-authored-by: JoshLove-msft <[email protected]>
1 parent 67acc01 commit 4e7fcab

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,29 @@ try {
108108
}
109109
}
110110

111-
# Use tsp from pinned version in eng/common/tsp-client
112-
$typespecCompileCommand = "Push-Location '$tspClientDir'; npx tsp compile '$mainTypeSpecFile' --emit $emitterName$emitterAdditionalOptions"
113-
if ($TypespecAdditionalOptions) {
114-
$options = $TypespecAdditionalOptions.Split(";");
115-
foreach ($option in $options) {
116-
$typespecCompileCommand += " --option $emitterName.$option"
111+
# Use tsp from pinned version in eng/common/tsp-client by changing to that directory
112+
Push-Location $tspClientDir
113+
try {
114+
$typespecCompileCommand = "npx tsp compile '$mainTypeSpecFile' --emit $emitterName$emitterAdditionalOptions"
115+
if ($TypespecAdditionalOptions) {
116+
$options = $TypespecAdditionalOptions.Split(";");
117+
foreach ($option in $options) {
118+
$typespecCompileCommand += " --option $emitterName.$option"
119+
}
117120
}
118-
}
119-
120-
if ($SaveInputs) {
121-
$typespecCompileCommand += " --option $emitterName.save-inputs=true"
122-
}
123-
124-
$typespecCompileCommand += "; Pop-Location"
125121

126-
Write-Host($typespecCompileCommand)
127-
Invoke-Expression $typespecCompileCommand
122+
if ($SaveInputs) {
123+
$typespecCompileCommand += " --option $emitterName.save-inputs=true"
124+
}
128125

129-
if ($LASTEXITCODE) { exit $LASTEXITCODE }
126+
Write-Host($typespecCompileCommand)
127+
Invoke-Expression $typespecCompileCommand
128+
129+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
130+
}
131+
finally {
132+
Pop-Location
133+
}
130134
}
131135
finally {
132136
Pop-Location

eng/packages/http-client-csharp-mgmt/eng/scripts/Generation.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ function Get-Mgmt-TspCommand {
4747
)
4848
Install-TspClient
4949

50-
$command = "cd `"$tspClientDir`" && npx tsp compile `"$specFile`""
50+
# Change to tsp-client directory to use pinned version, then run tsp compile
51+
if ($IsLinux -or $IsMacOs) {
52+
$command = "cd '$tspClientDir' && npx tsp compile '$specFile'"
53+
} else {
54+
$command = "pushd `"$tspClientDir`" && npx tsp compile `"$specFile`" && popd"
55+
}
5156
$command += " --trace @azure-typespec/http-client-csharp-mgmt"
5257
$command += " --emit `"$repoRoot/..`""
5358
$configFile = Join-Path $generationDir "tspconfig.yaml"

eng/packages/http-client-csharp/eng/scripts/Generation.psm1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ function Get-TspCommand {
4949
)
5050
Install-TspClient
5151

52-
$command = "cd `"$tspClientDir`" && npx tsp compile `"$specFile`""
52+
# Change to tsp-client directory to use pinned version, then run tsp compile
53+
if ($IsLinux -or $IsMacOs) {
54+
$command = "cd '$tspClientDir' && npx tsp compile '$specFile'"
55+
} else {
56+
$command = "pushd `"$tspClientDir`" && npx tsp compile `"$specFile`" && popd"
57+
}
5358
$command += " --trace @azure-typespec/http-client-csharp"
5459
$command += " --emit `"$repoRoot/..`""
5560
$configFile = Join-Path $generationDir "tspconfig.yaml"
@@ -85,7 +90,12 @@ function Get-Mgmt-TspCommand {
8590
)
8691
Install-TspClient
8792

88-
$command = "cd `"$tspClientDir`" && npx tsp compile `"$specFile`""
93+
# Change to tsp-client directory to use pinned version, then run tsp compile
94+
if ($IsLinux -or $IsMacOs) {
95+
$command = "cd '$tspClientDir' && npx tsp compile '$specFile'"
96+
} else {
97+
$command = "pushd `"$tspClientDir`" && npx tsp compile `"$specFile`" && popd"
98+
}
8999
$command += " --trace @azure-typespec/http-client-csharp-mgmt"
90100
$command += " --emit `"$repoRoot/../../http-client-csharp-mgmt`""
91101

eng/scripts/Invoke-GenerateAndBuildV2.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,19 @@ if ($relatedTypeSpecProjectFolder) {
142142
exit $LASTEXITCODE
143143
}
144144
}
145+
146+
# Use tsp-client from pinned version by running from tsp-client directory
147+
$tspclientCommand = "npm exec --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid"
148+
if ($swaggerDir) {
149+
$tspclientCommand += " --local-spec-repo $typespecFolder"
150+
}
151+
Write-Host $tspclientCommand
152+
Invoke-Expression $tspclientCommand
145153
}
146154
finally {
147155
Pop-Location
148156
}
149157

150-
$tspclientCommand = "Push-Location '$tspClientDir'; npm exec --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid"
151-
if ($swaggerDir) {
152-
$tspclientCommand += " --local-spec-repo $typespecFolder"
153-
}
154-
$tspclientCommand += "; Pop-Location"
155-
Write-Host $tspclientCommand
156-
Invoke-Expression $tspclientCommand
157158
if ($LASTEXITCODE) {
158159
# If Process script call fails, then return with failure to CI and don't need to call GeneratePackage
159160
Write-Host "[ERROR] Failed to generate typespec project:$typespecFolder. Exit code: $LASTEXITCODE. Please review the detail errors for potential fixes. If the issue persists, contact the DotNet language support channel at $DotNetSupportChannelLink and include this spec pull request."

0 commit comments

Comments
 (0)