Create main.yml #1
This file contains hidden or 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: PowerShell Script Validator | |
| # 1. TRIGGER: | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| # 2. JOBS: | |
| jobs: | |
| lint-scripts: | |
| name: Analyze PowerShell Code | |
| # Spin up a fresh Windows virtual machine | |
| runs-on: windows-latest | |
| # 3. STEPS: tasks to execute | |
| steps: | |
| # Step A: Download repo code | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| # Step B: Run Posh | |
| - name: Run PSScriptAnalyzer | |
| shell: pwsh | |
| run: | | |
| Write-Host "Installing PSScriptAnalyzer..." | |
| Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser | |
| Write-Host "Scanning repository for PowerShell scripts..." | |
| $results = Invoke-ScriptAnalyzer -Path . -Recurse | |
| if ($results) { | |
| $results | Format-Table -AutoSize | |
| Write-Error "Syntax issues or best-practice violations found!" | |
| exit 1 # This tells GitHub to mark the pipeline as FAILED | |
| } else { | |
| Write-Host "Success! All scripts look good." | |
| } |