Skip to content

Commit 2d71ec8

Browse files
🩹 [Patch]: Add WorkingDirectory and align naming of internal envvar which are mapped to inputs (#5)
## Description This pull request includes several updates to the workflow configuration files, documentation, and scripts to improve the setup and execution of tests. The most important changes include the addition of a new input parameter `WorkingDirectory`, updates to environment variable names, and corrections to default values and paths. Updates to workflow configuration: * `.github/workflows/Action-Test.yml`: * Added `WorkingDirectory` input parameter and updated `Path` and `SettingsFilePath` values to reflect the new structure. Documentation updates: * `README.md`: * Updated the default value for `Path` and added a description for the new `WorkingDirectory` input parameter. Updates to action inputs: * `action.yml`: * Added `WorkingDirectory` input parameter and updated environment variable names and default values for consistency. Script updates: * `scripts/main.ps1`: * Updated environment variable names to use the new naming convention. * `scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1`: Updated environment variable names to use the new naming convention. ## 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 f0a55ea commit 2d71ec8

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

.github/workflows/Action-Test.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ jobs:
3131
uses: ./
3232
id: action-test
3333
with:
34-
Path: tests/srcTestRepo/src
34+
WorkingDirectory: tests/srcTestRepo
35+
Path: src
3536
Settings: SourceCode
3637

3738
- name: Status
@@ -54,9 +55,10 @@ jobs:
5455
uses: ./
5556
id: action-test
5657
with:
57-
Path: tests/srcTestRepo/src
58+
WorkingDirectory: tests/srcTestRepo
59+
Path: src
5860
Settings: Custom
59-
SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1
61+
SettingsFilePath: tests/Custom.Settings.psd1
6062

6163
- name: Status
6264
shell: pwsh
@@ -79,7 +81,8 @@ jobs:
7981
continue-on-error: true
8082
id: action-test
8183
with:
82-
Path: tests/srcWithManifestTestRepo/src
84+
WorkingDirectory: tests/srcWithManifestTestRepo
85+
Path: src
8386
Settings: SourceCode
8487

8588
- name: Status
@@ -102,7 +105,8 @@ jobs:
102105
uses: ./
103106
id: action-test
104107
with:
105-
Path: tests/outputTestRepo/outputs/modules/PSModuleTest
108+
WorkingDirectory: tests/outputTestRepo
109+
Path: outputs/modules/PSModuleTest
106110
Settings: Module
107111

108112
- name: Status

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ customize rule selection, severity filtering, and custom rule inclusion.
1515

1616
## Inputs
1717

18-
| Input | Description | Required | Default |
19-
|---------------------|----------------------------------------------------------------|----------|-----------------------------------------------------------------------------|
20-
| `Path` | The path to the code to test. | false | `${{ github.workspace }}` |
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` |
23-
| `Debug` | Enable debug output. | false | `'false'` |
24-
| `Verbose` | Enable verbose output. | false | `'false'` |
25-
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
26-
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
18+
| Input | Description | Required | Default |
19+
|--------------------|----------------------------------------------------------------|----------|-----------------------------------------------------------------------------|
20+
| `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` |
23+
| `Debug` | Enable debug output. | false | `'false'` |
24+
| `Verbose` | Enable verbose output. | false | `'false'` |
25+
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
26+
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
27+
| `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` |
2728

2829
## Outputs
2930

action.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ inputs:
99
Path:
1010
description: The path to the code to test.
1111
required: false
12-
default: ${{ github.workspace }}
1312
Settings:
1413
description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'.
1514
required: false
16-
default: 'Custom'
15+
default: Custom
1716
SettingsFilePath:
1817
description: If 'Custom' is selected, the path to the settings file.
1918
required: false
@@ -33,26 +32,32 @@ inputs:
3332
description: Allow prerelease versions if available.
3433
required: false
3534
default: 'false'
35+
WorkingDirectory:
36+
description: The working directory where the script will run from.
37+
required: false
38+
default: ${{ github.workspace }}
3639

3740
runs:
3841
using: composite
3942
steps:
40-
- name: Get test paths
43+
- name: Get-TestPaths
4144
uses: PSModule/Github-Script@v1
4245
id: paths
4346
env:
44-
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Path: ${{ inputs.Path }}
45-
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Settings: ${{ inputs.Settings }}
46-
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath: ${{ inputs.SettingsFilePath }}
47+
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path: ${{ inputs.Path }}
48+
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings: ${{ inputs.Settings }}
49+
PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath: ${{ inputs.SettingsFilePath }}
4750
with:
4851
Debug: ${{ inputs.Debug }}
4952
Prerelease: ${{ inputs.Prerelease }}
5053
Verbose: ${{ inputs.Verbose }}
5154
Version: ${{ inputs.Version }}
55+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
5256
Script: ${{ github.action_path }}/scripts/main.ps1
5357

5458
- name: Invoke-Pester
55-
uses: PSModule/Invoke-Pester@v3
59+
# uses: PSModule/Invoke-Pester@v3
60+
uses: PSModule/Invoke-Pester@fixCOntainerEval
5661
id: test
5762
env:
5863
Settings: ${{ fromJson(steps.paths.outputs.result).Settings }}
@@ -62,6 +67,7 @@ runs:
6267
Prerelease: ${{ inputs.Prerelease }}
6368
Verbose: ${{ inputs.Verbose }}
6469
Version: ${{ inputs.Version }}
70+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
6571
TestResult_TestSuiteName: PSScriptAnalyzer
6672
Path: ${{ github.action_path }}/scripts/tests/PSScriptAnalyzer
67-
Run_Path: ${{ inputs.Path }}
73+
Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }}

scripts/main.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# 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:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Settings
2+
$settings = $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings
33
$testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-Object -ExpandProperty Path
4-
$codePath = Resolve-Path -Path $env:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Path | Select-Object -ExpandProperty Path
4+
$codePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path | Select-Object -ExpandProperty Path
55
$settingsFilePath = switch -Regex ($settings) {
66
'Module|SourceCode' {
77
"$testPath/$settings.Settings.psd1"
88
}
99
'Custom' {
10-
Resolve-Path -Path "$env:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath" | Select-Object -ExpandProperty Path
10+
Resolve-Path -Path "$env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath" | Select-Object -ExpandProperty Path
1111
}
1212
default {
1313
throw "Invalid test type: [$settings]"

scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@{
22
Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName
33
Data = @{
4-
Path = $env:GITHUB_ACTION_INPUT_Run_Path
4+
Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path
55
SettingsFilePath = $env:SettingsFilePath
66
Debug = $false
77
Verbose = $false

0 commit comments

Comments
 (0)