Аудит конфигурации CI
Находит файлы GitHub Actions, GitLab CI, Azure, CircleCI и Jenkins и проверяет базовые секции.
Что делает скрипт
Скрипт обходит известные пути CI-конфигураций и выполняет структурные проверки: наличие jobs, шагов, checkout и блока triggers. Это не полноценный YAML-парсер, но он быстро ловит пустые и явно неполные файлы. Конфигурации только читаются.
Быстрый старт
powershell -File CI-ConfigAudit.ps1 -Path C:\Users\user\src\app
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File CI-ConfigAudit.ps1 -Path .powershell -File CI-ConfigAudit.ps1 -Path D:\Projects\app -Csv ci.csv
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
CI-ConfigAudit.ps1
[CmdletBinding()]
param(
[string]$Path = ".",
[string]$Csv
)
$ErrorActionPreference = 'Stop'
$root = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path
if (-not (Test-Path -LiteralPath $root -PathType Container)) {
throw "Folder not found: $root"
}
$files = @()
$workflowDir = Join-Path $root '.github\workflows'
if (Test-Path -LiteralPath $workflowDir -PathType Container) {
$files += Get-ChildItem -LiteralPath $workflowDir -File -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -in '.yml', '.yaml' }
}
foreach ($relative in @('.gitlab-ci.yml', 'azure-pipelines.yml', 'Jenkinsfile', 'bitbucket-pipelines.yml')) {
$candidate = Join-Path $root $relative
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$files += Get-Item -LiteralPath $candidate
}
}
$circle = Join-Path $root '.circleci\config.yml'
if (Test-Path -LiteralPath $circle -PathType Leaf) {
$files += Get-Item -LiteralPath $circle
}
if ($files.Count -eq 0) {
Write-Host "No CI configuration files found."
exit 0
}
$rows = @()
foreach ($file in $files) {
$text = Get-Content -LiteralPath $file.FullName -Raw -ErrorAction Stop
$warnings = @()
$platform = 'unknown'
if ($file.FullName -like '*\.github\workflows\*') {
$platform = 'github'
if ($text -notmatch '(?m)^on:') { $warnings += 'no on trigger' }
if ($text -notmatch '(?m)^jobs:') { $warnings += 'no jobs block' }
if ($text -notmatch 'runs-on:') { $warnings += 'no runs-on' }
if ($text -notmatch 'actions/checkout') { $warnings += 'no checkout step' }
if ($text -notmatch '(?m)^permissions:') { $warnings += 'no permissions block' }
} elseif ($file.Name -eq '.gitlab-ci.yml') {
$platform = 'gitlab'
if ($text -notmatch '(?m)^stages:') { $warnings += 'no stages' }
if ($text -notmatch 'script:') { $warnings += 'no script steps' }
} elseif ($file.Name -eq 'azure-pipelines.yml') {
$platform = 'azure'
if ($text -notmatch '(?m)^trigger:') { $warnings += 'no trigger' }
if ($text -notmatch 'pool:') { $warnings += 'no pool' }
if ($text -notmatch 'steps:') { $warnings += 'no steps' }
} elseif ($file.Name -eq 'Jenkinsfile') {
$platform = 'jenkins'
if ($text -notmatch 'pipeline\s*{') { $warnings += 'no pipeline block' }
if ($text -notmatch 'stages\s*{') { $warnings += 'no stages block' }
} elseif ($file.Name -eq 'config.yml') {
$platform = 'circleci'
if ($text -notmatch 'version:') { $warnings += 'no version' }
if ($text -notmatch '(?m)^jobs:') { $warnings += 'no jobs' }
} elseif ($file.Name -eq 'bitbucket-pipelines.yml') {
$platform = 'bitbucket'
if ($text -notmatch '(?m)^pipelines:') { $warnings += 'no pipelines block' }
}
if ([string]::IsNullOrWhiteSpace($text)) {
$warnings += 'empty file'
}
$statusValue = if ($warnings.Count -eq 0) { 'OK' } else { 'Review' }
$rows += [pscustomobject]@{
Platform = $platform
File = $file.FullName.Substring($root.Length).TrimStart([char[]]@('\', '/'))
Lines = ($text -split "`n").Count
Status = $statusValue
Warnings = ($warnings -join '; ')
}
}
$rows | Format-Table -AutoSize -Wrap
if ($Csv) {
$rows | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8
Write-Host "CSV saved: $Csv"
}
$bad = @($rows | Where-Object { $_.Status -ne 'OK' }).Count
Write-Host "Configs: $($rows.Count), needs review: $bad"
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.