Test workflow by separating PSSA workflow PowerShell code into its ow… #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | |
with: | |
fetch-depth: 0 # Required for getting changed files | |
- name: Get changed files | |
shell: pwsh | |
run: | | |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') { | |
$baseCommit = git rev-parse $env:GITHUB_EVENT.pull_request.base.sha | |
$headCommit = git rev-parse HEAD | |
$changedFiles = git diff --name-only $baseCommit..$headCommit | |
} else { | |
$changedFiles = git diff --name-only HEAD^1 HEAD | |
} | |
$powershellFiles = $changedFiles | Where-Object { | |
$_ -match '\.(ps1|psm1|psd1)$' | |
} | |
$powershellFiles | Out-File -FilePath $env:GITHUB_WORKSPACE/changed_files.txt | |
Write-Host "Changed PowerShell files:" | |
$powershellFiles | ForEach-Object { Write-Host " $_" } | |
- name: Install PSScriptAnalyzer | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module PSScriptAnalyzer -Force | |
- name: Run PSScriptAnalyzer | |
shell: pwsh | |
run: | | |
$settingsPath = Join-Path $env:GITHUB_WORKSPACE 'Hawk' 'internal' 'configurations' 'PSScriptAnalyzerSettings.psd1' | |
$changedFiles = Get-Content -Path "$env:GITHUB_WORKSPACE/changed_files.txt" | |
$scriptPath = Join-Path $env:GITHUB_WORKSPACE 'Hawk' 'internal' 'scripts' 'git_hub_action_scripts' 'Invoke-PowerShellScriptAnalyzer.ps1' | |
. $scriptPath -SettingsPath $settingsPath -ChangedFiles $changedFiles | |
- name: Upload Results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: psscriptanalyzer-results | |
path: psscriptanalyzer-results.txt | |
if-no-files-found: warn |