Skip to content

Commit eaf82d0

Browse files
Remove Settings with predefined settings
1 parent c1d451e commit eaf82d0

File tree

7 files changed

+76
-39
lines changed

7 files changed

+76
-39
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.workspace }}/.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.workspace }}/.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: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
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-
}
5+
$settingsFilePath = Join-Path -Path $codePath -ChildPath $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath
6+
7+
if (!(Test-Path -Path $settingsFilePath)) {
8+
Write-Error "Settings file not found at path: $settingsFilePath"
9+
exit 1
1610
}
1711

1812
[pscustomobject]@{
19-
Settings = $settings
2013
CodePath = $codePath
2114
TestPath = $testPath
2215
SettingsFilePath = $settingsFilePath
2316
} | Format-List | Out-String
2417

25-
Set-GitHubOutput -Name Settings -Value $settings
2618
Set-GitHubOutput -Name CodePath -Value $codePath
2719
Set-GitHubOutput -Name TestPath -Value $testPath
2820
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)