-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture full coverage of cadl ranch in ci (#4054)
Fixes #4036
- Loading branch information
Showing
6 changed files
with
207 additions
and
96 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/http-client-csharp/eng/scripts/CadlRanch-Helper.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..') | ||
|
||
function IsGenerated { | ||
param ( | ||
[string]$dir | ||
) | ||
|
||
if (-not ($dir.EndsWith("Generated"))) { | ||
return $false | ||
} | ||
|
||
$csFiles = Get-ChildItem -Path $dir -Filter *.cs -File | ||
return $csFiles.Count -gt 0 | ||
} | ||
|
||
function Capitalize-FirstLetter { | ||
param ( | ||
[string]$inputString | ||
) | ||
|
||
if ([string]::IsNullOrEmpty($inputString)) { | ||
return $inputString | ||
} | ||
|
||
$firstChar = $inputString[0].ToString().ToUpper() | ||
$restOfString = $inputString.Substring(1) | ||
|
||
return $firstChar + $restOfString | ||
} | ||
|
||
function Get-Namespace { | ||
param ( | ||
[string]$dir | ||
) | ||
|
||
$words = $dir.Split('-') | ||
$namespace = "" | ||
foreach ($word in $words) { | ||
$namespace += Capitalize-FirstLetter $word | ||
} | ||
return $namespace | ||
} | ||
|
||
Export-ModuleMember -Function "IsGenerated" | ||
Export-ModuleMember -Function "Get-Namespace" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/http-client-csharp/eng/scripts/Get-CadlRanch-Coverage.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# cspell:ignore cadlranch | ||
|
||
#Requires -Version 7.0 | ||
|
||
Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force; | ||
Import-Module "$PSScriptRoot\CadlRanch-Helper.psm1" -DisableNameChecking -Force; | ||
|
||
$packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') | ||
|
||
Refresh-Build | ||
|
||
$specsDirectory = Join-Path $packageRoot 'node_modules' '@azure-tools' 'cadl-ranch-specs' | ||
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch' | ||
$directories = Get-ChildItem -Path "$cadlRanchRoot" -Directory -Recurse | ||
$cadlRanchCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests' 'TestProjects.CadlRanch.Tests.csproj' | ||
$runSettings = Join-Path $packageRoot 'eng' 'test-configurations' 'cadlranch.runsettings' | ||
|
||
$coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage' | ||
|
||
if (-not (Test-Path $coverageDir)) { | ||
New-Item -ItemType Directory -Path $coverageDir | Out-Null | ||
} | ||
|
||
# generate all | ||
foreach ($directory in $directories) { | ||
if (-not (IsGenerated $directory.FullName)) { | ||
continue | ||
} | ||
|
||
$outputDir = $directory.FullName.Substring(0, $directory.FullName.IndexOf("src") - 1) | ||
$subPath = $outputDir.Substring($cadlRanchRoot.Length + 1) | ||
|
||
Write-Host "Regenerating $subPath" -ForegroundColor Cyan | ||
|
||
$specFile = Join-Path $specsDirectory $subPath "main.tsp" | ||
|
||
$command = Get-TspCommand $specFile $outputDir | ||
Invoke $command | ||
# exit if the generation failed | ||
if ($LASTEXITCODE -ne 0) { | ||
exit $LASTEXITCODE | ||
} | ||
} | ||
|
||
# test all | ||
Write-Host "Testing $subPath" -ForegroundColor Cyan | ||
$command = "dotnet test $cadlRanchCsproj --settings $runSettings" | ||
Invoke $command | ||
# exit if the testing failed | ||
if ($LASTEXITCODE -ne 0) { | ||
exit $LASTEXITCODE | ||
} | ||
|
||
# restore all | ||
foreach ($directory in $directories) { | ||
if (-not (IsGenerated $directory.FullName)) { | ||
continue | ||
} | ||
|
||
$outputDir = $directory.FullName.Substring(0, $directory.FullName.IndexOf("src") - 1) | ||
$subPath = $outputDir.Substring($cadlRanchRoot.Length + 1) | ||
|
||
Write-Host "Restoring $subPath" -ForegroundColor Cyan | ||
$command = "git clean -xfd $outputDir" | ||
Invoke $command | ||
# exit if the restore failed | ||
if ($LASTEXITCODE -ne 0) { | ||
exit $LASTEXITCODE | ||
} | ||
$command = "git restore $outputDir" | ||
Invoke $command | ||
# exit if the restore failed | ||
if ($LASTEXITCODE -ne 0) { | ||
exit $LASTEXITCODE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters