|
1 | | -# Template-Action |
| 1 | +```markdown |
| 2 | +# Invoke-ScriptAnalyzer (by PSModule) |
2 | 3 |
|
3 | | -A template repository for GitHub Actions |
| 4 | +This repository contains a GitHub Action that runs PSScriptAnalyzer on your code. |
| 5 | +The action analyzes PowerShell scripts using a hashtable-based settings file to |
| 6 | +customize rule selection, severity filtering, and custom rule inclusion. |
4 | 7 |
|
5 | | -## Usage |
| 8 | +> **Note:** This repository includes automated tests that run via Pester to ensure |
| 9 | +> your settings file is working as expected. |
6 | 10 |
|
7 | | -### Inputs |
| 11 | +## Action Details |
8 | 12 |
|
9 | | -### Secrets |
| 13 | +- **Name:** Invoke-ScriptAnalyzer (by PSModule) |
| 14 | +- **Description:** Runs PSScriptAnalyzer on the code. |
| 15 | +- **Author:** PSModule |
| 16 | +- **Branding:** |
| 17 | + Icon: `check-square` |
| 18 | + Color: `gray-dark` |
10 | 19 |
|
11 | | -### Outputs |
| 20 | +## Inputs |
12 | 21 |
|
13 | | -### Example |
| 22 | +| Input | Description | Required | Default | |
| 23 | +|---------------------|-------------------------------------------------------------------|----------|-----------------------------------------------------------------------------| |
| 24 | +| **Path** | The path to the code to test. | Yes | `${{ github.workspace }}` | |
| 25 | +| **Settings** | The type of tests to run: `Module`, `SourceCode`, or `Custom`. | No | `Custom` | |
| 26 | +| **SettingsFilePath**| If `Custom` is selected, the path to the settings file. | No | `${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1` | |
| 27 | + |
| 28 | +## Outputs |
| 29 | + |
| 30 | +| Output | Description | Value | |
| 31 | +|---------|---------------------------------------|--------------------------------------------| |
| 32 | +| passed | Indicates if the tests passed. | `${{ steps.test.outputs.Passed }}` | |
| 33 | + |
| 34 | +## Files Overview |
| 35 | + |
| 36 | +- **action.yml** |
| 37 | + Describes the action inputs, outputs, and run steps. The action uses a |
| 38 | + composite run steps approach with two main steps: |
| 39 | + 1. **Get test paths:** Uses a script to resolve paths and settings. |
| 40 | + 2. **Invoke-Pester:** Runs Pester tests against PSScriptAnalyzer. |
| 41 | + |
| 42 | +- **scripts/main.ps1** |
| 43 | + Determines the correct settings file path based on the test type. It |
| 44 | + supports testing a module, source code, or using a custom settings file. |
| 45 | + |
| 46 | +- **scripts/tests/PSScriptAnalyzer/** |
| 47 | + Contains Pester tests that run PSScriptAnalyzer using the provided settings |
| 48 | + file. The tests check for issues reported by PSScriptAnalyzer based on rule |
| 49 | + configuration. |
| 50 | + |
| 51 | +## How It Works |
| 52 | + |
| 53 | +1. **Path Resolution:** |
| 54 | + The action reads inputs and determines the code path, test path, and the |
| 55 | + settings file path. For custom settings, it uses the file at: |
| 56 | + ``` |
| 57 | + .github/linters/.powershell-psscriptanalyzer.psd1 |
| 58 | + ``` |
| 59 | + Otherwise, it uses a default settings file from the test folder. |
| 60 | +
|
| 61 | +2. **Pester Testing:** |
| 62 | + The tests import the settings file and use `Invoke-ScriptAnalyzer` to scan |
| 63 | + the code. Each rule is evaluated, and if a rule violation is found, the test |
| 64 | + will fail for that rule. Rules that are marked to be skipped (via exclusions |
| 65 | + in the settings file) are automatically skipped in the test. |
| 66 | +
|
| 67 | +3. **Automation:** |
| 68 | + Designed for CI/CD, this action integrates with GitHub Actions, Azure Pipelines, |
| 69 | + and other systems. The settings file customizes analysis, letting you control |
| 70 | + rule inclusion, severity filtering, and custom rule paths. |
| 71 | +
|
| 72 | +## Example Workflow |
| 73 | +
|
| 74 | +Below is an example workflow configuration using this action: |
14 | 75 |
|
15 | 76 | ```yaml |
16 | | -Example here |
| 77 | +name: Analyze PowerShell Code |
| 78 | +
|
| 79 | +on: [push, pull_request] |
| 80 | +
|
| 81 | +jobs: |
| 82 | + lint: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v2 |
| 86 | + - name: Invoke PSScriptAnalyzer |
| 87 | + uses: PSModule/Invoke-ScriptAnalyzer@v1 |
| 88 | + with: |
| 89 | + Path: ${{ github.workspace }} |
| 90 | + Settings: Custom |
| 91 | + SettingsFilePath: ${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1 |
| 92 | +``` |
| 93 | + |
| 94 | +## Appendix: Settings File Documentation |
| 95 | + |
| 96 | +For detailed documentation on the format of the settings file, see the |
| 97 | +[Settings File Documentation](./SettingsFileDocumentation.md) file. |
| 98 | + |
| 99 | +## References and Links |
| 100 | + |
| 101 | +- [PSScriptAnalyzer Documentation](https://learn.microsoft.com/powershell/module/psscriptanalyzer/) |
| 102 | +- [GitHub Super-Linter](https://github.com/github/super-linter) |
| 103 | +- [PSScriptAnalyzer GitHub Repository](https://github.com/PowerShell/PSScriptAnalyzer) |
| 104 | +- [Custom Rules in PSScriptAnalyzer](https://docs.microsoft.com/powershell/scripting/developer/hosting/psscriptanalyzer-extensibility) |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +This project is licensed under the MIT License. |
17 | 109 | ``` |
0 commit comments