From d51ad42bce2f14181fbd676d1b304d8f4ec9b975 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 14:22:29 +0100 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20action?= =?UTF-8?q?=20inputs=20to=20include=20WorkingDirectory=20and=20update=20pa?= =?UTF-8?q?ths=20in=20workflow=20and=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 14 +++++++++----- README.md | 19 ++++++++++--------- action.yml | 12 +++++++++--- scripts/main.ps1 | 6 +++--- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index d39594a..b86c702 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..5c86c8a 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 | `${{ 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'` | +| `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` | ## Outputs diff --git a/action.yml b/action.yml index 04e7dc7..12d37e1 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,10 @@ 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 @@ -41,14 +45,15 @@ runs: 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 @@ -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 }} 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]" From 5c29818f0c50a77a2b5c2331b0a970443a2d873b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 14:32:48 +0100 Subject: [PATCH 2/7] Update default values for Path and Settings inputs in action.yml and README --- README.md | 2 +- action.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5c86c8a..7c78e9f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ customize rule selection, severity filtering, and custom rule inclusion. | Input | Description | Required | Default | |--------------------|----------------------------------------------------------------|----------|-----------------------------------------------------------------------------| -| `Path` | The path to the code to test. | false | `${{ github.workspace }}` | +| `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'` | diff --git a/action.yml b/action.yml index 12d37e1..5937be9 100644 --- a/action.yml +++ b/action.yml @@ -9,11 +9,11 @@ inputs: Path: description: The path to the code to test. required: false - default: ${{ github.workspace }} + default: '.' 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 @@ -41,7 +41,7 @@ inputs: runs: using: composite steps: - - name: Get test paths + - name: Get-TestPaths uses: PSModule/Github-Script@v1 id: paths env: From a016fff0efc5fa11c20496ea40c7c39ffccb7998 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 15:13:41 +0100 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Path=20i?= =?UTF-8?q?nput=20in=20Action-Test.yml=20to=20remove=20leading=20slash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index b86c702..5b4aac8 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -32,7 +32,7 @@ jobs: id: action-test with: WorkingDirectory: tests/srcTestRepo - Path: /src + Path: src Settings: SourceCode - name: Status From 241da40136b03061887044c3838a571509e129a9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 16:17:00 +0100 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Run=5FPa?= =?UTF-8?q?th=20to=20use=20output=20from=20paths=20step=20in=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5937be9..5cbf2e5 100644 --- a/action.yml +++ b/action.yml @@ -70,4 +70,4 @@ runs: 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 }} From 8270234dda74ece52287e60fdeeea3777dba783d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 17:41:04 +0100 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20PSScript?= =?UTF-8?q?Analyzer.Container.ps1=20to=20use=20PSMODULE=5FINVOKE=5FSCRIPTA?= =?UTF-8?q?NALYZER=5FINPUT=5FRun=5FPath=20for=20Path=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 404a041..ab1baa0 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_SCRIPTANALYZER_INPUT_Run_Path SettingsFilePath = $env:SettingsFilePath Debug = $false Verbose = $false From 04ab2b786bbe2318b1076d44297fd23023f51a71 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 21:36:11 +0100 Subject: [PATCH 6/7] Update action.yml to remove default Path value and change Invoke-Pester action reference --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 5cbf2e5..e19817b 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,6 @@ inputs: Path: description: The path to the code to test. required: false - default: '.' Settings: description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'. required: false @@ -57,7 +56,8 @@ runs: 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 }} From e576b54872a8b207bca4ff2ccf9b16c99a3234a6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 21:42:19 +0100 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20PSScript?= =?UTF-8?q?Analyzer.Container.ps1=20to=20use=20PSMODULE=5FINVOKE=5FPESTER?= =?UTF-8?q?=5FINPUT=5FRun=5FPath=20for=20Path=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index ab1baa0..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:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Run_Path + Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path SettingsFilePath = $env:SettingsFilePath Debug = $false Verbose = $false