Reusable Workflows and Composite Actions
Why reuse?
A team runs the same checks in many repositories. Copying a workflow creates maintenance drift. A reusable workflow describes one or more jobs; a composite action groups steps within a caller job. Choose the boundary based on what must be shared, not how many lines you can remove.
Define a callable workflow
Save this inactive example as .github/workflows/garden-check.yml in a disposable project if practicing manually. workflow_call declares the interface: strict must be a boolean, not the quoted string "true". Inputs are available through the inputs context. This example only prints the selection; it does not perform strict validation. The empty permissions map grants no token permissions.
name: Reusable garden checkon: workflow_call: inputs: strict: required: true type: booleanpermissions: {}jobs: check: runs-on: ubuntu-latest steps: - name: Report selected policy env: STRICT: ${{ inputs.strict }} shell: bash run: printf '%s\n' "$STRICT"Call at job level
Save as .github/workflows/caller.yml. jobs.verify.uses invokes the local workflow from the same commit; it is not a step and does not declare its own runner here. For cross-repository reuse, review the referenced version and prefer an immutable full commit ID; grant only necessary permissions and explicitly map required secrets. Nested calls cannot elevate token permissions.
name: Call garden checkon: [workflow_dispatch]permissions: {}jobs: verify: uses: ./.github/workflows/garden-check.yml with: strict: trueReuse steps instead
Put this metadata in .github/actions/greeting/action.yml. A caller uses it as a step with uses: ./.github/actions/greeting and with: {label: Demo} after the repository files are available on the runner. Composite steps require their own shell when using run. Quoted environment expansion treats the label as data. The composite shares the caller job environment, not an independent runner.
name: Garden greetingdescription: Print a supplied labelinputs: label: description: Label to print required: trueruns: using: composite steps: - shell: bash env: LABEL: ${{ inputs.label }} run: printf '%s\n' "$LABEL"Practice and limits
Predict which abstraction fits a multi-job Linux/Windows test suite and which fits a shared greeting step. Answer: reusable workflow for the suite, composite for the greeting. Offline lab checks YAML placement, input types and locally executes the fixed print commands. It cannot verify hosted reuse, secrets or runner behavior.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reusable Workflows and Composite Actions — knowledge check
Reason about reliable delivery and trust boundaries.
Which abstraction can reuse several jobs?
Where does a caller invoke a reusable workflow?
Which value matches a boolean workflow input?
What must be available before using a local composite action?
What should a cross-repository call use?