Skip to content

Commit 7b5d1a9

Browse files
authored
update unified pipeline script to support E2E flow (Azure#33005)
* update ci script * support local swagger * update script * remove unused code * update sdk generation pipeline * remove duplicate ymal install
1 parent bfbdcde commit 7b5d1a9

File tree

5 files changed

+119
-48
lines changed

5 files changed

+119
-48
lines changed

eng/scripts/Cadl-Project-Generate.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ $npmWorkingDir = Resolve-Path $tempFolder/$innerFolder
4242
$mainCadlFile = If (Test-Path "$npmWorkingDir/client.cadl") { Resolve-Path "$npmWorkingDir/client.cadl" } Else { Resolve-Path "$npmWorkingDir/main.cadl"}
4343
$resolvedProjectDirectory = Resolve-Path "$ProjectDirectory/src"
4444

45+
if (Test-Path "$npmWorkingDir/cadl-project.yaml") {
46+
$cadlProjectYaml = Get-Content -Path "$npmWorkingDir/cadl-project.yaml" -Raw
47+
$yml = ConvertFrom-YAML $cadlProjectYaml
48+
if ( $yml["emitters"]["@azure-tools/cadl-csharp"]["sdk-folder"]) {
49+
$yml["emitters"]["@azure-tools/cadl-csharp"]["sdk-folder"] = ""
50+
}
51+
(ConvertTo-Yaml $yml) | Out-File "$npmWorkingDir/cadl-project.yaml"
52+
}
53+
4554
try {
4655
Push-Location $npmWorkingDir
4756
NpmInstallForProject $npmWorkingDir

eng/scripts/Cadl-Project-Sync.ps1

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,29 @@ $configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yam
9393
$pieces = $cadlConfigurationFile.Path.Replace("\","/").Split("/")
9494
$projectName = $pieces[$pieces.Count - 3]
9595

96-
$specCloneDir = GetSpecCloneDir $projectName
97-
98-
$gitRemoteValue = GetGitRemoteValue $configuration["repo"]
99-
100-
Write-Host "Setting up sparse clone for $projectName at $specCloneDir"
10196
$specSubDirectory = $configuration["directory"]
102-
Push-Location $specCloneDir.Path
103-
try {
104-
if (!(Test-Path ".git")) {
105-
InitializeSparseGitClone $gitRemoteValue
106-
UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"]
97+
if ( $configuration["repo"] -and $configuration["commit"]) {
98+
$specCloneDir = GetSpecCloneDir $projectName
99+
$gitRemoteValue = GetGitRemoteValue $configuration["repo"]
100+
101+
Write-Host "Setting up sparse clone for $projectName at $specCloneDir"
102+
103+
Push-Location $specCloneDir.Path
104+
try {
105+
if (!(Test-Path ".git")) {
106+
InitializeSparseGitClone $gitRemoteValue
107+
UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"]
108+
}
109+
git checkout $configuration["commit"]
107110
}
108-
git checkout $configuration["commit"]
109-
}
110-
finally {
111-
Pop-Location
111+
finally {
112+
Pop-Location
113+
}
114+
} elseif ( $configuration["spec-root-dir"] ) {
115+
$specCloneDir = $configuration["spec-root-dir"]
112116
}
113117

118+
114119
$tempCadlDir = "$ProjectDirectory/TempCadlFiles"
115120
New-Item $tempCadlDir -Type Directory -Force | Out-Null
116121
CopySpecToProjectIfNeeded `

eng/scripts/Invoke-GenerateAndBuildV2.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ if ($relatedCadlProjectFolder) {
115115
$cadlFolder = Resolve-Path (Join-Path $swaggerDir $cadlRelativeFolder)
116116
$newPackageOutput = "newPackageOutput.json"
117117

118-
Push-Location $cadlFolder
119-
trap {Pop-Location}
120118
$cadlProjectYaml = Get-Content -Path (Join-Path "$cadlFolder" "cadl-project.yaml") -Raw
121119

122120
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
@@ -131,16 +129,21 @@ if ($relatedCadlProjectFolder) {
131129
$service = $directories[-3];
132130
$namespace = $directories[-2];
133131
}
134-
New-CADLPackageFolder -service $service -namespace $namespace -sdkPath $sdkPath -cadlInput $cadlFolder/main.cadl -outputJsonFile $newpackageoutput
132+
New-CADLPackageFolder `
133+
-service $service `
134+
-namespace $namespace `
135+
-sdkPath $sdkPath `
136+
-relatedCadlProjectFolder $cadlRelativeFolder `
137+
-specRoot $swaggerDir `
138+
-outputJsonFile $newpackageoutput
135139
$newPackageOutputJson = Get-Content $newPackageOutput -Raw | ConvertFrom-Json
136140
$relativeSdkPath = $newPackageOutputJson.path
137-
npm install
138-
npx cadl compile --output-path $sdkPath --emit @azure-tools/cadl-csharp .
139-
if ( !$?) {
140-
Throw "Failed to generate sdk for cadl. exit code: $?"
141-
}
142-
GeneratePackage -projectFolder $projectFolder -sdkRootPath $sdkPath -path $relativeSdkPath -downloadUrlPrefix $downloadUrlPrefix -skipGenerate -generatedSDKPackages $generatedSDKPackages
143-
Pop-Location
141+
GeneratePackage `
142+
-projectFolder $projectFolder `
143+
-sdkRootPath $sdkPath `
144+
-path $relativeSdkPath `
145+
-downloadUrlPrefix $downloadUrlPrefix `
146+
-generatedSDKPackages $generatedSDKPackages
144147
}
145148
}
146149
$outputJson = [PSCustomObject]@{

eng/scripts/automation/GenerateAndBuildLib.ps1

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#Requires -Version 7.0
22
$CI_YAML_FILE = "ci.yml"
3+
$CADL_LOCATION_FILE = "cadl-location.yaml"
34

45
. (Join-Path $PSScriptRoot ".." ".." "common" "scripts" "Helpers" PSModule-Helpers.ps1)
56

@@ -359,12 +360,59 @@ function New-MgmtPackageFolder() {
359360
return $projectFolder
360361
}
361362

363+
function CreateOrUpdateCadlConfigFile() {
364+
param (
365+
[string]$cadlConfigurationFile,
366+
[string]$directory,
367+
[string]$commit = "",
368+
[string]$repo = "",
369+
[string]$specRoot = ""
370+
)
371+
if (!(Test-Path -Path $cadlConfigurationFile)) {
372+
New-Item -Path $cadlConfigurationFile
373+
}
374+
375+
$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml
376+
if ( !$configuration) {
377+
$configuration = [System.Collections.Generic.Dictionary[string,string]](New-Object 'System.Collections.Generic.Dictionary[string,string]')
378+
}
379+
$configuration["directory"] = $directory
380+
if ($commit) {
381+
$configuration["commit"] = $commit
382+
} else {
383+
$configuration.Remove("commit")
384+
}
385+
if ($repo) {
386+
$configuration["repo"] = $repo
387+
} else {
388+
$configuration.Remove("repo")
389+
}
390+
391+
if ($specRoot) {
392+
$configuration["spec-root-dir"] = $specRoot
393+
} else {
394+
$configuration.Remove("spec-root-dir")
395+
}
396+
397+
$fileContent = ""
398+
foreach ( $key in $configuration.keys) {
399+
if ($configuration[$key]) {
400+
$fileContent += ( $key + ": " + $configuration[$key] + [Environment]::NewLine)
401+
}
402+
}
403+
404+
$fileContent | Out-File $cadlConfigurationFile
405+
}
406+
362407
function New-CADLPackageFolder() {
363408
param(
364409
[string]$service,
365410
[string]$namespace,
366411
[string]$sdkPath = "",
367-
[string]$cadlInput ="",
412+
[string]$relatedCadlProjectFolder,
413+
[string]$commit = "",
414+
[string]$repo = "",
415+
[string]$specRoot = "",
368416
[string]$outputJsonFile = "$PWD/output.json"
369417
)
370418
$serviceFolder = (Join-Path $sdkPath "sdk" $service)
@@ -381,17 +429,14 @@ function New-CADLPackageFolder() {
381429
if (Test-Path -Path $projectFolder/src/autorest.md) {
382430
Remove-Item -Path $projectFolder/src/autorest.md
383431
}
384-
$projFile = (Join-Path $projectFolder "src" "$namespace.csproj")
385-
$fileContent = Get-Content -Path $projFile
386-
$match = ($fileContent | Select-String -Pattern "<AutoRestInput>").LineNumber
387-
if ($match.count -gt 0) {
388-
$fileContent[$match[0] - 1] = "<AutoRestInput>$cadlInput</AutoRestInput>";
389-
} else {
390-
$startNum = ($fileContent | Select-String -Pattern '</PropertyGroup>').LineNumber[0]
391-
$fileContent[$startNum - 2] += ([Environment]::NewLine + "<AutoRestInput>$cadlInput</AutoRestInput>")
392-
}
393-
$fileContent | Out-File $projFile
394-
432+
433+
CreateOrUpdateCadlConfigFile `
434+
-cadlConfigurationFile $projectFolder/src/$CADL_LOCATION_FILE `
435+
-directory $relatedCadlProjectFolder `
436+
-commit $commit `
437+
-repo $repo `
438+
-specRoot $specRoot
439+
395440
Update-CIYmlFile -ciFilePath $ciymlFilePath -artifact $namespace
396441
} else {
397442
Write-Host "Path doesn't exist. create template."
@@ -425,8 +470,6 @@ function New-CADLPackageFolder() {
425470
$projFile = (Join-Path $projectFolder "src" "$namespace.csproj")
426471
$fileContent = Get-Content -Path $projFile
427472
$fileContent = $fileContent -replace '<Version>[^<]+</Version>', '<Version>1.0.0-beta.1</Version>'
428-
$startNum = ($fileContent | Select-String -Pattern '</PropertyGroup>').LineNumber[0]
429-
$fileContent[$startNum - 2] += ([Environment]::NewLine + "<AutoRestInput>$cadlInput</AutoRestInput>")
430473
$fileContent | Out-File $projFile
431474
# (Get-Content $projFile) -replace "<Version>*.*.*-*.*</Version>", "<Version>1.0.0-beta.1</Version>" | -replace "<AutoRestInput>*</AutoRestInput>", "<AutoRestInput>$cadlInput</AutoRestInput>" |Set-Content $projFile
432475
Pop-Location
@@ -435,6 +478,14 @@ function New-CADLPackageFolder() {
435478
if (Test-Path -Path $projectFolder/src/autorest.md) {
436479
Remove-Item -Path $projectFolder/src/autorest.md
437480
}
481+
482+
CreateOrUpdateCadlConfigFile `
483+
-cadlConfigurationFile $projectFolder/src/$CADL_LOCATION_FILE `
484+
-directory $relatedCadlProjectFolder `
485+
-commit $commit `
486+
-repo $repo `
487+
-specRoot $specRoot
488+
438489
dotnet sln remove src/$namespace.csproj
439490
dotnet sln add src/$namespace.csproj
440491
dotnet sln remove tests/$namespace.Tests.csproj

eng/scripts/automation/Invoke-GenerateAndBuild.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ if ($relatedCadlProjectFolder) {
6969
$cadlFolder = Resolve-Path (Join-Path $swaggerDir $relatedCadlProjectFolder)
7070
$newPackageOutput = "newPackageOutput.json"
7171

72-
Push-Location $cadlFolder
73-
trap {Pop-Location}
7472
$cadlProjectYaml = Get-Content -Path (Join-Path "$cadlFolder" "cadl-project.yaml") -Raw
7573

7674
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
@@ -85,16 +83,21 @@ if ($relatedCadlProjectFolder) {
8583
$service = $directories[-3];
8684
$namespace = $directories[-2];
8785
}
88-
New-CADLPackageFolder -service $service -namespace $namespace -sdkPath $sdkPath -cadlInput $cadlFolder/main.cadl -outputJsonFile $newpackageoutput
86+
New-CADLPackageFolder `
87+
-service $service `
88+
-namespace $namespace `
89+
-sdkPath $sdkPath `
90+
-relatedCadlProjectFolder $relatedCadlProjectFolder `
91+
-specRoot $swaggerDir `
92+
-outputJsonFile $newpackageoutput
8993
$newPackageOutputJson = Get-Content $newPackageOutput -Raw | ConvertFrom-Json
9094
$relativeSdkPath = $newPackageOutputJson.path
91-
npm install
92-
npx cadl compile --output-path $sdkPath --emit @azure-tools/cadl-csharp .
93-
if ( !$?) {
94-
Throw "Failed to generate sdk for cadl. exit code: $?"
95-
}
96-
GeneratePackage -projectFolder $projectFolder -sdkRootPath $sdkPath -path $relativeSdkPath -downloadUrlPrefix $downloadUrlPrefix -skipGenerate -generatedSDKPackages $generatedSDKPackages
97-
Pop-Location
95+
GeneratePackage `
96+
-projectFolder $projectFolder `
97+
-sdkRootPath $sdkPath `
98+
-path $relativeSdkPath `
99+
-downloadUrlPrefix $downloadUrlPrefix `
100+
-generatedSDKPackages $generatedSDKPackages
98101
}
99102
$outputJson = [PSCustomObject]@{
100103
packages = $generatedSDKPackages

0 commit comments

Comments
 (0)