Skip to content

Commit b82e76a

Browse files
🚀 [Feature]: Add Shell parameter (#28)
## Description - Add `Shell` parameter, as a preparation to test on `powershell` and `pwsh`. - Compatibility update for PS5.1. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 19bc279 commit b82e76a

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

.github/workflows/Action-Test.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.eve
55
on: [pull_request]
66

77
jobs:
8-
ActionTestSrc:
8+
ActionTest:
99
strategy:
1010
fail-fast: false
1111
matrix:
12+
shell: [pwsh]
13+
os: [ubuntu-latest, macos-latest, windows-latest]
1214
path: [tests/src, tests/outputs/modules]
13-
name: Action-Test - [${{ matrix.path }}]
14-
runs-on: ubuntu-latest
15+
include:
16+
- shell: powershell
17+
os: windows-latest
18+
path: tests/src
19+
- shell: powershell
20+
os: windows-latest
21+
path: tests/outputs/modules
22+
name: Action-Test - [${{ matrix.os }}@${{ matrix.shell }}] - [${{ matrix.path }}]
23+
runs-on: ${{ matrix.os }}
1524
steps:
1625
- name: Checkout repo
1726
uses: actions/checkout@v4
@@ -24,6 +33,8 @@ jobs:
2433

2534
- name: Initialize environment
2635
uses: PSModule/Initialize-PSModule@main
36+
with:
37+
Shell: ${{ matrix.shell }}
2738

2839
- name: Action-Test
2940
uses: ./
@@ -32,3 +43,4 @@ jobs:
3243
with:
3344
Name: PSModule
3445
Path: ${{ matrix.path }}
46+
Shell: ${{ matrix.shell }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
| `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | |
9191
| `Path` | The path to the module to test. | `true` | |
9292
| `RunModuleTests` | Run the module tests. | `false` | `true` |
93+
| `Shell` | The shell to use for running the tests. | `false` | `pwsh` |
9394

9495
## PSModule tests
9596

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ inputs:
1616
description: Run the module tests.
1717
required: false
1818
default: 'true'
19+
Shell:
20+
description: The shell to use for running the tests.
21+
required: false
22+
default: pwsh
1923

2024
runs:
2125
using: composite
2226
steps:
2327
- name: Run Test-PSModule
24-
shell: pwsh
28+
shell: ${{ inputs.Shell }}
2529
env:
2630
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
2731
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}

scripts/helpers/Test-PSModule.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Test-PSModule {
3434
#region Add test - Common - PSScriptAnalyzer
3535
Start-LogGroup 'Add test - Common - PSScriptAnalyzer'
3636
$containers = @()
37-
$PSSATestsPath = Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts' 'tests' 'PSScriptAnalyzer'
37+
$PSSATestsPath = Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts\tests\PSScriptAnalyzer'
3838
$containerParams = @{
3939
Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1'
4040
Data = @{
@@ -50,7 +50,7 @@ function Test-PSModule {
5050

5151
#region Add test - Common - PSModule
5252
Start-LogGroup 'Add test - Common - PSModule'
53-
$PSModuleTestsPath = Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts' 'tests' 'PSModule'
53+
$PSModuleTestsPath = Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts\tests\PSModule'
5454
$containerParams = @{
5555
Path = $PSModuleTestsPath
5656
Data = @{
@@ -90,8 +90,8 @@ function Test-PSModule {
9090
if ((Test-Path -Path $moduleTestsPath) -and $RunModuleTests) {
9191
Start-LogGroup "Importing module: $moduleName"
9292
Add-PSModulePath -Path (Split-Path $Path -Parent)
93-
Remove-Module -Name $moduleName -ErrorAction SilentlyContinue -Force
94-
Import-Module $Path -Force
93+
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force -Verbose:$false
94+
Import-Module -Name $moduleName -Force
9595
Stop-LogGroup
9696
}
9797
#endregion

scripts/main.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
param()
55

66
Start-LogGroup 'Loading helper scripts'
7-
Get-ChildItem -Path (Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts' 'helpers') -Filter '*.ps1' -Recurse |
7+
Get-ChildItem -Path (Join-Path -Path $env:GITHUB_ACTION_PATH -ChildPath 'scripts\helpers') -Filter '*.ps1' -Recurse |
88
ForEach-Object { Write-Verbose "[$($_.FullName)]"; . $_.FullName }
99
Stop-LogGroup
1010

1111
Start-LogGroup 'Loading inputs'
12-
$moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
12+
$moduleName = if ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) { $env:GITHUB_REPOSITORY_NAME } else { $env:GITHUB_ACTION_INPUT_Name }
1313
Write-Verbose "Module name: [$moduleName]"
1414

15-
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path $moduleName
15+
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "$env:GITHUB_ACTION_INPUT_Path\$moduleName"
1616
Write-Verbose "Code to test: [$codeToTest]"
1717
if (-not (Test-Path -Path $codeToTest)) {
1818
throw "Path [$codeToTest] does not exist."
@@ -23,7 +23,7 @@ Write-Verbose "Run module tests: [$runModuleTests]"
2323
Stop-LogGroup
2424

2525
$params = @{
26-
Path = $codeToTest
26+
Path = $codeToTest
2727
RunModuleTests = $runModuleTests
2828
}
2929
$results = Test-PSModule @params

scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ Param(
2020
)
2121

2222
BeforeDiscovery {
23-
$rules = Get-ScriptAnalyzerRule | Sort-Object -Property Severity | ConvertTo-Json | ConvertFrom-Json -AsHashtable
23+
$rules = @()
24+
$ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity
25+
foreach ($ruleObject in $ruleObjects) {
26+
$hashTable = @{}
27+
foreach ($property in $ruleObject.PSObject.Properties) {
28+
$hashTable[$property.Name] = $property.Value
29+
}
30+
$rules += $hashTable
31+
}
2432
Write-Warning "Discovered [$($rules.Count)] rules"
2533
$relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/')
2634
}

0 commit comments

Comments
 (0)