Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated automation script used in docker scenario #37447

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eng/scripts/Invoke-GenerateAndBuildV2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ if ($relatedTypeSpecProjectFolder) {
})
} else {
$relativeSdkPath = Resolve-Path $sdkProjectFolder -Relative
$specRepoRoot = $swaggerDir -replace "/specification", ""
raych1 marked this conversation as resolved.
Show resolved Hide resolved
raych1 marked this conversation as resolved.
Show resolved Hide resolved
if ($sdkProjectFolders -contains $sdkProjectFolder) {
# Existed SDK project case, needs to generate code
GeneratePackage `
Expand All @@ -135,7 +136,7 @@ if ($relatedTypeSpecProjectFolder) {
-downloadUrlPrefix $downloadUrlPrefix `
-serviceType "data-plane" `
-generatedSDKPackages $generatedSDKPackages `
-specRepoRoot $swaggerDir
-specRepoRoot $specRepoRoot
} else {
# New SDK project case, code is already generated by emitter. So, skip code generation
GeneratePackage `
Expand All @@ -146,7 +147,7 @@ if ($relatedTypeSpecProjectFolder) {
-serviceType "data-plane" `
-skipGenerate `
-generatedSDKPackages $generatedSDKPackages `
-specRepoRoot $swaggerDir
-specRepoRoot $specRepoRoot
}
}
}
Expand Down
80 changes: 38 additions & 42 deletions eng/scripts/automation/Invoke-GenerateAndBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ $readmeFile = $inputJson.relatedReadmeMdFile
$readmeFile = $readmeFile -replace "\\", "/"
$commitid = $inputJson.headSha
$repoHttpsUrl = $inputJson.repoHttpsUrl
$serviceType = $inputJson.serviceType
$downloadUrlPrefix = $inputJson.installInstructionInput.downloadUrlPrefix
$autorestConfig = $inputJson.autorestConfig

Expand Down Expand Up @@ -69,53 +68,50 @@ if ($readmeFile) {
Invoke-GenerateAndBuildSDK -readmeAbsolutePath $readme -sdkRootPath $sdkPath -autorestConfigYaml "$autorestConfigYaml" -downloadUrlPrefix "$downloadUrlPrefix" -generatedSDKPackages $generatedSDKPackages
}

# generate sdk from typespec file
if ($relatedTypeSpecProjectFolder) {
$typespecFolder = Resolve-Path (Join-Path $swaggerDir $relatedTypeSpecProjectFolder)
$newPackageOutput = "newPackageOutput.json"
foreach ($typespecRelativeFolder in $relatedTypeSpecProjectFolder) {
$typespecFolder = Resolve-Path (Join-Path $swaggerDir $typespecRelativeFolder)
$processScript = Resolve-Path (Join-Path $sdkPath "eng/common/scripts" "TypeSpec-Project-Process.ps1")
$sdkProjectFolders = Get-ChildItem -Path (Join-Path $sdkPath "sdk") -Depth 1 -Directory | Select-Object -ExpandProperty FullName

$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"]
# Invoke Process script. SkipSyncAndGenerate only when it's not a new SDK project
$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.Add(@{
result = "failed";
path=@("");
})
} else {
$relativeSdkPath = Resolve-Path $sdkProjectFolder -Relative
$specRepoRoot = $swaggerDir -replace "/specification", ""
if ($sdkProjectFolders -contains $sdkProjectFolder) {
# Existed SDK project case, needs to generate code
GeneratePackage `
-projectFolder $sdkProjectFolder `
-sdkRootPath $sdkPath `
-path $relativeSdkPath `
-downloadUrlPrefix $downloadUrlPrefix `
-serviceType "data-plane" `
-generatedSDKPackages $generatedSDKPackages `
-specRepoRoot $specRepoRoot
} else {
# New SDK project case, code is already generated by emitter. So, skip code generation
GeneratePackage `
-projectFolder $sdkProjectFolder `
-sdkRootPath $sdkPath `
-path $relativeSdkPath `
-downloadUrlPrefix $downloadUrlPrefix `
-serviceType "data-plane" `
-skipGenerate `
-generatedSDKPackages $generatedSDKPackages `
-specRepoRoot $specRepoRoot
}
}
}
if (!$service || !$namespace) {
throw "Not provide service name or namespace."
}
$projectFolder = (Join-Path $sdkPath "sdk" $service $namespace)
$specRoot = $swaggerDir
if ((-Not $relatedTypeSpecProjectFolder.Contains("specification")) -And $swaggerDir.Contains("specification"))
raych1 marked this conversation as resolved.
Show resolved Hide resolved
{
$relatedTypeSpecProjectFolder = "specification/$relatedTypeSpecProjectFolder"
$specRoot = Split-Path $specRoot
}
New-TypeSpecPackageFolder `
-service $service `
-namespace $namespace `
-sdkPath $sdkPath `
-relatedTypeSpecProjectFolder $relatedTypeSpecProjectFolder `
-specRoot $specRoot `
-outputJsonFile $newpackageoutput
$newPackageOutputJson = Get-Content $newPackageOutput -Raw | ConvertFrom-Json
$relativeSdkPath = $newPackageOutputJson.path
GeneratePackage `
-projectFolder $projectFolder `
-sdkRootPath $sdkPath `
-path $relativeSdkPath `
-downloadUrlPrefix $downloadUrlPrefix `
-serviceType "data-plane" `
-generatedSDKPackages $generatedSDKPackages
}
$outputJson = [PSCustomObject]@{
packages = $generatedSDKPackages
}
$outputJson
$outputJson | ConvertTo-Json -depth 100 | Out-File $outputJsonFile