Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
id: action-test
with:
Path: src
Settings: SourceCode
WorkingDirectory: tests/srcTestRepo

- name: Status
Expand All @@ -56,7 +55,6 @@ jobs:
id: action-test
with:
Path: src
Settings: Custom
SettingsFilePath: tests/Custom.Settings.psd1
WorkingDirectory: tests/srcTestRepo

Expand All @@ -82,7 +80,7 @@ jobs:
id: action-test
with:
Path: src
Settings: SourceCode
SettingsFilePath: tests/SourceCode.Settings.psd1
WorkingDirectory: tests/srcWithManifestTestRepo

- name: Status
Expand All @@ -106,7 +104,6 @@ jobs:
id: action-test
with:
Path: outputs/modules/PSModuleTest
Settings: Module
WorkingDirectory: tests/outputTestRepo

- name: Status
Expand Down
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ customize rule selection, severity filtering, and custom rule inclusion.
| Input | Description | Required | Default |
|--------------------------------------|--------------------------------------------------------------------------------|----------|-----------------------------------------------------------------------------|
| `Path` | The path to the code to test. | false | `'.'` |
| `Settings` | The type of tests to run: `Module`, `SourceCode`, or `Custom`. | false | `Custom` |
| `SettingsFilePath` | If `Custom` is selected, the path to the settings file. | false | `${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1` |
| `SettingsFilePath` | The path to the settings file. | false | `.github/linters/.powershell-psscriptanalyzer.psd1` |
| `Debug` | Enable debug output. | false | `'false'` |
| `Verbose` | Enable verbose output. | false | `'false'` |
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
Expand Down Expand Up @@ -89,19 +88,18 @@ The action provides the following outputs:
Choose a path for your code to test into the `Path` input. This can be a
directory or a file.

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

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

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

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

3. **Run the Action**
The tests import the settings file and use `Invoke-ScriptAnalyzer` to analyze
Expand Down Expand Up @@ -139,7 +137,7 @@ jobs:
uses: PSModule/Invoke-ScriptAnalyzer@v2
with:
Path: src
Settings: SourceCode
SettingsFilePath: .github/linters/.powershell-psscriptanalyzer.psd1
```

## References and Links
Expand Down
10 changes: 2 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ inputs:
Path:
description: The path to the code to test.
required: false
Settings:
description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'.
required: false
default: Custom
SettingsFilePath:
description: If 'Custom' is selected, the path to the settings file.
description: The path to the settings file.
required: false
default: ${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1
default: .github/linters/.powershell-psscriptanalyzer.psd1
Debug:
description: Enable debug output.
required: false
Expand Down Expand Up @@ -251,7 +247,6 @@ runs:
id: paths
env:
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path: ${{ inputs.Path }}
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings: ${{ inputs.Settings }}
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath: ${{ inputs.SettingsFilePath }}
with:
Debug: ${{ inputs.Debug }}
Expand All @@ -265,7 +260,6 @@ runs:
uses: PSModule/Invoke-Pester@v4
id: test
env:
Settings: ${{ fromJson(steps.paths.outputs.result).Settings }}
SettingsFilePath: ${{ fromJson(steps.paths.outputs.result).SettingsFilePath }}
with:
Debug: ${{ inputs.Debug }}
Expand Down
20 changes: 5 additions & 15 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
# If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder.
$settings = $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings
# Resolve paths for testing
$testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-Object -ExpandProperty Path
$path = [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path) ? '.' : $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path
$codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path
$settingsFilePath = switch -Regex ($settings) {
'Module|SourceCode' {
"$testPath/$settings.Settings.psd1"
}
'Custom' {
Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath | Select-Object -ExpandProperty Path
}
default {
throw "Invalid test type: [$settings]"
}
}
$settingsFilePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath | Select-Object -ExpandProperty Path

[pscustomobject]@{
Settings = $settings
CodePath = $codePath
TestPath = $testPath
SettingsFilePath = $settingsFilePath
} | Format-List | Out-String

Set-GitHubOutput -Name Settings -Value $settings
if (!(Test-Path -Path $settingsFilePath)) {
throw "Settings file not found at path: $settingsFilePath"
}
Set-GitHubOutput -Name CodePath -Value $codePath
Set-GitHubOutput -Name TestPath -Value $testPath
Set-GitHubOutput -Name SettingsFilePath -Value $settingsFilePath
56 changes: 56 additions & 0 deletions tests/srcWithManifestTestRepo/tests/SourceCode.Settings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@{
Rules = @{
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
PSAvoidLongLines = @{
Enable = $true
MaximumLineLength = 150
}
PSAvoidSemicolonsAsLineTerminators = @{
Enable = $true
}
PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $false
IgnoreOneLineBlock = $true
NoEmptyLineBefore = $false
}
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $true
}
PSProvideCommentHelp = @{
Enable = $true
ExportedOnly = $false
BlockComment = $true
VSCodeSnippetCorrection = $false
Placement = 'begin'
}
PSUseConsistentIndentation = @{
Enable = $true
IndentationSize = 4
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
Kind = 'space'
}
PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $true
CheckOpenParen = $true
CheckOperator = $true
CheckPipe = $true
CheckPipeForRedundantWhitespace = $true
CheckSeparator = $true
CheckParameter = $true
IgnoreAssignmentOperatorInsideHashTable = $true
}
}
ExcludeRules = @(
'PSMissingModuleManifestField', # This rule is not applicable until the module is built.
'PSUseToExportFieldsInManifest'
)
}
Loading