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

Support cadl generation from dotnet language repo #32540

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
88671a0
test(cadl): initial sdk for adp
archerzz Nov 8, 2022
ac88d5f
move csproj
archerzz Nov 14, 2022
aa10195
update csproj
archerzz Nov 14, 2022
566d1a7
fix csproj name
archerzz Nov 14, 2022
e07dca0
fix compilation error
archerzz Nov 14, 2022
e0bf24b
update using template
archerzz Nov 15, 2022
98dd4bb
pull in shared codes
archerzz Nov 15, 2022
a0ae598
remove unimplemented link
archerzz Nov 15, 2022
835b07c
Merge branch 'cadl/adp-rp' of https://github.com/archerzz/azure-sdk-f…
m-nash Nov 16, 2022
a8f76fd
wip for temporarily pulling in partial spec clone
m-nash Nov 17, 2022
3d16923
address feedback
m-nash Nov 17, 2022
a86ced5
support ssh and uri auth
m-nash Nov 18, 2022
2aa29ae
add `Cadl-Project-Buiolder.ps1`
archerzz Nov 18, 2022
9ac84ea
update folder names
m-nash Nov 18, 2022
3f2e053
update script name to reflect its purpose
m-nash Nov 18, 2022
8d646e4
update generate script
m-nash Nov 19, 2022
f252df0
tweak the sparse checkout for perf
m-nash Nov 19, 2022
4eb8e25
add a base package.json
m-nash Nov 19, 2022
8276a3e
move the npm install to the generate step
m-nash Nov 19, 2022
978422d
point at latest in the pr
m-nash Nov 19, 2022
50fca1a
regen using only GenerateCode target
m-nash Nov 19, 2022
e694910
bump autorest.csharp to 20221120.1
archerzz Nov 21, 2022
a63e007
Merge branch 'main' into mnash-cadlGeneration
archerzz Nov 21, 2022
86d8e9d
add diagnostic of remote output
archerzz Nov 21, 2022
4138a8d
Merge branch 'mnash-cadlGeneration' of github.com:Azure/azure-sdk-for…
archerzz Nov 21, 2022
beefc46
support non-bare remote repository
archerzz Nov 21, 2022
a06461f
always use ssh otherwise user name will be prompted
archerzz Nov 21, 2022
bc8e2ad
update git remote regex
m-nash Nov 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
123 changes: 123 additions & 0 deletions eng/scripts/Cadl-Project-Sync.ps1
@@ -0,0 +1,123 @@
[CmdletBinding()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking - if I'm on a plane with no network access and have a copy of all the spec files needed already sync'd to local.... I can still run codegen, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we would need to add in some "offline" mode. Right now it will always try to pull the changes in for the commit sha since it doesn't know if the local files are up to date or not.

we could do this by some flag in the cadl-location.yaml such as commit: local to indicate don't sync just use my local files.

Do you mind filing an issue for this and we can address after this PR unless you think its a requirement for v1. Trying to keep this to MVP as the dpg timelines are very sensitive right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially add some configuration option that allows folks to point at a local specs repo clone as I do think that will be an interesting scenario even outside of the offline scenario.

param (
[Parameter(Position=0)]
[ValidateNotNullOrEmpty()]
[string] $ProjectDirectory
)

$ErrorActionPreference = "Stop"
. $PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module

function AddSparseCheckoutPath([string]$subDirectory) {
$file = ".git/info/sparse-checkout"
if (!(Test-Path $file) -or !((Get-Content $file).Contains($subDirectory))) {
Write-Output $subDirectory >> .git/info/sparse-checkout
}
}

function NpmInstallForProject([string]$workingDirectory) {
Push-Location $workingDirectory
m-nash marked this conversation as resolved.
Show resolved Hide resolved
try {
$currentDur = Resolve-Path "."
Write-Host "Generating from $currentDur"
if (Test-Path "package.json") {
Remove-Item -Path "package.json" -Force
}
if (Test-Path ".npmrc") {
Remove-Item -Path ".npmrc" -Force
}
npm install "@azure-tools/cadl-csharp"
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
finally {
Pop-Location
}
}

function CopySpecToProjectIfNeeded([string]$pullResult, [string]$specCloneRoot, [string]$mainSpecDir, [string]$dest, [string[]]$specAdditionalSubDirectories) {
if (!($pullResult.Contains("Already up to date.")) && Test-Path $dest) {

$source = "$specCloneRoot/$mainSpecDir"
Write-Host "Copying spec from $source"
Copy-Item -Path $source -Destination $dest -Recurse -Force
foreach($additionalDir in $specAdditionalSubDirectories)
{
$source = "$specCloneRoot/$additionalDir"
Write-Host "Copying spec from $source"
Copy-Item -Path $source -Destination $dest -Recurse -Force
}
}
}

function UpdateSparseCheckoutFile([string]$mainSpecDir, [string[]]$specAdditionalSubDirectories) {
AddSparseCheckoutPath $mainSpecDir
foreach($subDir in $specAdditionalSubDirectories)
{
AddSparseCheckoutPath $subDir
}
}

function InitializeSparseGitClone([string]$repo) {
if (!(Test-Path ".git")) {
git init
if ($LASTEXITCODE) { exit $LASTEXITCODE }
git remote add origin $repo
if ($LASTEXITCODE) { exit $LASTEXITCODE }
git config core.sparseCheckout true
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
}

function GetSpecCloneDir([string]$projectName) {
Push-Location $ProjectDirectory
try {
$root = git rev-parse --show-toplevel
}
finally {
Pop-Location
}

$sparseSpecCloneDir = "$root/../temp/$projectName"
New-Item $sparseSpecCloneDir -Type Directory -Force | Out-Null
$createResult = Resolve-Path $sparseSpecCloneDir
return $createResult
}

$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/src/cadl-location.yaml"
Write-Host "Reading configuration from $cadlConfigurationFile"
$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml
m-nash marked this conversation as resolved.
Show resolved Hide resolved

$pieces = $cadlConfigurationFile.Path.Replace("\","/").Split("/")
$projectName = $pieces[$pieces.Count - 3]

$specCloneDir = GetSpecCloneDir $projectName

Write-Host "Setting up sparse clone for $projectName"
m-nash marked this conversation as resolved.
Show resolved Hide resolved
Push-Location $specCloneDir.Path
try {
InitializeSparseGitClone $configuration["repo"]

$specSubDirectory = $configuration["directory"]
UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"]

$result = (git pull origin $configuration["commit"])
m-nash marked this conversation as resolved.
Show resolved Hide resolved
Write-Host $result
}
finally {
Pop-Location
}

$specDir = Resolve-Path "$specCloneDir/$specSubDirectory"

$tempCadlDir = "$ProjectDirectory/temp"
New-Item $tempCadlDir -Type Directory -Force | Out-Null
CopySpecToProjectIfNeeded `
-pullResult $result `
-specCloneRoot $specCloneDir `
-mainSpecDir $specSubDirectory `
-dest $tempCadlDir `
-specAdditionalSubDirectories $configuration["additionalDirectories"]

$innerFolder = Split-Path $specDir -Leaf
NpmInstallForProject (Resolve-Path "$tempCadlDir/$innerFolder")
@@ -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("{CEF82141-C65B-49D6-88DE-A2F45B14F2C1}") = "Azure.AI.AutonomousDevelopmentPlatform.Perf", "perf\Azure.AI.AutonomousDevelopmentPlatform.Perf.csproj", "{30C5FF85-655A-49FC-A324-16438130FF3F}"
EndProject
Project("{CEF82141-C65B-49D6-88DE-A2F45B14F2C1}") = "Azure.AI.AutonomousDevelopmentPlatform.Stress", "stress\Azure.AI.AutonomousDevelopmentPlatform.Stress.csproj", "{47E3BC66-5C4F-47CD-A37B-A973E54BCBA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.AutonomousDevelopmentPlatform", "src\Azure.AI.AutonomousDevelopmentPlatform.csproj", "{34289CB8-9AA8-4B52-907D-34C13D702B90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.AutonomousDevelopmentPlatform.Tests", "tests\Azure.AI.AutonomousDevelopmentPlatform.Tests.csproj", "{E3FF04BD-E1F0-4A44-B7EC-EE46F7B6D17C}"
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
{34289CB8-9AA8-4B52-907D-34C13D702B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34289CB8-9AA8-4B52-907D-34C13D702B90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34289CB8-9AA8-4B52-907D-34C13D702B90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34289CB8-9AA8-4B52-907D-34C13D702B90}.Release|Any CPU.Build.0 = Release|Any CPU
{E3FF04BD-E1F0-4A44-B7EC-EE46F7B6D17C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3FF04BD-E1F0-4A44-B7EC-EE46F7B6D17C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3FF04BD-E1F0-4A44-B7EC-EE46F7B6D17C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3FF04BD-E1F0-4A44-B7EC-EE46F7B6D17C}.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
11 changes: 11 additions & 0 deletions sdk/adp/Azure.AI.AutonomousDevelopmentPlatform/CHANGELOG.md
@@ -0,0 +1,11 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
@@ -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>
90 changes: 90 additions & 0 deletions sdk/adp/Azure.AI.AutonomousDevelopmentPlatform/README.md
@@ -0,0 +1,90 @@
# Azure AutonomousDevelopmentPlatform client library for .NET

This section should give out brief introduction of the client library.

* First sentence: **Describe the service** briefly. You can usually use the first line of the service's docs landing page for this (Example: [Cosmos DB docs landing page](https://docs.microsoft.com/azure/cosmos-db/)).
* Next, add a **bulleted list** of the **most common tasks** supported by the package or library, prefaced with "Use the client library for [Product Name] to:". Then, provide code snippets for these tasks in the [Examples](#examples) section later in the document. Keep the task list short but include those tasks most developers need to perform with your package.

[Source code](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/adp/Azure.AI.AutonomousDevelopmentPlatform/src) | Package (NuGet): TBD | [API reference documentation](https://azure.github.io/azure-sdk-for-net) | [Product documentation](https://docs.microsoft.com/azure)

## Getting started

This section should include everything a developer needs to do to install and create their first client connection *very quickly*.

### Install the package

First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `dotnet add package package-name`, but should enable a developer to successfully install the package from NuGet, npm, or even cloning a GitHub repository.

Install the client library for .NET with [NuGet](https://www.nuget.org/ ):

```dotnetcli
dotnet add package Azure.AI.AutonomousDevelopmentPlatform --prerelease
```

### Prerequisites

Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB:

> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) and [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API). In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`.

### Authenticate the client

If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating.

For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object.

## Key concepts

The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity.

Include the *Thread safety* and *Additional concepts* sections below at the end of your *Key concepts* section. You may remove or add links depending on what your library makes use of:

### Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.

### Additional concepts
<!-- CLIENT COMMON BAR -->
[Client options](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md) |
[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#mocking) |
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
<!-- CLIENT COMMON BAR -->

## Examples

You can familiarize yourself with different APIs using [Samples](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/adp/Azure.AI.AutonomousDevelopmentPlatform/samples).

### <scenario>

You can create a client and call the client's `<operation>` method.

```C# Snippet:Azure_AI_AutonomousDevelopmentPlatform_Scenario
```

## Troubleshooting

Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery.

Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API.

If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code.

## Next steps

* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory.
* If appropriate, point users to other packages that might be useful.
* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for.

## Contributing

This is a template, but your SDK readme should include details on how to contribute code to the repo/package.

<!-- LINKS -->
[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization
[style-guide-cloud]: https://aka.ms/azsdk/cloud-style-guide

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net/sdk/adp/Azure.AI.AutonomousDevelopmentPlatform/README.png)