Nushell script for triggering GitHub Actions workflows based on configurable rules.
- Nushell (installed and in PATH)
- GitHub CLI (
gh) authenticated - GitHub Token (required for cross-repository operations)
Note: Automaticgithub.tokendoesn't support operations on other repositories!
dispatch.nu [flags]| Short | Long | Description | Default |
|---|---|---|---|
-c |
--config |
Path to dispatch config | .github/.dispatch.yaml |
-i |
--inputs |
Inputs as record or JSON | {} |
-h |
--help |
Show help message |
default:
dispatch:
workflow: test-pr.yaml
inputs:
client: hello
feature: pr
match:
type: pull_request
pull_request:
title_regex: '^ci\({feature} {client}\):'
dispatch:
- repository: dennybaa/ghbar
- repository: dennybaa/ghfoo
- repository: dennybaa/testing
inputs:
pr-number: '{pull_request.number}' # additional input (take data from a matched pull_request)
match:
fallback_ref: main-
Config Loading
- Reads
--configfile (default:.github/.dispatch.yaml) - Merges configurations with priority:
default.dispatch<dispatch[N]<--inputs
- Reads
-
Rule Processing
- Executes matcher based on
match.type - Substitutes inputs from parameters (
{parameter}) used in rules such aspull_request.title_regex
- Executes matcher based on
-
Workflow Dispatch
- Triggers workflow for each matched ref (branch/tag)
steps:
- uses: hustcer/setup-nu@main
- name: Checkout Code
uses: actions/checkout@v4
with: { path: code }
- name: Checkout Nu Modules
uses: actions/checkout@v4
with:
repository: bitdeps/nu_scripts
path: nu
- name: Dispatch Workflows
env:
GITHUB_TOKEN: ${{ secrets.MYPAT }}
NU_LOG_LEVEL: info
NU_MODULE_DIRS: |
${{ github.workspace }}/nu/modules;
shell: nu {0}
run: |
const workspace = '${{ github.workspace }}'
source $"($workspace)/nu/scripts/common/env.nu"
cd code; nu -I (nu-include-dirs) $"($workspace)/nu/scripts/github/dispatch.nu"GITHUB_TOKEN: PAT withworkflowscopeNU_MODULE_DIRS: Paths to Nushell modulesNU_LOG_LEVEL: Script verbosity (debug,info,warning,error)
- Uses
{parameter}placeholders in regex patterns - Automatically substitutes values from
inputs - Example:
'^ci\({feature} {client-id}\):'becomes'^ci\(pr hello\):'