Skip to content

Commit 276b770

Browse files
🩹 [Patch]: Don't require source code to be in a module folder. (#45)
## Description - Don't require source code in a module folder. - Add param for TestsPath. - Add docs for outputs and TestsPath = 'tests'. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [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 fc14511 commit 276b770

23 files changed

+39
-10
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ The action runs the following the Pester test framework:
1616
- [PSScriptAnalyzer tests](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/readme?view=ps-modules)
1717
- [PSModule framework tests](#psmodule-tests)
1818
- If `TestType` is set to `Module`:
19-
- The module manifest is:
20-
- tested using [Test-ModuleManifest](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest).
21-
- temporarily altered to version `999.0.0` to avoid version conflicts when running for dependencies of the framework.
19+
- The module manifest is tested using [Test-ModuleManifest](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest).
2220
- The module is imported.
2321
- Custom module tests from the `tests` directory in the module repository are run.
2422
- CodeCoverage is calculated.
25-
- The following reports are calculated and uploaded as artifacts:
26-
- Test suite results.
27-
- Code coverage results.
2823
- If `TestType` is set to `SourceCode`:
2924
- The source code is tested with:
3025
- `PSScriptAnalyzer` for best practices, using custom settings.
3126
- `PSModule.SourceCode` for other PSModule standards.
27+
- The action returns a `passed` output that is `true` if all tests pass, else `false`.
28+
- The following reports are calculated and uploaded as artifacts:
29+
- Test suite results.
30+
- Code coverage results.
3231

3332
The action fails if any of the tests fail or it fails to run the tests.
33+
This is mitigated by the `continue-on-error` option in the workflow.
3434

3535
## How to use it
3636

@@ -97,11 +97,18 @@ jobs:
9797

9898
| Name | Description | Required | Default |
9999
| ---- | ----------- | -------- | ------- |
100-
| `Path` | The path to the module to test. | `true` | |
100+
| `Path` | The path to the code to test. | `true` | |
101101
| `TestType` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | |
102102
| `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | |
103+
| `TestsPath` | The path to the tests to run. | `false` | `tests` |
103104
| `Shell` | The shell to use for running the tests. | `false` | `pwsh` |
104105

106+
### Outputs
107+
108+
| Name | Description | Possible values |
109+
| ---- | ----------- | --------------- |
110+
| `passed` | If the tests passed. | `true`, `false` |
111+
105112
## PSModule tests
106113

107114
The [PSModule framework tests](https://github.com/PSModule/Test-PSModule/blob/main/scripts/tests/PSModule/PSModule.Tests.ps1) verifies the following coding practices that the framework enforces:

action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ inputs:
1010
description: The name of the module to test. The name of the repository is used if not specified.
1111
required: false
1212
Path:
13-
description: The path to the module to test.
13+
description: The path to the code to test.
1414
required: true
1515
TestType:
1616
description: The type of tests to run. Can be either 'Module' or 'SourceCode'.
1717
required: true
18+
TestsPath:
19+
description: The path to the tests to run.
20+
required: false
21+
default: tests
1822
Shell:
1923
description: The shell to use for running the tests.
2024
required: false
@@ -35,6 +39,7 @@ runs:
3539
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
3640
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
3741
GITHUB_ACTION_INPUT_TestType: ${{ inputs.TestType }}
42+
GITHUB_ACTION_INPUT_TestsPath: ${{ inputs.TestsPath }}
3843
run: |
3944
# Test-PSModule
4045
$passed = . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose

scripts/helpers/Test-PSModule.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ function Test-PSModule {
1515
# Run module tests.
1616
[Parameter()]
1717
[ValidateSet('SourceCode', 'Module')]
18-
[string] $TestType = 'SourceCode'
18+
[string] $TestType = 'SourceCode',
19+
20+
# Path to the folder where the tests are located.
21+
[Parameter()]
22+
[string] $TestsPath = 'tests'
1923
)
2024

2125
$moduleName = Split-Path -Path $Path -Leaf
2226
$testSourceCode = $TestType -eq 'SourceCode'
2327
$testModule = $TestType -eq 'Module'
24-
$moduleTestsPath = Join-Path $env:GITHUB_WORKSPACE 'tests'
28+
$moduleTestsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $TestsPath
2529

2630
#region Get test kit versions
2731
Start-LogGroup 'Get test kit versions'

scripts/main.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ $moduleName = if ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) { $env:GITHUB_R
1313
Write-Verbose "Module name: [$moduleName]"
1414

1515
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "$env:GITHUB_ACTION_INPUT_Path\$moduleName"
16+
if (Test-Path -Path $codeToTest) {
17+
Write-Verbose "Code to test: [$codeToTest]"
18+
} else {
19+
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path
20+
}
21+
1622
Write-Verbose "Code to test: [$codeToTest]"
1723
if (-not (Test-Path -Path $codeToTest)) {
1824
throw "Path [$codeToTest] does not exist."
1925
}
2026
Write-Verbose "Test type to run: [$env:GITHUB_ACTION_INPUT_TestType]"
2127

28+
$testsPath = $env:GITHUB_ACTION_INPUT_TestsPath
29+
Write-Verbose "Path to tests: [$testsPath]"
30+
if (-not (Test-Path -Path $testsPath)) {
31+
throw "Path [$testsPath] does not exist."
32+
}
33+
2234
Stop-LogGroup
2335

2436
$params = @{
2537
Path = $codeToTest
2638
TestType = $env:GITHUB_ACTION_INPUT_TestType
39+
TestsPath = $testsPath
2740
}
2841
$results = Test-PSModule @params
2942

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)