For contributors who want to add new actions (adapters) or modify existing ones in the Open-Source Actions project.
This guide explains the structure of the unified dispatcher and how to extend it with new adapters and scripts.
Invoke-OSAction.ps1
): Entry point that parses inputs and dispatches to an adapter based on -ActionName
.OpenSourceActions.psm1
): Houses all adapter functions and shared logic.scripts/<action-name>/
."my-new-action"
.scripts/<action-name>/
with a clear name.Invoke-<PascalCase>
(e.g., Invoke-MyNewAction
).scripts/
my-new-action/
MyNewAction.ps1
Add your function to OpenSourceActions.psm1
:
function Invoke-MyNewAction {
[CmdletBinding()]
param(
[Parameter(Mandatory)] [string] $Param1,
[Parameter(Mandatory)] [int] $Param2,
[Parameter()] [string] $OptionalParam = "default",
[switch] $DryRun
)
Write-Information "Invoking MyNewAction with Param1=$Param1 ..." -InformationAction Continue
$scriptPath = Join-Path $PSScriptRoot '../scripts/my-new-action/MyNewAction.ps1'
$args = @{
Param1 = $Param1
Param2 = $Param2
OptionalParam = $OptionalParam
}
if ($DryRun) {
Write-Information "DryRun: would call $scriptPath with args $($args | ConvertTo-Json -Compress)"
return 0
}
& $scriptPath @args
if ($LASTEXITCODE -ne 0) {
throw "MyNewAction failed with exit code $LASTEXITCODE"
}
return $LASTEXITCODE
}
dispatchers.json
)After adding your adapter function, regenerate the dispatcher registry:
npx tsx scripts/derive-dispatcher-registry.ts
to update dispatchers.json
.Use Write-Information
for normal logs and Write-Verbose
for debug details. The dispatcher’s -LogLevel
parameter sets verbosity before your adapter runs.
If -DryRun
is specified, log what would happen and return 0 instead of calling the underlying script.
tests/pester/
.pwsh -File tests/pester/Dispatcher.Tests.ps1
before submitting.OpenSourceActions.psd1
if appropriate.docs/actions/
. Start from _template.md
and include sections: Purpose, Parameters (Required/Optional), CLI example, GitHub Action example, and Return Codes. Update central lists.Write-Host
.Exit
.By adhering to these conventions, your new action will be discoverable, consistent, and easier to maintain. Happy coding!