Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions scripts/security/Test-ActionVersionConsistency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,13 @@ function Export-ConsistencyReport {
}
}

#region Main Execution

function Invoke-ActionVersionConsistencyCheck {
function Invoke-ActionVersionConsistency {
<#
.SYNOPSIS
Orchestrates the version consistency analysis.
#>
[OutputType([int])]
[CmdletBinding()]
[OutputType([void])]
param(
[Parameter(Mandatory = $false)]
[string]$Path = '.github/workflows',
Expand All @@ -378,6 +380,7 @@ function Invoke-ActionVersionConsistencyCheck {
Write-ConsistencyLog 'Starting GitHub Actions version consistency analysis...' -Level Info
Write-ConsistencyLog "Scanning path: $Path" -Level Info

# Scan for violations
$result = Get-ActionVersionViolations -WorkflowPath $Path

$violations = $result.Violations
Expand All @@ -388,39 +391,39 @@ function Invoke-ActionVersionConsistencyCheck {
Write-ConsistencyLog "Found $mismatchCount version mismatches" -Level $(if ($mismatchCount -gt 0) { 'Warning' } else { 'Info' })
Write-ConsistencyLog "Found $missingCount missing version comments" -Level $(if ($missingCount -gt 0) { 'Warning' } else { 'Info' })

Export-ConsistencyReport -Violations $violations -Format $Format -OutputPath $OutputPath -TotalActions $result.TotalActions
# Export report (pipe to Out-Host to prevent pipeline pollution of return value)
Export-ConsistencyReport -Violations $violations -Format $Format -OutputPath $OutputPath -TotalActions $result.TotalActions | Out-Host

$failed = $false
# Determine exit code
$exitCode = 0

if ($FailOnMismatch -and $mismatchCount -gt 0) {
Write-ConsistencyLog "Failing due to $mismatchCount version mismatch(es) (-FailOnMismatch enabled)" -Level Error
$failed = $true
$exitCode = 1
}

if ($FailOnMissingComment -and $missingCount -gt 0) {
Write-ConsistencyLog "Failing due to $missingCount missing version comment(s) (-FailOnMissingComment enabled)" -Level Error
$failed = $true
$exitCode = 1
}

if ($failed) {
throw 'Version consistency violations detected'
}

if ($violations.Count -eq 0) {
if ($exitCode -eq 0 -and $violations.Count -eq 0) {
Write-ConsistencyLog 'All SHA-pinned actions have consistent version comments!' -Level Success
}

return $exitCode
}

#region Main Execution
if ($MyInvocation.InvocationName -ne '.') {
try {
Invoke-ActionVersionConsistencyCheck -Path $Path -Format $Format -OutputPath $OutputPath -FailOnMismatch:$FailOnMismatch -FailOnMissingComment:$FailOnMissingComment
exit 0
$exitCode = Invoke-ActionVersionConsistency @PSBoundParameters
exit $exitCode
}
catch {
Write-Error -ErrorAction Continue "Test-ActionVersionConsistency failed: $($_.Exception.Message)"
Write-CIAnnotation -Message $_.Exception.Message -Level Error
exit 1
}
}

#endregion Main Execution
5 changes: 5 additions & 0 deletions scripts/tests/dev-tools/Generate-PrReference.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

BeforeAll {
. $PSScriptRoot/../../dev-tools/Generate-PrReference.ps1

}

AfterAll {
Remove-Module CIHelpers -Force -ErrorAction SilentlyContinue
}

Describe 'Test-GitAvailability' {
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/lib/Get-VerifiedDownload.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
BeforeAll {
. $PSScriptRoot/../../lib/Get-VerifiedDownload.ps1
}

Describe 'Get-FileHashValue' {
It 'Returns uppercase hash string for valid file' {
$tempFile = New-TemporaryFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ BeforeAll {

AfterAll {
Restore-CIEnvironment
Remove-Module CIHelpers -Force -ErrorAction SilentlyContinue
}

Describe 'Write-ConsistencyLog' -Tag 'Unit' {
Expand Down
Loading