Skip to content

Commit

Permalink
Test bad results in workflow now that reverted back to yaml workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnybottles committed Nov 26, 2024
1 parent b8a1b26 commit ec01690
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 83 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
$ErrorActionPreference = 'Stop'
$settings = Join-Path (Get-Location) 'Hawk/internal/configurations/PSScriptAnalyzerSettings.psd1'
if ($MyInvocation.ScriptName -eq (Join-Path $PSScriptRoot 'Invoke-PowerShellScriptAnalyzer.ps1')) {
$excludedFiles = @(
'C:\Users\xxbut\code\hawk\Hawk\tests\general\Test-PreCommitHook.ps1'
)

# Define the list of files to exclude
$excludedFiles = @(
'none'
)
$files = git diff --cached --name-only --diff-filter=AM | Where-Object { $_ -match '\.(ps1|psm1|psd1)$' }
$hasErrors = $false

$files = git diff --cached --name-only --diff-filter=AM | Where-Object { $_ -match '\.(ps1|psm1|psd1)$' }
$hasErrors = $false

foreach ($file in $files) {
if ($excludedFiles -notcontains $file) {
Write-Output "Analyzing $file..."
$results = Invoke-ScriptAnalyzer -Path $file -Settings $settings
if ($results) {
$results | Format-Table -AutoSize
$hasErrors = $true
foreach ($file in $files) {
if ($excludedFiles -contains $file) {
Write-Output "Skipping analysis for excluded file: $file"
}
else {
Write-Output "Analyzing $file..."
$results = Invoke-ScriptAnalyzer -Path $file -Settings $settings
if ($results) {
$results | Format-Table -AutoSize
$hasErrors = $true
}
}
}

if ($hasErrors) {
Write-Output "PSScriptAnalyzer found errors. Exiting with error code 1."
exit 1
}
else {
Write-Output "Skipping analysis for excluded file: $file"
Write-Output "No PSScriptAnalyzer issues found. Exiting with code 0."
exit 0
}
}
if ($hasErrors) { exit 1 }
else {
# Original script content
}
11 changes: 6 additions & 5 deletions Hawk/tests/general/Test-PreCommitHook.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# 3. Observe the PSScriptAnalyzer warnings/errors

#region Good Code Examples - These will pass PSScriptAnalyzer
# testssssssss
# test
function Test-GoodFunction {
[CmdletBinding()]
param (
Expand Down Expand Up @@ -52,9 +52,10 @@ function Test-AdvancedFunction {
#region Bad Code Examples - Uncomment to test PSScriptAnalyzer
# NOTE: The following code is intentionally written with issues to demonstrate PSScriptAnalyzer rules

<#

# Bad function - Multiple issues
function test-badfunction { # Wrong capitalization
function test-badfunction {
# Wrong capitalization
param([string]$param1) # Missing CmdletBinding

$Global:badVariable = $param1 # Using global variable
Expand All @@ -77,8 +78,8 @@ function Test-BadValidation {
}

# Aliases and positional parameters
dir C:\ | where {$_.Length -gt 1000} # Using aliases instead of full cmdlet names
#>
dir C:\ | where { $_.Length -gt 1000 } # Using aliases instead of full cmdlet names

#endregion

#region Testing Instructions
Expand Down

0 comments on commit ec01690

Please sign in to comment.