Monk CIMonk CI home

30 Nov, 2026Akshit Mandial

Smaller GitHub Workflows with Composite Actions


Simplify GitHub workflow files with scripts, composite actions and reusable workflows. Choose a reuse boundary and keep inputs, outputs and permissions clear.

A GitHub composite action reuses a sequence of steps inside a job; a reusable workflow reuses one or more jobs. Use repository scripts for ordinary build logic, composite actions for repeated step sequences, and reusable workflows when runner selection and job structure need to be shared.

The goal is readable behavior, not the fewest YAML lines. Keep triggers, permissions and required results easy to inspect even when their implementation is reused.

Which reuse mechanism should you choose?

Choose the smallest boundary that contains the repeated behavior. Moving every command into a shared framework can make a simple pipeline harder to debug.

MechanismBest fitImportant boundary
Repository scriptBuild or test logic runnable locallyReceives explicit arguments/environment
Composite actionRepeated setup and command stepsRuns inside the caller's job
Reusable workflowShared jobs, runners and dependenciesCalled at job level

GitHub's composite-action tutorial and reusable-workflow guide describe these different interfaces.

What logic should move into a script?

Move ordinary command sequencing into a versioned script when it benefits local reproduction and focused testing. Keep the workflow responsible for when and where that script runs.

For an npm project with test:ci and build scripts, create scripts/ci.sh:

#!/usr/bin/env bash
set -euo pipefail
npm ci
npm run test:ci
npm run build

Then a workflow step can call bash scripts/ci.sh. This preserves failure propagation and lets developers run the same sequence locally after selecting the expected toolchain.

Avoid passing untrusted event text directly into shell code. Use explicit parameters or environment values and validate them according to the operation they control. Extracting a command into a file does not automatically make its inputs safe.

What does a complete local composite action look like?

The action can select the runtime, call the shared script and expose a useful output. Save this as .github/actions/node-validation/action.yml:

yaml
name: Node validation
inputs:
  node-version:
    description: Supported Node version
    required: false
    default: '24'
outputs:
  revision:
    description: Validated source revision
    value: ${{ steps.revision.outputs.sha }}
runs:
  using: composite
  steps:
    - uses: actions/setup-node@v7
      with:
        node-version: ${{ inputs.node-version }}
        cache: npm
    - name: Validate project
      shell: bash
      run: bash scripts/ci.sh
    - id: revision
      shell: bash
      run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

This assumes the caller has checked out the repository and that the lockfile and script are at the root. The action metadata reference explains input, output and composite-step syntax.

A caller job can use it as follows:

yaml
name: Validate application
on: [push, pull_request]
permissions:
  contents: read
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: ./.github/actions/node-validation
        with:
          node-version: '24'

The local action does not choose another runner or create a new job. Those decisions remain visible in the caller.

When is a reusable workflow better?

Use a reusable workflow when the shared unit includes jobs, runner configuration, permissions or dependencies between jobs. Define a workflow_call interface and call the workflow at job level rather than from a normal step.

Keep inputs, secrets and outputs explicit. An output from an internal step is not automatically a caller-visible workflow output; map it through the documented step, job and workflow interfaces. Likewise, do not assume every environment value or secret crosses the boundary automatically.

For shared workflows in another repository, choose an update policy deliberately. A full commit SHA gives an immutable reference; moving tags or branches need a controlled process for testing and rolling out changes. Avoid quoting a fixed nesting limit without checking the current documentation.

How do you know the refactor preserved behavior?

Compare a passing case and an intentional failing case before and after extraction. Verify the same tests, outputs, permissions and required-check names remain in place.

Use the Node build-and-test guide for the application contract and the compatibility checklist when infrastructure changes too. After following the Monk CI quickstart, a compatible caller job can select runs-on: monkci-ubuntu-24.04-4; the local action still executes inside that job.

A clearer workflow is easier to maintain, but fewer YAML lines do not by themselves make the workload run faster.

Frequently asked questions

Can a composite action choose its own runner?

It executes its steps within the job that calls it, so the caller selects the runner. Use a reusable workflow when the shared behavior needs job-level runner choices or several dependent jobs. Keep that distinction visible so a refactor does not accidentally hide infrastructure or permission decisions from reviewers.

Must every shell command move into a script?

No. A simple setup command can remain clear in the workflow. Extract logic when local execution, reuse or focused testing benefits the project, rather than following a line-count rule. Preserve the workflow's readable orchestration and avoid introducing another abstraction for a command that is already easy to understand.

Do reusable workflows inherit all secrets automatically?

Treat their interface as explicit and follow GitHub's supported passing mechanisms. Check the caller, called workflow and relevant environment behavior instead of assuming every value crosses the boundary. Pass only what the shared job needs, and verify the actual event path before using the refactor for deployment.

Does pinning a workflow to a tag prevent all changes?

A tag can be moved by someone with the necessary repository permissions. A full commit SHA provides an immutable code reference, while tags and branches require a trusted update policy. Choose the approach deliberately and test shared changes before rolling them across consumers whose required checks depend on that workflow.

Try Monk CI for free

Continue with GitHub