Public/Test-CCCIConfiguration.ps1
|
function Test-CCCIConfiguration { [CmdletBinding()] param( [Parameter(Mandatory)][string]$Path, [string]$Standard = 'core', [string]$Config ) $cfg = Get-CCRepoConfig -Path $Path -Standard $Standard -ConfigFile $Config $disabled = $cfg['disabled_checks'] ?? @() $results = @() if (-not $cfg['require_ci']) { return $results } $workflowDir = Join-Path $Path '.github/workflows' $workflows = @() if (Test-Path $workflowDir) { $workflows = @(Get-ChildItem -Path "$workflowDir/*" -Include '*.yml','*.yaml' -ErrorAction SilentlyContinue) } # CI-001: At least one workflow exists if ('CI-001' -notin $disabled) { $results += New-CCRepoCheckResult -CheckId 'CI-001' -Category 'CI/CD' ` -Item 'Workflow files' ` -Status $(if ($workflows.Count -gt 0) { 'Pass' } else { 'Fail' }) ` -Severity 'Error' ` -Message $(if ($workflows.Count -gt 0) { "Found $($workflows.Count) workflow file(s)" } else { "No workflow files found in .github/workflows/" }) ` -Standard $Standard ` -FixAvailable $true ` -FixAction 'Create .github/workflows/ci.yml' } # CI-002: Workflow includes test step if ('CI-002' -notin $disabled -and $cfg['require_test_step'] -and $workflows.Count -gt 0) { $hasTestStep = $false foreach ($wf in $workflows) { $content = Get-Content $wf.FullName -Raw if ($content -match '(?i)(invoke-pester|pytest|npm\s+test|dotnet\s+test|go\s+test|cargo\s+test|jest|mocha|vitest)') { $hasTestStep = $true break } } $results += New-CCRepoCheckResult -CheckId 'CI-002' -Category 'CI/CD' ` -Item 'Test step in CI' ` -Status $(if ($hasTestStep) { 'Pass' } else { 'Fail' }) ` -Severity 'Error' ` -Message $(if ($hasTestStep) { "CI includes a test step" } else { "No test step detected in workflow files" }) ` -Standard $Standard } # CI-003: Workflow includes lint/analysis step if ('CI-003' -notin $disabled -and $cfg['require_lint_step'] -and $workflows.Count -gt 0) { $hasLint = $false foreach ($wf in $workflows) { $content = Get-Content $wf.FullName -Raw if ($content -match '(?i)(eslint|prettier|psalm|phpstan|pylint|flake8|ruff|clippy|PSScriptAnalyzer|dotnet\s+format|AnalysisLevel)') { $hasLint = $true break } } $results += New-CCRepoCheckResult -CheckId 'CI-003' -Category 'CI/CD' ` -Item 'Lint/analysis step in CI' ` -Status $(if ($hasLint) { 'Pass' } else { 'Warning' }) ` -Severity 'Warning' ` -Message $(if ($hasLint) { "CI includes a lint/analysis step" } else { "No lint/analysis step detected in workflow files" }) ` -Standard $Standard } $results } |