Repository navigation
🩹 [Patch]: Standardize project structure and rename release workflow - #81
Conversation
| try { | ||
| ${{ github.action_path }}/scripts/init.ps1 | ||
| ${{ github.action_path }}/scripts/info.ps1 | ||
| ${{ github.action_path }}/src/init.ps1 |
Check warning
Code scanning / CodeQL
Code injection
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, to address code injection warnings in GitHub Actions, move expression values (${{ ... }}) into environment variables and then reference them using the shell’s native syntax instead of embedding expressions directly inside the run: script. This eliminates the opportunity for shell parsing of templated strings and aligns with GitHub’s recommended pattern.
For this specific file, we should:
- Define an environment variable (for example
PSMODULE_GITHUB_ACTION_PATH) set to${{ github.action_path }}underenv:for the step. - Replace all occurrences of
${{ github.action_path }}in the PowerShell script with the PowerShell environment variable reference$env:PSMODULE_GITHUB_ACTION_PATH. - While doing so, preserve the rest of the logic and keep
${{ inputs.Script }}untouched, since changing that behavior would alter functionality and go beyond the requested change.
Concretely, in action.yml within the composite runs.steps block for RunGitHubScript, we add a new env: entry (e.g., on a new line after line 95) and then adjust lines 102–105 and 108 so that they call the PowerShell scripts using $env:PSMODULE_GITHUB_ACTION_PATH instead of ${{ github.action_path }}. No additional external dependencies or imports are required.
| @@ -93,17 +93,18 @@ | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }} | ||
| PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }} | ||
| run: | | ||
| # ${{ inputs.Name }} | ||
| $ErrorView = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView | ||
| $DebugPreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| $VerbosePreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| try { | ||
| ${{ github.action_path }}/src/init.ps1 | ||
| ${{ github.action_path }}/src/info.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/init.ps1" | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/info.ps1" | ||
| ${{ inputs.Script }} | ||
| ${{ github.action_path }}/src/outputs.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/outputs.ps1" | ||
| } | ||
| finally { | ||
| ${{ github.action_path }}/src/clean.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/clean.ps1" | ||
| } |
| ${{ github.action_path }}/scripts/init.ps1 | ||
| ${{ github.action_path }}/scripts/info.ps1 | ||
| ${{ github.action_path }}/src/init.ps1 | ||
| ${{ github.action_path }}/src/info.ps1 |
Check warning
Code scanning / CodeQL
Code injection
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
General fix: avoid using ${{ ... }} expressions directly inside the run: script. Instead, assign those values to environment variables (or to action inputs that are already mapped to env vars), and inside the PowerShell script refer to them via $env:VAR or normal PowerShell variables. This follows GitHub’s recommended pattern and prevents the expression language from being mixed with shell syntax.
Concrete change here: we will add an environment variable (e.g. PSMODULE_GITHUB_ACTION_PATH) set to ${{ github.action_path }}, and then update the PowerShell script so it invokes the scripts via $env:PSMODULE_GITHUB_ACTION_PATH\src\*.ps1. That way, no ${{ ... }} appears inside the run: block for these paths, and CodeQL’s injection concern is removed, while functionality remains the same. We will not alter ${{ inputs.Script }} because the entire action is built around intentionally executing that content as PowerShell.
Changes to make in action.yml:
- In the
env:section of theRunGitHubScriptstep, add:PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }}
- In the
run:script:- Replace:
${{ github.action_path }}/src/init.ps1${{ github.action_path }}/src/info.ps1${{ github.action_path }}/src/outputs.ps1${{ github.action_path }}/src/clean.ps1
- With proper PowerShell invocations that reference the environment variable, e.g.:
& "$env:PSMODULE_GITHUB_ACTION_PATH/src/init.ps1"- etc.
- Replace:
Using & ensures the script is actually executed as a PowerShell script even if the path contains spaces. All other behavior (inputs, outputs) remains unchanged.
No extra imports or external libraries are necessary; all changes are within action.yml.
| @@ -93,17 +93,18 @@ | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }} | ||
| PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }} | ||
| run: | | ||
| # ${{ inputs.Name }} | ||
| $ErrorView = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView | ||
| $DebugPreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| $VerbosePreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| try { | ||
| ${{ github.action_path }}/src/init.ps1 | ||
| ${{ github.action_path }}/src/info.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/init.ps1" | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/info.ps1" | ||
| ${{ inputs.Script }} | ||
| ${{ github.action_path }}/src/outputs.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/outputs.ps1" | ||
| } | ||
| finally { | ||
| ${{ github.action_path }}/src/clean.ps1 | ||
| & "$env:PSMODULE_GITHUB_ACTION_PATH/src/clean.ps1" | ||
| } |
| ${{ github.action_path }}/src/info.ps1 | ||
| ${{ inputs.Script }} | ||
| ${{ github.action_path }}/scripts/outputs.ps1 | ||
| ${{ github.action_path }}/src/outputs.ps1 |
Check warning
Code scanning / CodeQL
Code injection
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
General approach: Avoid embedding GitHub expression syntax (${{ ... }}) directly in the run: script where it becomes part of the PowerShell code. Instead, assign those values to environment variables (already done for inputs) or to step outputs, and then read and use them via native PowerShell syntax ($env:VAR, variables, & to invoke scripts). For script paths, construct them from a safe base directory in PowerShell rather than concatenating expression results into the script body.
Best concrete fix here:
- Add an environment variable (or variables) in the step’s
env:section that capturesgithub.action_pathas a value, e.g.PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }}. - Update the PowerShell
run:block so it does not contain${{ github.action_path }}or${{ inputs.Script }}directly. Instead:- Define a PowerShell variable
$actionPath = $env:PSMODULE_GITHUB_ACTION_PATH. - Safely build the script paths using
Join-Path $actionPath 'src/init.ps1', etc., and execute them via&(the call operator). - Move the user-supplied script out of the expression context: pass
inputs.Scriptvia an env var (e.g.PSMODULE_GITHUB_SCRIPT_INPUT_Script) and invoke it using PowerShell’sInvoke-Expressionon that env var. This avoids GitHub expression injection; note that ifinputs.Scriptitself is attacker-controlled PowerShell code, that is by design for this action (it runs arbitrary user PowerShell), so we only need to prevent extra commands being smuggled through the GitHub expression layer.
- Define a PowerShell variable
- Keep existing behavior: the same init, info, user script, outputs, and clean scripts still run in the same order; inputs already exposed via env remain unchanged.
Concretely, within action.yml we will:
- Add a new env entry:
PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }}. - Add a new env entry for the script text:
PSMODULE_GITHUB_SCRIPT_INPUT_Script: ${{ inputs.Script }}. - Replace the body of the
run:block to:- Set
$actionPathand$scriptToRunfrom the environment. - Use
Join-Pathand&to runinit.ps1,info.ps1, the user script,outputs.ps1, andclean.ps1.
- Set
| @@ -93,17 +93,23 @@ | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_Script: ${{ inputs.Script }} | ||
| PSMODULE_GITHUB_ACTION_PATH: ${{ github.action_path }} | ||
| run: | | ||
| # ${{ inputs.Name }} | ||
| $ErrorView = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView | ||
| $DebugPreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| $VerbosePreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| $actionPath = $env:PSMODULE_GITHUB_ACTION_PATH | ||
| $scriptToRun = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Script | ||
| try { | ||
| ${{ github.action_path }}/src/init.ps1 | ||
| ${{ github.action_path }}/src/info.ps1 | ||
| ${{ inputs.Script }} | ||
| ${{ github.action_path }}/src/outputs.ps1 | ||
| & (Join-Path $actionPath 'src/init.ps1') | ||
| & (Join-Path $actionPath 'src/info.ps1') | ||
| if ($scriptToRun) { | ||
| Invoke-Expression $scriptToRun | ||
| } | ||
| & (Join-Path $actionPath 'src/outputs.ps1') | ||
| } | ||
| finally { | ||
| ${{ github.action_path }}/src/clean.ps1 | ||
| & (Join-Path $actionPath 'src/clean.ps1') | ||
| } |
| } | ||
| finally { | ||
| ${{ github.action_path }}/scripts/clean.ps1 | ||
| ${{ github.action_path }}/src/clean.ps1 |
Check warning
Code scanning / CodeQL
Code injection
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, to fix this type of issue in GitHub Actions, any value coming from a GitHub expression (${{ ... }}), whether or not it is attacker-controlled, should be assigned to an environment variable and then referenced using the shell’s native syntax ($VAR in PowerShell) inside the run: block. This avoids the risk of expression-based code injection inside scripts.
For this file, the safest, minimal-change fix is:
- Define an environment variable (for example,
ACTION_PATH) in theenv:section with the value${{ github.action_path }}. - Replace all usages of
${{ github.action_path }}in therun:script with$env:ACTION_PATH, which is standard PowerShell syntax for environment variables. - Leave
${{ inputs.Script }}as-is, because that is the intended script content input to the action; the CodeQL report specifically targets thegithub.action_pathexpression.
Concretely, within action.yml:
- Under
env:for theRunGitHubScriptstep, add a lineACTION_PATH: ${{ github.action_path }}(or similarly named variable). - In the
run:block, change:${{ github.action_path }}/src/init.ps1→$env:ACTION_PATH/src/init.ps1${{ github.action_path }}/src/info.ps1→$env:ACTION_PATH/src/info.ps1${{ github.action_path }}/src/outputs.ps1→$env:ACTION_PATH/src/outputs.ps1${{ github.action_path }}/src/clean.ps1→$env:ACTION_PATH/src/clean.ps1
No additional imports or external libraries are needed; this is purely a YAML and PowerShell syntax adjustment.
| @@ -93,17 +93,18 @@ | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }} | ||
| PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }} | ||
| ACTION_PATH: ${{ github.action_path }} | ||
| run: | | ||
| # ${{ inputs.Name }} | ||
| $ErrorView = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView | ||
| $DebugPreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| $VerbosePreference = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' | ||
| try { | ||
| ${{ github.action_path }}/src/init.ps1 | ||
| ${{ github.action_path }}/src/info.ps1 | ||
| $env:ACTION_PATH/src/init.ps1 | ||
| $env:ACTION_PATH/src/info.ps1 | ||
| ${{ inputs.Script }} | ||
| ${{ github.action_path }}/src/outputs.ps1 | ||
| $env:ACTION_PATH/src/outputs.ps1 | ||
| } | ||
| finally { | ||
| ${{ github.action_path }}/src/clean.ps1 | ||
| $env:ACTION_PATH/src/clean.ps1 | ||
| } |
There was a problem hiding this comment.
Pull request overview
This PR standardizes the GitHub-Script action's project structure by renaming the scripts/ folder to src/ to align with PSModule conventions, and updates the release workflow to use the renamed action and improved naming.
Changes:
- Renamed
scripts/folder tosrc/for consistency with PSModule project structure - Updated workflow from
Auto-ReleasetoReleaseand migrated fromPSModule/Auto-Release@v1.9.5toPSModule/Release-GHRepository@v2.0.1 - Disabled JSCPD validation in linter and removed its configuration file
Reviewed changes
Copilot reviewed 4 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/outputs.ps1 | Moved from scripts/ with logic for displaying script outputs |
| src/init.ps1 | Moved from scripts/ with initialization and module setup logic |
| src/info.ps1 | Moved from scripts/ with environment information display logic |
| src/clean.ps1 | Moved from scripts/ with cleanup logic for credentials |
| action.yml | Updated all script path references from scripts/ to src/ |
| .github/workflows/Release.yml | Renamed workflow, updated action reference, and added paths filter |
| .github/workflows/Linter.yml | Disabled JSCPD validation |
| .github/linters/.jscpd.json | Removed unused linter configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR standardizes the project structure and updates workflows to align with PSModule conventions.
Changed
Auto-Release.ymlworkflow toRelease.ymlfor consistencyPSModule/Auto-Release@v1.9.5toPSModule/Release-GHRepository@v2scripts/folder tosrc/to follow standard project layoutaction.ymlto reference scripts from newsrc/locationRemoved
.jscpd.jsonlinter configuration fileSummary
This PR brings the GitHub-Script action in line with PSModule's standardized project structure. The
scripts/folder is renamed tosrc/for consistency across all actions, and the release workflow is updated to use the renamedRelease-GHRepositoryaction.