Skip to content

Commit 5af4a54

Browse files
authored
First cadl version of AnomalyDetector (Azure#32482)
* First version of AnomalyDetector cadl * Update * Update latest spec * Fix build issue * Update API * Remove samples * Fix issue * Fix issue * Comment tests * Resolve issue * comment tests * Fix
1 parent d09618d commit 5af4a54

File tree

86 files changed

+4247
-3297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4247
-3297
lines changed

eng/csharp-emitter-package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"main": "dist/src/index.js",
3+
"dependencies": {
4+
"@azure-tools/cadl-csharp": "0.1.7"
5+
}
6+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter(Position=0)]
4+
[ValidateNotNullOrEmpty()]
5+
[string] $ProjectDirectory
6+
)
7+
8+
$ErrorActionPreference = "Stop"
9+
. $PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1
10+
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
11+
12+
function NpmInstallForProject([string]$workingDirectory) {
13+
Push-Location $workingDirectory
14+
try {
15+
$currentDur = Resolve-Path "."
16+
Write-Host "Generating from $currentDur"
17+
if (Test-Path "package.json") {
18+
Remove-Item -Path "package.json" -Force
19+
}
20+
if (Test-Path ".npmrc") {
21+
Remove-Item -Path ".npmrc" -Force
22+
}
23+
Copy-Item -Path "$PSScriptRoot/../csharp-emitter-package.json" -Destination "package.json" -Force
24+
npm install
25+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
26+
}
27+
finally {
28+
Pop-Location
29+
}
30+
}
31+
32+
$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/src/cadl-location.yaml"
33+
34+
Write-Host "Reading configuration from $cadlConfigurationFile"
35+
$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml
36+
37+
$specSubDirectory = $configuration["directory"]
38+
$innerFolder = Split-Path $specSubDirectory -Leaf
39+
40+
$tempFolder = "$ProjectDirectory/TempCadlFiles"
41+
$npmWorkingDir = Resolve-Path $tempFolder/$innerFolder
42+
$mainCadlFile = If (Test-Path "$npmWorkingDir/client.cadl") { Resolve-Path "$npmWorkingDir/client.cadl" } Else { Resolve-Path "$npmWorkingDir/main.cadl"}
43+
$resolvedProjectDirectory = Resolve-Path "$ProjectDirectory/src"
44+
45+
try {
46+
Push-Location $npmWorkingDir
47+
NpmInstallForProject $npmWorkingDir
48+
Write-Host("npx cadl compile $mainCadlFile --emit `"`@azure-tools/cadl-csharp`" --output-path `"$resolvedProjectDirectory`"")
49+
npx cadl compile $mainCadlFile --emit "@azure-tools/cadl-csharp" --output-path "$resolvedProjectDirectory"
50+
}
51+
finally {
52+
Pop-Location
53+
}
54+
55+
$shouldCleanUp = $configuration["cleanup"] ?? $true
56+
if ($shouldCleanUp) {
57+
Remove-Item $tempFolder -Recurse -Force
58+
}

eng/scripts/Cadl-Project-Sync.ps1

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter(Position=0)]
4+
[ValidateNotNullOrEmpty()]
5+
[string] $ProjectDirectory
6+
)
7+
8+
$ErrorActionPreference = "Stop"
9+
. $PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1
10+
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
11+
$sparseCheckoutFile = ".git/info/sparse-checkout"
12+
13+
function AddSparseCheckoutPath([string]$subDirectory) {
14+
if (!(Test-Path $sparseCheckoutFile) -or !((Get-Content $sparseCheckoutFile).Contains($subDirectory))) {
15+
Write-Output $subDirectory >> .git/info/sparse-checkout
16+
}
17+
}
18+
19+
function CopySpecToProjectIfNeeded([string]$specCloneRoot, [string]$mainSpecDir, [string]$dest, [string[]]$specAdditionalSubDirectories) {
20+
$source = "$specCloneRoot/$mainSpecDir"
21+
Write-Host "Copying spec from $source"
22+
Copy-Item -Path $source -Destination $dest -Recurse -Force
23+
foreach($additionalDir in $specAdditionalSubDirectories)
24+
{
25+
$source = "$specCloneRoot/$additionalDir"
26+
Write-Host "Copying spec from $source"
27+
Copy-Item -Path $source -Destination $dest -Recurse -Force
28+
}
29+
}
30+
31+
function UpdateSparseCheckoutFile([string]$mainSpecDir, [string[]]$specAdditionalSubDirectories) {
32+
AddSparseCheckoutPath $mainSpecDir
33+
foreach($subDir in $specAdditionalSubDirectories)
34+
{
35+
AddSparseCheckoutPath $subDir
36+
}
37+
}
38+
39+
function GetGitRemoteValue([string]$repo) {
40+
Push-Location $ProjectDirectory
41+
$result = ""
42+
try {
43+
$gitRemotes = (git remote -v)
44+
foreach ($remote in $gitRemotes)
45+
{
46+
if ($remote.StartsWith("origin")) {
47+
if ($remote -match 'https://github.com/\S+[\.git]') {
48+
$result = "https://github.com/$repo.git"
49+
break
50+
} elseif ($remote -match "[email protected]:\S+[\.git]"){
51+
$result = "[email protected]:$repo.git"
52+
break
53+
} else {
54+
throw "Unknown git remote format found: $remote"
55+
}
56+
}
57+
}
58+
}
59+
finally {
60+
Pop-Location
61+
}
62+
63+
return $result
64+
}
65+
66+
function InitializeSparseGitClone([string]$repo) {
67+
git clone --no-checkout --filter=tree:0 $repo .
68+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
69+
git sparse-checkout init
70+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
71+
Remove-Item $sparseCheckoutFile -Force
72+
}
73+
74+
function GetSpecCloneDir([string]$projectName) {
75+
Push-Location $ProjectDirectory
76+
try {
77+
$root = git rev-parse --show-toplevel
78+
}
79+
finally {
80+
Pop-Location
81+
}
82+
83+
$sparseSpecCloneDir = "$root/../sparse-spec/$projectName"
84+
New-Item $sparseSpecCloneDir -Type Directory -Force | Out-Null
85+
$createResult = Resolve-Path $sparseSpecCloneDir
86+
return $createResult
87+
}
88+
89+
$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/src/cadl-location.yaml"
90+
Write-Host "Reading configuration from $cadlConfigurationFile"
91+
$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml
92+
93+
$pieces = $cadlConfigurationFile.Path.Replace("\","/").Split("/")
94+
$projectName = $pieces[$pieces.Count - 3]
95+
96+
$specCloneDir = GetSpecCloneDir $projectName
97+
98+
$gitRemoteValue = GetGitRemoteValue $configuration["repo"]
99+
100+
Write-Host "Setting up sparse clone for $projectName at $specCloneDir"
101+
$specSubDirectory = $configuration["directory"]
102+
Push-Location $specCloneDir.Path
103+
try {
104+
if (!(Test-Path ".git")) {
105+
InitializeSparseGitClone $gitRemoteValue
106+
UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"]
107+
}
108+
git checkout $configuration["commit"]
109+
}
110+
finally {
111+
Pop-Location
112+
}
113+
114+
$tempCadlDir = "$ProjectDirectory/TempCadlFiles"
115+
New-Item $tempCadlDir -Type Directory -Force | Out-Null
116+
CopySpecToProjectIfNeeded `
117+
-specCloneRoot $specCloneDir `
118+
-mainSpecDir $specSubDirectory `
119+
-dest $tempCadlDir `
120+
-specAdditionalSubDirectories $configuration["additionalDirectories"]

0 commit comments

Comments
 (0)