Modules/businessdev.ALbuild.Apps/Public/Get-BcAppSourceCopBaseline.ps1
|
function Get-BcAppSourceCopBaseline { <# .SYNOPSIS Finds the previous app version AppSourceCop compares against, as the compile step sees it. .DESCRIPTION AppSourceCop reports breaking changes against the version named in AppSourceCop.json ('version'), and only when that app is in the package cache. The quality gate compiles with the project's .alpackages, where a repository keeps the baseline (Banking: 365 business Banking 18.3.513.27128); a build with a fresh package cache has no baseline and silently skips every breaking-change rule. This returns the baseline file so such a build can stage it. .PARAMETER ProjectFolder The app folder (app.json, AppSourceCop.json, .alpackages). .OUTPUTS PSCustomObject: Version, File (full path, or $null when the baseline is missing), Message. $null when the project has no AppSourceCop.json or no 'version' in it. #> [CmdletBinding()] [OutputType([PSCustomObject])] param([Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $ProjectFolder) $copPath = Join-Path $ProjectFolder 'AppSourceCop.json' if (-not (Test-Path -LiteralPath $copPath)) { return $null } $cop = Get-Content -LiteralPath $copPath -Raw | ConvertFrom-Json $version = if ($cop.PSObject.Properties.Name -contains 'version') { "$($cop.version)".Trim() } else { '' } if (-not $version) { return $null } $app = Get-Content -LiteralPath (Join-Path $ProjectFolder 'app.json') -Raw | ConvertFrom-Json $leaf = "$($app.publisher)_$($app.name)_$version.app" $file = Join-Path (Join-Path $ProjectFolder '.alpackages') $leaf if (Test-Path -LiteralPath $file) { return [PSCustomObject]@{ Version = $version; File = (Resolve-Path -LiteralPath $file).Path; Message = "AppSourceCop baseline $version ($leaf)." } } return [PSCustomObject]@{ Version = $version; File = $null; Message = "AppSourceCop.json names baseline $version, but '$leaf' is not in .alpackages; the breaking-change rules cannot run." } } |