A comprehensive PowerShell code quality framework with custom rules, automated testing, and GitHub Actions integration.
This repository provides custom PSScriptAnalyzer rules, test automation, and CI/CD integration to ensure consistent PowerShell code quality across Sky Ledger projects. It enforces Sky Ledger coding standards and best practices through automated analysis and testing.
Prerequisites: PowerShell 5.1+, PSScriptAnalyzer, Pester v5.0+
# Clone and setup
git clone https://github.com/Sky-Ledger/powershell-script-analyzer.git
cd powershell-script-analyzer
# Install modules
Install-Module -Name PSScriptAnalyzer, Pester -Force
# Run analysis
.\Invoke-PSScriptAnalyzer.ps1 -Path ".\path-to-files"
# Run tests
.\tests\Invoke-PesterTests.ps1rules/- Custom PSScriptAnalyzer rules enforcing Sky Ledger standardsscripts/- Utility scripts for environment validation and setuptests/- Comprehensive Pester test suite with rule validationInvoke-PSScriptAnalyzer.ps1- Main analyzer script with custom rulesPSScriptAnalyzer.Settings.psd1- Configuration for built-in and custom rules (now points to00-Custom.Rules.psm1).github/workflows/- Automated CI/CD quality checks.github/copilot-instructions.md- Instructions for GitHub Copilot on project-specifics.
# Analyze files/directories
.\Invoke-PSScriptAnalyzer.ps1 -Path ".\scripts"
.\Invoke-PSScriptAnalyzer.ps1 -Path ".\MyScript.ps1" -Quiet
# Run tests
.\tests\Invoke-PesterTests.ps1
# Validate environment
.\scripts\Test-WorkflowCompatibility.ps1PSScriptAnalyzer.Settings.psd1 configures built-in rules, custom Sky Ledger rules, and severity levels.
GitHub Actions automatically run quality checks on pull requests and main branch pushes.
Adding Rules: Create rule file in rules/, write tests in tests/
Local Testing: Run .\scripts\Test-WorkflowCompatibility.ps1 and .\tests\Invoke-PesterTests.ps1
CI/CD: GitHub Actions automatically validates all changes with full test suite
- Consistent Standards - Enforces Sky Ledger PowerShell coding practices
- Automated Testing - CI/CD integration with comprehensive test coverage
- Cross-Platform - Windows PowerShell 5.1+ and PowerShell Core 7.0+
- Rich Diagnostics - Color-coded output with detailed error messages
- Fork and create feature branch
- Follow PowerShell best practices (strict mode, error handling, comment-based help)
- Add comprehensive Pester tests for new rules
- Run validation:
.\scripts\Test-WorkflowCompatibility.ps1and.\tests\Invoke-PesterTests.ps1
- PowerShell 5.1+ or PowerShell Core 7.0+
- PSScriptAnalyzer and Pester modules
- Git
Module Issues: Install-Module -Name PSScriptAnalyzer, Pester -Force
Test Failures: .\tests\Invoke-PesterTests.ps1 -Verbose
Help: Get-Help .\Invoke-PSScriptAnalyzer.ps1 -Detailed
Understanding script exit codes for CI/CD integration:
| Exit Code | Meaning | Action Required |
|---|---|---|
0 |
Success - No issues found | ✅ Continue pipeline |
1 |
Analysis issues found | ❌ Fix code quality issues |
2 |
Invalid path or file type | ❌ Check file paths |
3 |
PSScriptAnalyzer module missing | ❌ Install required modules |
4 |
Settings file issues | ❌ Fix configuration |
The analyzer supports:
- Built-in Rules: Complete set of Microsoft's PSScriptAnalyzer rules
- Custom Rules: Sky Ledger specific coding standards and practices
- File Types:
.ps1,.psm1,.psd1 - Cross-Platform: Windows PowerShell 5.1+ and PowerShell Core 7.0+
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the Sky Ledger Team