134 lines
5.0 KiB
PowerShell
134 lines
5.0 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[switch] $SkipRestore
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
|
$testResultsPath = Join-Path $repositoryRoot 'TestResults\Validation'
|
|
$dotnetHome = Join-Path (Split-Path -Parent $repositoryRoot) '.dotnet-cli-validation'
|
|
|
|
$env:DOTNET_CLI_HOME = $dotnetHome
|
|
$env:DOTNET_GENERATE_ASPNET_CERTIFICATE = 'false'
|
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
|
|
$env:DOTNET_NOLOGO = '1'
|
|
|
|
function Invoke-External
|
|
{
|
|
param(
|
|
[Parameter(Mandatory)] [string] $FilePath,
|
|
[Parameter(Mandatory)] [string[]] $ArgumentList
|
|
)
|
|
|
|
& $FilePath @ArgumentList
|
|
if ($LASTEXITCODE -ne 0)
|
|
{
|
|
throw "Command failed with exit code ${LASTEXITCODE}: $FilePath $($ArgumentList -join ' ')"
|
|
}
|
|
}
|
|
|
|
function Get-VisualStudioMsBuild
|
|
{
|
|
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
|
if (Test-Path -LiteralPath $vsWhere -PathType Leaf)
|
|
{
|
|
$foundPath = & $vsWhere -latest -products * -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1
|
|
if ($foundPath) { return $foundPath }
|
|
}
|
|
|
|
$candidates = @(
|
|
'C:\Program Files\Microsoft Visual Studio\18\Enterprise\MSBuild\Current\Bin\MSBuild.exe',
|
|
'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe',
|
|
'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe',
|
|
'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe'
|
|
)
|
|
$foundPath = $candidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
|
|
if ($foundPath) { return $foundPath }
|
|
|
|
throw 'Visual Studio MSBuild was not found. BusinessMgr requires its SSDT SQL unit-testing targets.'
|
|
}
|
|
|
|
function Get-TestAssemblyPath
|
|
{
|
|
param(
|
|
[Parameter(Mandatory)] [string] $ProjectPath,
|
|
[Parameter(Mandatory)] [string] $AssemblyName
|
|
)
|
|
|
|
$projectFullPath = Join-Path $repositoryRoot $ProjectPath
|
|
[xml] $projectXml = Get-Content -LiteralPath $projectFullPath -Raw
|
|
$targetFrameworkNode = $projectXml.SelectSingleNode('//TargetFramework')
|
|
if ($null -eq $targetFrameworkNode)
|
|
{
|
|
throw "A single TargetFramework was not found in $ProjectPath"
|
|
}
|
|
|
|
return Join-Path (Split-Path -Parent $projectFullPath) "bin\Debug\$($targetFrameworkNode.InnerText)\$AssemblyName.dll"
|
|
}
|
|
|
|
function Test-LineEndings
|
|
{
|
|
$crlfExtensions = @('.cs', '.csproj', '.sln', '.props', '.targets', '.config', '.json', '.xml', '.md', '.txt', '.ps1', '.cmd', '.bat')
|
|
$lfExtensions = @('.svg', '.html', '.css', '.js', '.sh', '.yml', '.yaml')
|
|
$invalidFiles = [System.Collections.Generic.List[string]]::new()
|
|
$files = @(& git -C $repositoryRoot diff --name-only --diff-filter=ACMRT)
|
|
if ($LASTEXITCODE -ne 0) { throw 'Unable to enumerate modified repository files.' }
|
|
$files += @(& git -C $repositoryRoot diff --cached --name-only --diff-filter=ACMRT)
|
|
if ($LASTEXITCODE -ne 0) { throw 'Unable to enumerate staged repository files.' }
|
|
$files += @(& git -C $repositoryRoot ls-files --others --exclude-standard)
|
|
if ($LASTEXITCODE -ne 0) { throw 'Unable to enumerate untracked repository files.' }
|
|
$files = $files | Sort-Object -Unique
|
|
|
|
foreach ($relativePath in $files)
|
|
{
|
|
$extension = [System.IO.Path]::GetExtension($relativePath).ToLowerInvariant()
|
|
if (($extension -notin $crlfExtensions) -and ($extension -notin $lfExtensions)) { continue }
|
|
|
|
$fullPath = Join-Path $repositoryRoot $relativePath
|
|
if (-not (Test-Path -LiteralPath $fullPath -PathType Leaf)) { continue }
|
|
$bytes = [System.IO.File]::ReadAllBytes($fullPath)
|
|
for ($index = 0; $index -lt $bytes.Length; $index++)
|
|
{
|
|
if (($extension -in $crlfExtensions) -and ($bytes[$index] -eq 10) -and (($index -eq 0) -or ($bytes[$index - 1] -ne 13)))
|
|
{
|
|
$invalidFiles.Add($relativePath)
|
|
break
|
|
}
|
|
if (($extension -in $lfExtensions) -and ($bytes[$index] -eq 13))
|
|
{
|
|
$invalidFiles.Add($relativePath)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($invalidFiles.Count -gt 0)
|
|
{
|
|
throw "Files with incorrect line endings:`n$($invalidFiles -join "`n")"
|
|
}
|
|
}
|
|
|
|
Push-Location $repositoryRoot
|
|
try
|
|
{
|
|
Write-Host 'Validating BusinessMgr workspace...'
|
|
$msBuildPath = Get-VisualStudioMsBuild
|
|
$msBuildArguments = @('BusinessMgr.sln', '/p:Configuration=Debug', '/m:1', '/v:minimal', '/nologo')
|
|
if (-not $SkipRestore) { $msBuildArguments += '/restore' }
|
|
Invoke-External $msBuildPath $msBuildArguments
|
|
|
|
$controlAssembly = Get-TestAssemblyPath 'SaBusMgrTest_Control\SaBusMgrTest_Control.csproj' 'SaBusMgrTest_Control'
|
|
$portalAssembly = Get-TestAssemblyPath 'SaBusMgrTest_Portal\SaBusMgrTest_Portal.csproj' 'SaBusMgrTest_Portal'
|
|
Invoke-External dotnet @('vstest', $controlAssembly, "--TestAdapterPath:$(Split-Path -Parent $controlAssembly)", "--ResultsDirectory:$testResultsPath")
|
|
Invoke-External dotnet @('vstest', $portalAssembly, "--TestAdapterPath:$(Split-Path -Parent $portalAssembly)", "--ResultsDirectory:$testResultsPath")
|
|
Invoke-External git @('diff', '--check')
|
|
Test-LineEndings
|
|
|
|
Write-Host 'BusinessMgr validation passed.' -ForegroundColor Green
|
|
}
|
|
finally
|
|
{
|
|
Pop-Location
|
|
}
|