open-source

Adapter Authoring Guide

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.

Architecture Recap

Naming Conventions

scripts/
  my-new-action/
    MyNewAction.ps1

Adapter Function Template

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
}

Registry Update (dispatchers.json)

After adding your adapter function, regenerate the dispatcher registry:

  1. Run npx tsx scripts/derive-dispatcher-registry.ts to update dispatchers.json.
  2. Commit the regenerated file.

Logging and Verbosity

Use Write-Information for normal logs and Write-Verbose for debug details. The dispatcher’s -LogLevel parameter sets verbosity before your adapter runs.

DryRun Considerations

If -DryRun is specified, log what would happen and return 0 instead of calling the underlying script.

Testing Your Adapter

Module Version and Documentation

Logging and Error Handling Guidelines

Following these Steps

By adhering to these conventions, your new action will be discoverable, consistent, and easier to maintain. Happy coding!