Skip to content

Commit 1783982

Browse files
🌟[Major]: Remove Settings with predefined settings (#18)
## Description This pull request simplifies the configuration of the script analyzer action by removing the `Settings` input (which previously allowed selecting between `Module`, `SourceCode`, or `Custom` modes) in favor of always using a `SettingsFilePath`. Documentation, workflow, and implementation are updated to reflect this streamlined approach. Additionally, a new example settings file for source code analysis is added for clarity. **Configuration and API Simplification:** - Removed the `Settings` input from `action.yml`, the workflow, and environment variables, so users now always specify a `SettingsFilePath` for analyzer configuration. The default settings file path is now `.github/linters/.powershell-psscriptanalyzer.psd1`. [[1]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L12-R15) [[2]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L254) [[3]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L268) [[4]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L35) [[5]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L59) [[6]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L85-R83) [[7]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L109) **Documentation Updates:** - Updated `README.md` to remove references to the old `Settings` input and predefined settings types, clarifying that users should provide a settings file via `SettingsFilePath`. Usage instructions and examples are revised accordingly. [[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L21-R21) [[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L92-R100) [[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L142-R140) **Implementation Changes:** - Refactored `scripts/main.ps1` to resolve only the `SettingsFilePath` and validate its existence, removing all logic related to the `Settings` input and its switch statement. **Test and Example Improvements:** - Added a new `tests/srcWithManifestTestRepo/tests/SourceCode.Settings.psd1` file containing example analyzer rules for source code analysis. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c1d451e commit 1783982

File tree

7 files changed

+75
-40
lines changed

7 files changed

+75
-40
lines changed

.github/workflows/Action-Test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
id: action-test
3333
with:
3434
Path: src
35-
Settings: SourceCode
3635
WorkingDirectory: tests/srcTestRepo
3736

3837
- name: Status
@@ -56,7 +55,6 @@ jobs:
5655
id: action-test
5756
with:
5857
Path: src
59-
Settings: Custom
6058
SettingsFilePath: tests/Custom.Settings.psd1
6159
WorkingDirectory: tests/srcTestRepo
6260

@@ -82,7 +80,7 @@ jobs:
8280
id: action-test
8381
with:
8482
Path: src
85-
Settings: SourceCode
83+
SettingsFilePath: tests/SourceCode.Settings.psd1
8684
WorkingDirectory: tests/srcWithManifestTestRepo
8785

8886
- name: Status
@@ -106,7 +104,6 @@ jobs:
106104
id: action-test
107105
with:
108106
Path: outputs/modules/PSModuleTest
109-
Settings: Module
110107
WorkingDirectory: tests/outputTestRepo
111108

112109
- name: Status

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ customize rule selection, severity filtering, and custom rule inclusion.
1818
| Input | Description | Required | Default |
1919
|--------------------------------------|--------------------------------------------------------------------------------|----------|-----------------------------------------------------------------------------|
2020
| `Path` | The path to the code to test. | false | `'.'` |
21-
| `Settings` | The type of tests to run: `Module`, `SourceCode`, or `Custom`. | false | `Custom` |
22-
| `SettingsFilePath` | If `Custom` is selected, the path to the settings file. | false | `${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1` |
21+
| `SettingsFilePath` | The path to the settings file. | false | `.github/linters/.powershell-psscriptanalyzer.psd1` |
2322
| `Debug` | Enable debug output. | false | `'false'` |
2423
| `Verbose` | Enable verbose output. | false | `'false'` |
2524
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
@@ -89,19 +88,18 @@ The action provides the following outputs:
8988
Choose a path for your code to test into the `Path` input. This can be a
9089
directory or a file.
9190

92-
2. **Choose settings**
93-
Choose the type of tests to run by setting the `Settings` input. The options
94-
are `Module`, `SourceCode`, or `Custom`. The default is `Custom`.
91+
2. **Configure settings file**
92+
Create a custom settings file to customize the analysis. The settings file is
93+
a hashtable that defines the rules to include, exclude, or customize. The
94+
settings file is in the format of a `.psd1` file.
9595

96-
The predefined settings:
97-
- [`Module`](./scripts/tests/PSScriptAnalyzer/Module.Settings.psd1): Analyzes a module following PSModule standards.
98-
- [`SourceCode`](./scripts/tests/PSScriptAnalyzer/SourceCode.Settings.psd1): Analyzes the source code following PSModule standards.
96+
By default, the action looks for a settings file at:
97+
`.github/linters/.powershell-psscriptanalyzer.psd1`
9998

100-
You can also create a custom settings file to customize the analysis. The
101-
settings file is a hashtable that defines the rules to include, exclude, or
102-
customize. The settings file is in the format of a `.psd1` file.
99+
You can override this by setting the `SettingsFilePath` input to point to your
100+
custom settings file.
103101

104-
For more info on how to create a settings file, see the [Settings Documentation](./Settings.md) file.
102+
For more info on how to create a settings file, see the [Settings Documentation](./Settings.md) file.
105103

106104
3. **Run the Action**
107105
The tests import the settings file and use `Invoke-ScriptAnalyzer` to analyze
@@ -139,7 +137,7 @@ jobs:
139137
uses: PSModule/Invoke-ScriptAnalyzer@v2
140138
with:
141139
Path: src
142-
Settings: SourceCode
140+
SettingsFilePath: .github/linters/.powershell-psscriptanalyzer.psd1
143141
```
144142
145143
## References and Links

action.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ inputs:
99
Path:
1010
description: The path to the code to test.
1111
required: false
12-
Settings:
13-
description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'.
14-
required: false
15-
default: Custom
1612
SettingsFilePath:
17-
description: If 'Custom' is selected, the path to the settings file.
13+
description: The path to the settings file.
1814
required: false
19-
default: ${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1
15+
default: .github/linters/.powershell-psscriptanalyzer.psd1
2016
Debug:
2117
description: Enable debug output.
2218
required: false
@@ -251,7 +247,6 @@ runs:
251247
id: paths
252248
env:
253249
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path: ${{ inputs.Path }}
254-
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings: ${{ inputs.Settings }}
255250
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath: ${{ inputs.SettingsFilePath }}
256251
with:
257252
Debug: ${{ inputs.Debug }}
@@ -265,7 +260,6 @@ runs:
265260
uses: PSModule/Invoke-Pester@v4
266261
id: test
267262
env:
268-
Settings: ${{ fromJson(steps.paths.outputs.result).Settings }}
269263
SettingsFilePath: ${{ fromJson(steps.paths.outputs.result).SettingsFilePath }}
270264
with:
271265
Debug: ${{ inputs.Debug }}

scripts/main.ps1

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
# If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder.
2-
$settings = $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings
1+
# Resolve paths for testing
32
$testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-Object -ExpandProperty Path
43
$path = [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path) ? '.' : $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path
54
$codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path
6-
$settingsFilePath = switch -Regex ($settings) {
7-
'Module|SourceCode' {
8-
"$testPath/$settings.Settings.psd1"
9-
}
10-
'Custom' {
11-
Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath | Select-Object -ExpandProperty Path
12-
}
13-
default {
14-
throw "Invalid test type: [$settings]"
15-
}
16-
}
5+
$settingsFilePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath | Select-Object -ExpandProperty Path
176

187
[pscustomobject]@{
19-
Settings = $settings
208
CodePath = $codePath
219
TestPath = $testPath
2210
SettingsFilePath = $settingsFilePath
2311
} | Format-List | Out-String
2412

25-
Set-GitHubOutput -Name Settings -Value $settings
13+
if (!(Test-Path -Path $settingsFilePath)) {
14+
throw "Settings file not found at path: $settingsFilePath"
15+
}
2616
Set-GitHubOutput -Name CodePath -Value $codePath
2717
Set-GitHubOutput -Name TestPath -Value $testPath
2818
Set-GitHubOutput -Name SettingsFilePath -Value $settingsFilePath

scripts/tests/PSScriptAnalyzer/Module.Settings.psd1 renamed to tests/outputTestRepo/.github/linters/.powershell-psscriptanalyzer.psd1

File renamed without changes.

scripts/tests/PSScriptAnalyzer/SourceCode.Settings.psd1 renamed to tests/srcTestRepo/.github/linters/.powershell-psscriptanalyzer.psd1

File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@{
2+
Rules = @{
3+
PSAlignAssignmentStatement = @{
4+
Enable = $true
5+
CheckHashtable = $true
6+
}
7+
PSAvoidLongLines = @{
8+
Enable = $true
9+
MaximumLineLength = 150
10+
}
11+
PSAvoidSemicolonsAsLineTerminators = @{
12+
Enable = $true
13+
}
14+
PSPlaceCloseBrace = @{
15+
Enable = $true
16+
NewLineAfter = $false
17+
IgnoreOneLineBlock = $true
18+
NoEmptyLineBefore = $false
19+
}
20+
PSPlaceOpenBrace = @{
21+
Enable = $true
22+
OnSameLine = $true
23+
NewLineAfter = $true
24+
IgnoreOneLineBlock = $true
25+
}
26+
PSProvideCommentHelp = @{
27+
Enable = $true
28+
ExportedOnly = $false
29+
BlockComment = $true
30+
VSCodeSnippetCorrection = $false
31+
Placement = 'begin'
32+
}
33+
PSUseConsistentIndentation = @{
34+
Enable = $true
35+
IndentationSize = 4
36+
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
37+
Kind = 'space'
38+
}
39+
PSUseConsistentWhitespace = @{
40+
Enable = $true
41+
CheckInnerBrace = $true
42+
CheckOpenBrace = $true
43+
CheckOpenParen = $true
44+
CheckOperator = $true
45+
CheckPipe = $true
46+
CheckPipeForRedundantWhitespace = $true
47+
CheckSeparator = $true
48+
CheckParameter = $true
49+
IgnoreAssignmentOperatorInsideHashTable = $true
50+
}
51+
}
52+
ExcludeRules = @(
53+
'PSMissingModuleManifestField', # This rule is not applicable until the module is built.
54+
'PSUseToExportFieldsInManifest'
55+
)
56+
}

0 commit comments

Comments
 (0)