Skip to content

🩹 [Patch]: Add WorkingDirectory and align naming of internal envvar which are mapped to inputs #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 27, 2025
Merged
14 changes: 9 additions & 5 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
uses: ./
id: action-test
with:
Path: tests/srcTestRepo/src
WorkingDirectory: tests/srcTestRepo
Path: src
Settings: SourceCode

- name: Status
Expand All @@ -54,9 +55,10 @@ jobs:
uses: ./
id: action-test
with:
Path: tests/srcTestRepo/src
WorkingDirectory: tests/srcTestRepo
Path: src
Settings: Custom
SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1
SettingsFilePath: tests/Custom.Settings.psd1

- name: Status
shell: pwsh
Expand All @@ -79,7 +81,8 @@ jobs:
continue-on-error: true
id: action-test
with:
Path: tests/srcWithManifestTestRepo/src
WorkingDirectory: tests/srcWithManifestTestRepo
Path: src
Settings: SourceCode

- name: Status
Expand All @@ -102,7 +105,8 @@ jobs:
uses: ./
id: action-test
with:
Path: tests/outputTestRepo/outputs/modules/PSModuleTest
WorkingDirectory: tests/outputTestRepo
Path: outputs/modules/PSModuleTest
Settings: Module

- name: Status
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ customize rule selection, severity filtering, and custom rule inclusion.

## Inputs

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

## Outputs

Expand Down
22 changes: 14 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ inputs:
Path:
description: The path to the code to test.
required: false
default: ${{ github.workspace }}
Settings:
description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'.
required: false
default: 'Custom'
default: Custom
SettingsFilePath:
description: If 'Custom' is selected, the path to the settings file.
required: false
Expand All @@ -33,26 +32,32 @@ inputs:
description: Allow prerelease versions if available.
required: false
default: 'false'
WorkingDirectory:
description: The working directory where the script will run from.
required: false
default: ${{ github.workspace }}

runs:
using: composite
steps:
- name: Get test paths
- name: Get-TestPaths
uses: PSModule/Github-Script@v1
id: paths
env:
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Path: ${{ inputs.Path }}
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Settings: ${{ inputs.Settings }}
GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath: ${{ inputs.SettingsFilePath }}
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 }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
Script: ${{ github.action_path }}/scripts/main.ps1

- name: Invoke-Pester
uses: PSModule/Invoke-Pester@v3
# uses: PSModule/Invoke-Pester@v3
uses: PSModule/Invoke-Pester@fixCOntainerEval
id: test
env:
Settings: ${{ fromJson(steps.paths.outputs.result).Settings }}
Expand All @@ -62,6 +67,7 @@ runs:
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
TestResult_TestSuiteName: PSScriptAnalyzer
Path: ${{ github.action_path }}/scripts/tests/PSScriptAnalyzer
Run_Path: ${{ inputs.Path }}
Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }}
6 changes: 3 additions & 3 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Settings
$settings = $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Settings
$testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-Object -ExpandProperty Path
$codePath = Resolve-Path -Path $env:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_Path | Select-Object -ExpandProperty Path
$codePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path | Select-Object -ExpandProperty Path
$settingsFilePath = switch -Regex ($settings) {
'Module|SourceCode' {
"$testPath/$settings.Settings.psd1"
}
'Custom' {
Resolve-Path -Path "$env:GITHUB_ACTION_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath" | Select-Object -ExpandProperty Path
Resolve-Path -Path "$env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath" | Select-Object -ExpandProperty Path
}
default {
throw "Invalid test type: [$settings]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@{
Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName
Data = @{
Path = $env:GITHUB_ACTION_INPUT_Run_Path
Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path
SettingsFilePath = $env:SettingsFilePath
Debug = $false
Verbose = $false
Expand Down
Loading