Skip to content

Commit 12b3e73

Browse files
Update README.md and add SettingsFileDocumentation.md for Invoke-ScriptAnalyzer action
1 parent d6d03ba commit 12b3e73

File tree

3 files changed

+103
-11
lines changed

3 files changed

+103
-11
lines changed

README.md

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,109 @@
1-
# Template-Action
1+
```markdown
2+
# Invoke-ScriptAnalyzer (by PSModule)
23

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.
47

5-
## Usage
8+
> **Note:** This repository includes automated tests that run via Pester to ensure
9+
> your settings file is working as expected.
610
7-
### Inputs
11+
## Action Details
812

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`
1019

11-
### Outputs
20+
## Inputs
1221

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:
1475
1576
```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.
17109
```
File renamed without changes.

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: Test-PSModule (by PSModule)
2-
description: Test a PowerShell module before publishing the module to the PowerShell Gallery.
1+
name: Invoke-ScriptAnalyzer (by PSModule)
2+
description: Runs PSScriptAnalyzer on the code.
33
author: PSModule
44
branding:
55
icon: check-square
@@ -15,7 +15,7 @@ inputs:
1515
required: false
1616
default: 'Custom'
1717
SettingsFilePath:
18-
description: The path to the settings file.
18+
description: If 'Custom' is selected, the path to the settings file.
1919
required: false
2020
default: ${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1
2121

0 commit comments

Comments
 (0)