Skip to content

Commit

Permalink
Merge pull request #1488 from openapi-env-test/user/raych1/test-dotne…
Browse files Browse the repository at this point in the history
…t-auto

Update dotnet automation scripts
  • Loading branch information
raych1 authored Jun 13, 2023
2 parents 4ae973e + 2948f88 commit 193a90e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
51 changes: 18 additions & 33 deletions eng/scripts/Invoke-GenerateAndBuildV2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ foreach( $file in $inputFilePaths) {
$inputFileToGen += @($file)
}
}

}

if ($inputFileToGen) {
Expand All @@ -113,42 +113,27 @@ if ($inputFileToGen) {
if ($relatedTypeSpecProjectFolder) {
foreach ($typespecRelativeFolder in $relatedTypeSpecProjectFolder) {
$typespecFolder = Resolve-Path (Join-Path $swaggerDir $typespecRelativeFolder)
$newPackageOutput = "newPackageOutput.json"

$tspConfigYaml = Get-Content -Path (Join-Path "$typespecFolder" "tspconfig.yaml") -Raw

Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
$yml = ConvertFrom-YAML $tspConfigYaml
$service = ""
$namespace = ""
if ($yml) {
if ($yml["parameters"] -And $yml["parameters"]["service-directory-name"]) {
$service = $yml["parameters"]["service-directory-name"]["default"];
}
if ($yml["options"] -And $yml["options"]["@azure-tools/typespec-csharp"] -And $yml["options"]["@azure-tools/typespec-csharp"]["namespace"]) {
$namespace = $yml["options"]["@azure-tools/typespec-csharp"]["namespace"]
}
}
if (!$service || !$namespace) {
throw "Not provide service name or namespace."
}
$projectFolder = (Join-Path $sdkPath "sdk" $service $namespace)
New-TypeSpecPackageFolder `
-service $service `
-namespace $namespace `
-sdkPath $sdkPath `
-relatedTypeSpecProjectFolder $typespecRelativeFolder `
-specRoot $swaggerDir `
-outputJsonFile $newpackageoutput
$newPackageOutputJson = Get-Content $newPackageOutput -Raw | ConvertFrom-Json
$relativeSdkPath = $newPackageOutputJson.path
GeneratePackage `
-projectFolder $projectFolder `
$curpath = Get-Location | Select-Object -ExpandProperty Path | Out-String -Stream
Write-Host "Current path is $curpath"
$processScript = Resolve-Path (Join-Path "./eng/common/scripts" "TypeSpec-Project-Process.ps1")
$sdkProjectFolder = & $processScript $typespecFolder $commitid $repoHttpsUrl -SkipSyncAndGenerate
if ($LASTEXITCODE) {
# If Process script call fails, then return with failure to CI and don't need to call GeneratePackage
$generatedSDKPackages = @{
result = "failed";
path=@("");
}
} else {
$relativeSdkPath = Resolve-Path $sdkProjectFolder -Relative
GeneratePackage `
-projectFolder $sdkProjectFolder `
-sdkRootPath $sdkPath `
-path $relativeSdkPath `
-downloadUrlPrefix $downloadUrlPrefix `
-serviceType "data-plane" `
-generatedSDKPackages $generatedSDKPackages
-generatedSDKPackages $generatedSDKPackages `
-specRepoRoot $swaggerDir
}
}
}
$outputJson = [PSCustomObject]@{
Expand Down
9 changes: 7 additions & 2 deletions eng/scripts/automation/GenerateAndBuildLib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ function GeneratePackage()
[string]$downloadUrlPrefix="",
[string]$serviceType="data-plane",
[switch]$skipGenerate,
[object]$generatedSDKPackages
[object]$generatedSDKPackages,
[string]$specRepoRoot=""
)

$packageName = Split-Path $projectFolder -Leaf
Expand All @@ -740,7 +741,11 @@ function GeneratePackage()
Write-Host "Start to generate sdk $projectFolder"
$srcPath = Join-Path $projectFolder 'src'
if (!$skipGenerate) {
dotnet build /t:GenerateCode $srcPath
if($specRepoRoot -eq "") {
dotnet build /t:GenerateCode $srcPath
} else {
dotnet build /t:GenerateCode $srcPath /p:SpecRepoRoot=$specRepoRoot
}
}
if ( !$?) {
Write-Error "Failed to generate sdk. exit code: $?"
Expand Down

0 comments on commit 193a90e

Please sign in to comment.