Skip to content

[AutoPR-confidentialledger]Cadl demo #1276

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

Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions eng/scripts/Automation-Sdk-Init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ $dotnet = Join-Path $RepoRoot "../.dotnet"
if (Test-Path $installScript) {
Remove-Item $installScript
}

# npm install -g @azure-tools/cadl-csharp
44 changes: 42 additions & 2 deletions eng/scripts/Invoke-GenerateAndBuildV2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ please refer to eng/scripts/automation/unified-pipeline-test.md for more test sc

#>
param (
[string]$inputJsonFile,
[string]$outputJsonFile
[string]$inputJsonFile="./eng/scripts/tests/firstOnboardInput.json",
[string]$outputJsonFile="output.json"
)

. (Join-Path $PSScriptRoot ".." "common" "scripts" "Helpers" PSModule-Helpers.ps1)
Expand All @@ -41,6 +41,7 @@ $commitid = $inputJson.headSha
$repoHttpsUrl = $inputJson.repoHttpsUrl
$downloadUrlPrefix = $inputJson.installInstructionInput.downloadUrlPrefix
$autorestConfig = $inputJson.autorestConfig
$relatedCadlProjectFolder = $inputJson.relatedCadlProjectFolder

$autorestConfigYaml = ""
if ($autorestConfig) {
Expand Down Expand Up @@ -108,6 +109,45 @@ if ($inputFileToGen) {
UpdateExistingSDKByInputFiles -inputFilePaths $inputFileToGen -sdkRootPath $sdkPath -headSha $commitid -repoHttpsUrl $repoHttpsUrl -downloadUrlPrefix "$downloadUrlPrefix" -generatedSDKPackages $generatedSDKPackages
}

# generate sdk from cadl file
if ($relatedCadlProjectFolder) {
# Push-Location $swaggerDir
# npm install @azure-tools/cadl-csharp
# Pop-Location
for ($i = 0; $i -le $relatedCadlProjectFolder.Count - 1; $i++) {
$caldFolder = (Join-Path $swaggerDir $relatedCadlProjectFolder[$i]) -replace "\\", "/"
$newPackageOutput = "newPackageOutput.json"

Push-Location $caldFolder
$cadlProjectYaml = Get-Content -Path "$caldFolder/cadl-project.yaml" -Raw

Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
$yml = ConvertFrom-YAML $cadlProjectYaml
$sdkFolder = $yml["emitters"]["@azure-tools/cadl-csharp"]["sdk-folder"]
$projectFolder = (Join-Path $sdkPath $sdkFolder)
$projectFolder = $projectFolder -replace "\\", "/"
if ($projectFolder) {
$directories = $projectFolder.Split("/");
$count = $directories.Count
$projectFolder = $directories[0 .. ($count-2)] -join "/"
$service = $directories[-3];
$namespace = $directories[-2];
}
New-CADLPackageFolder -service $service -namespace $namespace -sdkPath $sdkPath -cadlInput $caldFolder/main.cadl -outputJsonFile $newpackageoutput
$newPackageOutputJson = Get-Content $newPackageOutput | Out-String | ConvertFrom-Json
$relativeSdkPath = $newPackageOutputJson.path
# node $swaggerDir/node_modules/@cadl-lang/compiler/cmd/cadl.js compile --emit @azure-tools/cadl-csharp --output-path $sdkPath .\main.cadl

# node $swaggerDir/node_modules/@cadl-lang/compiler/cmd/cadl.js compile --output-path $sdkPath --emit @azure-tools/cadl-csharp ./main.cadl
npm install
npx cadl compile --output-path $sdkPath --emit @azure-tools/cadl-csharp .
if ( !$?) {
Throw "Failed to generate sdk for cadl. exit code: $?"
}
GeneratePackage -projectFolder $projectFolder -sdkRootPath $sdkPath -path $relativeSdkPath -downloadUrlPrefix "$downloadUrlPrefix" -skipGenerate -generatedSDKPackages $generatedSDKPackages
Pop-Location
}
}
$outputJson = [PSCustomObject]@{
packages = $generatedSDKPackages
}
Expand Down
99 changes: 98 additions & 1 deletion eng/scripts/automation/GenerateAndBuildLib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,100 @@ function New-MgmtPackageFolder() {
return $projectFolder
}

function New-CADLPackageFolder() {
param(
[string]$service,
[string]$namespace,
[string]$sdkPath = "",
[string]$cadlInput ="",
[string]$outputJsonFile = "output.json"
)
$serviceFolder = (Join-Path $sdkPath "sdk" $service)
$projectFolder=(Join-Path $sdkPath "sdk" $service $namespace)
$ciymlFilePath =(Join-Path $sdkPath "sdk" $service $CI_YAML_FILE)
$apifolder = (Join-Path $projectFolder "api")
Write-Host "projectFolder:$projectFolder, apifolder:$apifolder"
if ((Test-Path -Path $projectFolder) -And (Test-Path -Path $apifolder)) {
Write-Host "Path exists!"
if (Test-Path -Path $projectFolder/src/autorest.md) {
Remove-Item -Path $projectFolder/src/autorest.md
}
$projFile = (Join-Path $projectFolder "src" "$namespace.csproj")
$fileContent = Get-Content -Path $projFile
$match = ($fileContent | Select-String -Pattern "<AutoRestInput>").LineNumber
if ($match.count -gt 0) {
$fileContent[$match[0] - 1] = "<AutoRestInput>$cadlInput</AutoRestInput>";
} else {
$startNum = ($fileContent | Select-String -Pattern '</PropertyGroup>').LineNumber[0]
$fileContent[$startNum - 2] += ([Environment]::NewLine + "<AutoRestInput>$cadlInput</AutoRestInput>")
}
$fileContent | Out-File $projFile

Update-CIYmlFile -ciFilePath $ciymlFilePath -artifact $namespace
} else {
Write-Host "Path doesn't exist. create template."
dotnet new -i $sdkPath/sdk/template
Write-Host "Create project folder $projectFolder"
if (Test-Path -Path $projectFolder) {
Remove-Item -Path $projectFolder -ItemType Directory
}

Push-Location $serviceFolder
$namespaceArray = $namespace.Split(".")
if ( $namespaceArray.Count -lt 3) {
Throw "Error: invalid namespace name."
}

$endIndex = $namespaceArray.Count - 2
$clientName = $namespaceArray[-1]
$groupName = $namespaceArray[1..$endIndex] -join "."
$dotnetNewCmd = "dotnet new azsdkdpg --name $namespace --clientName $clientName --groupName $groupName --serviceDirectory $service --force"

if (Test-Path -Path $ciymlFilePath) {
Write-Host "ci.yml already exists. update it to include the new serviceDirectory."
Update-CIYmlFile -ciFilePath $ciymlFilePath -artifact $namespace

$dotnetNewCmd = $dotnetNewCmd + " --includeCI false"
}
# dotnet new azsdkdpg --name $namespace --clientName $clientName --groupName $groupName --serviceDirectory $service --swagger $inputfile --securityScopes $securityScope --securityHeaderName $securityHeaderName --includeCI true --force
Write-Host "Invoke dotnet new command: $dotnetNewCmd"
Invoke-Expression $dotnetNewCmd

$projFile = (Join-Path $projectFolder "src" "$namespace.csproj")
$fileContent = Get-Content -Path $projFile
$fileContent = $fileContent -replace "<Version>*.*.*-*.*</Version>", "<Version>1.0.0-beta.1</Version>"
$startNum = ($fileContent | Select-String -Pattern '</PropertyGroup>').LineNumber[0]
$fileContent[$startNum - 2] += ([Environment]::NewLine + "<AutoRestInput>$cadlInput</AutoRestInput>")
$fileContent | Out-File $projFile
# (Get-Content $projFile) -replace "<Version>*.*.*-*.*</Version>", "<Version>1.0.0-beta.1</Version>" | -replace "<AutoRestInput>*</AutoRestInput>", "<AutoRestInput>$cadlInput</AutoRestInput>" |Set-Content $projFile
Pop-Location
# dotnet sln
Push-Location $projectFolder
if (Test-Path -Path $projectFolder/src/autorest.md) {
Remove-Item -Path $projectFolder/src/autorest.md
}
dotnet sln remove src/$namespace.csproj
dotnet sln add src/$namespace.csproj
dotnet sln remove tests/$namespace.Tests.csproj
dotnet sln add tests/$namespace.Tests.csproj
Pop-Location
}

Push-Location $sdkPath
$relativeFolderPath = Resolve-Path $projectFolder -Relative
Pop-Location

$outputJson = [PSCustomObject]@{
service = $service
packageName = $namespace
projectFolder = $projectFolder
path = @($relativeFolderPath)
}

$outputJson | ConvertTo-Json -depth 100 | Out-File $outputJsonFile
return $projectFolder
}

function Get-ResourceProviderFromReadme($readmeFile) {
$readmeFile = $readmeFile -replace "\\", "/"
$pathArray = $readmeFile.Split("/");
Expand Down Expand Up @@ -523,6 +617,7 @@ function GeneratePackage()
[string]$sdkRootPath,
[string]$path,
[string]$downloadUrlPrefix="",
[switch]$skipGenerate,
[object]$generatedSDKPackages
)

Expand All @@ -540,7 +635,9 @@ function GeneratePackage()
# Generate Code
Write-Host "Start to generate sdk $projectFolder"
$srcPath = Join-Path $projectFolder 'src'
dotnet build /t:GenerateCode $srcPath
if (!$skipGenerate) {
dotnet build /t:GenerateCode $srcPath
}
if ( !$?) {
Write-Error "Failed to generate sdk. exit code: $?"
$result = "failed"
Expand Down
58 changes: 47 additions & 11 deletions eng/scripts/automation/Invoke-GenerateAndBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ $downloadUrlPrefix = $inputJson.installInstructionInput.downloadUrlPrefix
$autorestConfig = $inputJson.autorestConfig

$autorestConfig = $inputJson.autorestConfig
$relatedCadlProjectFolder = $inputJson.relatedCadlProjectFolder

$autorestConfigYaml = ""
if ($autorestConfig -ne "") {
if ($autorestConfig) {
$autorestConfig | Set-Content "config.md"
$autorestConfigYaml = Get-Content -Path .\config.md
$range = ($autorestConfigYaml | Select-String -Pattern '```').LineNumber
Expand All @@ -41,27 +42,62 @@ if ($autorestConfig -ne "") {
}
}

Write-Host "swaggerDir:$swaggerDir, readmeFile:$readmeFile"
$generatedSDKPackages = New-Object 'Collections.Generic.List[System.Object]'

# $service, $serviceType = Get-ResourceProviderFromReadme $readmeFile
$sdkPath = (Join-Path $PSScriptRoot .. .. ..)
$sdkPath = Resolve-Path $sdkPath
$sdkPath = $sdkPath -replace "\\", "/"

$readme = ""
if ($commitid -ne "") {
if ($repoHttpsUrl -ne "") {
$readme = "$repoHttpsUrl/blob/$commitid/$readmeFile"
if ($readmeFile) {
Write-Host "swaggerDir:$swaggerDir, readmeFile:$readmeFile"

$readme = ""
if ($commitid -ne "") {
if ($repoHttpsUrl -ne "") {
$readme = "$repoHttpsUrl/blob/$commitid/$readmeFile"
} else {
$readme = "https://github.com/$org/azure-rest-api-specs/blob/$commitid/$readmeFile"
}
} else {
$readme = "https://github.com/$org/azure-rest-api-specs/blob/$commitid/$readmeFile"
$readme = (Join-Path $swaggerDir $readmeFile)
}
} else {
$readme = (Join-Path $swaggerDir $readmeFile)
Invoke-GenerateAndBuildSDK -readmeAbsolutePath $readme -sdkRootPath $sdkPath -autorestConfigYaml "$autorestConfigYaml" -downloadUrlPrefix "$downloadUrlPrefix" -generatedSDKPackages $generatedSDKPackages
}

$generatedSDKPackages = New-Object 'Collections.Generic.List[System.Object]'
Invoke-GenerateAndBuildSDK -readmeAbsolutePath $readme -sdkRootPath $sdkPath -autorestConfigYaml "$autorestConfigYaml" -downloadUrlPrefix "$downloadUrlPrefix" -generatedSDKPackages $generatedSDKPackages
if ($relatedCadlProjectFolder) {
$caldFolder = (Join-Path $swaggerDir $relatedCadlProjectFolder) -replace "\\", "/"
$newPackageOutput = "newPackageOutput.json"

Push-Location $caldFolder
$cadlProjectYaml = Get-Content -Path "$caldFolder/cadl-project.yaml" -Raw

Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
$yml = ConvertFrom-YAML $cadlProjectYaml
$sdkFolder = $yml["emitters"]["@azure-tools/cadl-csharp"]["sdk-folder"]
$projectFolder = (Join-Path $sdkPath $sdkFolder)
$projectFolder = $projectFolder -replace "\\", "/"
if ($projectFolder) {
$directories = $projectFolder.Split("/");
$count = $directories.Count
$projectFolder = $directories[0 .. ($count-2)] -join "/"
$service = $directories[-3];
$namespace = $directories[-2];
}
New-CADLPackageFolder -service $service -namespace $namespace -sdkPath $sdkPath -cadlInput $caldFolder/main.cadl -outputJsonFile $newpackageoutput
$newPackageOutputJson = Get-Content $newPackageOutput | Out-String | ConvertFrom-Json
$relativeSdkPath = $newPackageOutputJson.path
# node $swaggerDir/node_modules/@cadl-lang/compiler/cmd/cadl.js compile --emit @azure-tools/cadl-csharp --output-path $sdkPath .\main.cadl

# node $swaggerDir/node_modules/@cadl-lang/compiler/cmd/cadl.js compile --output-path $sdkPath --emit @azure-tools/cadl-csharp ./main.cadl
npm install
npx cadl compile --output-path $sdkPath --emit @azure-tools/cadl-csharp .
if ( !$?) {
Throw "Failed to generate sdk for cadl. exit code: $?"
}
GeneratePackage -projectFolder $projectFolder -sdkRootPath $sdkPath -path $relativeSdkPath -downloadUrlPrefix "$downloadUrlPrefix" -skipGenerate -generatedSDKPackages $generatedSDKPackages
Pop-Location
}
$outputJson = [PSCustomObject]@{
packages = $generatedSDKPackages
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyTitle>Azure Confidential Ledger</AssemblyTitle>
<Version>1.1.0-beta.2</Version>
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
<ApiCompatVersion>1.0.0</ApiCompatVersion>
<!-- <ApiCompatVersion>1.0.0</ApiCompatVersion> -->
<PackageTags>Azure ConfidentialLedger</PackageTags>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<DefineConstants>$(DefineConstants)</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{ECC730C1-4AEA-420C-916A-66B19B79E4DC}"
EndProject
Project("{F496793D-E397-4B77-869A-71287E62A92D}") = "Azure.Security.ConfidentialLedgerDemo.Perf", "perf\Azure.Security.ConfidentialLedgerDemo.Perf.csproj", "{30C5FF85-655A-49FC-A324-16438130FF3F}"
EndProject
Project("{F496793D-E397-4B77-869A-71287E62A92D}") = "Azure.Security.ConfidentialLedgerDemo.Stress", "stress\Azure.Security.ConfidentialLedgerDemo.Stress.csproj", "{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Security.ConfidentialLedgerDemo", "src\Azure.Security.ConfidentialLedgerDemo.csproj", "{33A76AED-02F0-479D-9AF0-07034633E1F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Security.ConfidentialLedgerDemo.Tests", "tests\Azure.Security.ConfidentialLedgerDemo.Tests.csproj", "{56049BA5-6383-45B9-A7B5-F613036CB7F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{30C5FF85-655A-49FC-A324-16438130FF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30C5FF85-655A-49FC-A324-16438130FF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30C5FF85-655A-49FC-A324-16438130FF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30C5FF85-655A-49FC-A324-16438130FF3F}.Release|Any CPU.Build.0 = Release|Any CPU
{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}.Release|Any CPU.Build.0 = Release|Any CPU
{33A76AED-02F0-479D-9AF0-07034633E1F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33A76AED-02F0-479D-9AF0-07034633E1F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33A76AED-02F0-479D-9AF0-07034633E1F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33A76AED-02F0-479D-9AF0-07034633E1F1}.Release|Any CPU.Build.0 = Release|Any CPU
{56049BA5-6383-45B9-A7B5-F613036CB7F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56049BA5-6383-45B9-A7B5-F613036CB7F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56049BA5-6383-45B9-A7B5-F613036CB7F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56049BA5-6383-45B9-A7B5-F613036CB7F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props
-->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
</Project>
Loading