diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index d39594a..5b4aac8 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -31,7 +31,8 @@ jobs: uses: ./ id: action-test with: - Path: tests/srcTestRepo/src + WorkingDirectory: tests/srcTestRepo + Path: src Settings: SourceCode - name: Status @@ -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 @@ -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 @@ -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 diff --git a/README.md b/README.md index 7fb45d6..7c78e9f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 04e7dc7..e19817b 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} @@ -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 }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b2822d8..5df78d4 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -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]" diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 404a041..30664b5 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -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