Skip to content

Commit

Permalink
Add psscriptanalyzer.yml to separate pester tests (validate.yml) from…
Browse files Browse the repository at this point in the history
… psscriptanalyzer tests.
  • Loading branch information
jonnybottles committed Nov 19, 2024
1 parent e8cd220 commit a231fea
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/psscriptanalzyer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PSScriptAnalyzer
on:
pull_request:
paths:
- "**.ps1"
- "**.psm1"
- "**.psd1"
push:
branches:
- main
- Development
- "feature/144-implement-dual-validation-psscriptanalyzer-with-standardized-settings"
paths:
- "**.ps1"
- "**.psm1"
- "**.psd1"

jobs:
analyze:
name: PSScriptAnalyzer
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
$settings = Join-Path $env:GITHUB_WORKSPACE '.github/psscriptanalyzer/PSScriptAnalyzerSettings.psd1'
$results = @()
# Analyze all PowerShell files
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Include *.ps1,*.psm1,*.psd1 |
ForEach-Object {
$analysis = Invoke-ScriptAnalyzer -Path $_.FullName -Settings $settings
if ($analysis) {
$results += $analysis
}
}
# Output results
if ($results) {
$results | Format-Table -AutoSize
Write-Output "::error::PSScriptAnalyzer found $($results.Count) issues"
exit 1
} else {
Write-Output "No PSScriptAnalyzer issues found"
}
- name: Upload PSScriptAnalyzer Results
if: failure()
uses: actions/upload-artifact@v3
with:
name: psscriptanalyzer-results
path: psscriptanalyzer-results.txt
1 change: 1 addition & 0 deletions Hawk/tests/general/Test-PreCommitHook.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# 3. Observe the PSScriptAnalyzer warnings/errors

#region Good Code Examples - These will pass PSScriptAnalyzer
# add comement to test
function Test-GoodFunction {
[CmdletBinding()]
param (
Expand Down

0 comments on commit a231fea

Please sign in to comment.