From 3180b21baa0b7ce13d8ca71bae85ba7957144ab9 Mon Sep 17 00:00:00 2001 From: Jonathan Butler Date: Wed, 20 Nov 2024 15:57:06 -0500 Subject: [PATCH] Change PSScriptAnalyzerSettings.psd1 path to not include GitHub workspace environment variable. --- .github/workflows/psscriptanalyzer.yml | 28 +++++++++++++---------- Hawk/tests/general/Test-PreCommitHook.ps1 | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/psscriptanalyzer.yml b/.github/workflows/psscriptanalyzer.yml index 9e81f1d..3e74dd4 100644 --- a/.github/workflows/psscriptanalyzer.yml +++ b/.github/workflows/psscriptanalyzer.yml @@ -17,7 +17,7 @@ on: jobs: analyze: name: PSScriptAnalyzer - runs-on: windows-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -27,8 +27,13 @@ jobs: run: | Write-Host "Current location: $(Get-Location)" Write-Host "GITHUB_WORKSPACE: $env:GITHUB_WORKSPACE" - Write-Host "Directory contents:" - Get-ChildItem -Path . -Recurse | Select-Object FullName + + $settingsPath = Join-Path $env:GITHUB_WORKSPACE '.github' 'psscriptanalyzer' 'PSScriptAnalyzerSettings.psd1' + Write-Host "Settings path: $settingsPath" + + Write-Host "`nVerifying .github structure:" + Get-ChildItem -Path (Join-Path $env:GITHUB_WORKSPACE '.github') -Recurse | + Select-Object FullName - name: Install PSScriptAnalyzer shell: pwsh @@ -39,21 +44,20 @@ jobs: - name: Run PSScriptAnalyzer shell: pwsh run: | - $settingsPath = "./.github/psscriptanalyzer/PSScriptAnalyzerSettings.psd1" + $settingsPath = Join-Path $env:GITHUB_WORKSPACE '.github' 'psscriptanalyzer' 'PSScriptAnalyzerSettings.psd1' - Write-Host "Looking for settings file..." - Write-Host "Settings path: $settingsPath" - Write-Host "`n.github folder contents:" - Get-ChildItem -Path "./.github" -Recurse | Select-Object FullName - + Write-Host "Using settings file: $settingsPath" if (-not (Test-Path $settingsPath)) { Write-Error "PSScriptAnalyzer settings file not found at: $settingsPath" exit 1 } $results = @() - $files = Get-ChildItem -Path . -Recurse -Include *.ps1,*.psm1,*.psd1 | - Where-Object { $_.FullName -notlike '*\node_modules\*' } + $files = Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Include *.ps1,*.psm1,*.psd1 | + Where-Object { + $_.FullName -notlike '*\node_modules\*' -and + $_.FullName -notlike '*/.git/*' + } foreach ($file in $files) { Write-Host "Analyzing $($file.FullName)" @@ -66,7 +70,7 @@ jobs: if ($results) { Write-Host "Found $($results.Count) issues" $results | Format-Table -AutoSize | Out-String | Write-Host - $results | Format-Table -AutoSize | Out-File psscriptanalyzer-results.txt + $results | Format-Table -AutoSize | Out-File (Join-Path $env:GITHUB_WORKSPACE 'psscriptanalyzer-results.txt') exit 1 } else { Write-Host "No PSScriptAnalyzer issues found" diff --git a/Hawk/tests/general/Test-PreCommitHook.ps1 b/Hawk/tests/general/Test-PreCommitHook.ps1 index 99a3111..bb79a3d 100644 --- a/Hawk/tests/general/Test-PreCommitHook.ps1 +++ b/Hawk/tests/general/Test-PreCommitHook.ps1 @@ -5,7 +5,7 @@ # 3. Observe the PSScriptAnalyzer warnings/errors #region Good Code Examples - These will pass PSScriptAnalyzer -# add comment to tests +# add comment to testss function Test-GoodFunction { [CmdletBinding()] param (