Skip to content

Latest commit

 

History

History
109 lines (86 loc) · 2.9 KB

File metadata and controls

109 lines (86 loc) · 2.9 KB

github/dispatch.nu

Nushell script for triggering GitHub Actions workflows based on configurable rules.

Requirements

  • Nushell (installed and in PATH)
  • GitHub CLI (gh) authenticated
  • GitHub Token (required for cross-repository operations)
    Note: Automatic github.token doesn't support operations on other repositories!

Usage

dispatch.nu [flags]

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

Configuration

dispatch.yaml Structure

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

Operation Flow

  1. Config Loading

    • Reads --config file (default: .github/.dispatch.yaml)
    • Merges configurations with priority:
      default.dispatch < dispatch[N] < --inputs
  2. Rule Processing

    • Executes matcher based on match.type
    • Substitutes inputs from parameters ({parameter}) used in rules such as pull_request.title_regex
  3. Workflow Dispatch

    • Triggers workflow for each matched ref (branch/tag)

GitHub Action Integration

Example Workflow

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"

Key Environment Variables

  • GITHUB_TOKEN: PAT with workflow scope
  • NU_MODULE_DIRS: Paths to Nushell modules
  • NU_LOG_LEVEL: Script verbosity (debug, info, warning, error)

Pattern Matching

  • Uses {parameter} placeholders in regex patterns
  • Automatically substitutes values from inputs
  • Example: '^ci\({feature} {client-id}\):' becomes '^ci\(pr hello\):'