Interview Prep/GitHub Actions/Custom Actions & Reusable Workflows

Write a minimal composite action that installs Node and dependencies with caching.

IntermediateConceptCustom Actions & Reusable Workflows
Answer

.github/actions/setup-app/action.yml:

name: Setup app
description: Install Node and npm dependencies with cache
inputs:
  node-version:
    description: Node.js version
    default: "22"
runs:
  using: composite
  steps:
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ inputs.node-version }}
        cache: npm
    - run: npm ci
      shell: bash

Use with - uses: ./.github/actions/setup-app after actions/checkout. Every run step in a composite action must declare shell.

All GitHub Actions questions Roadmap: GitHub Actions

More on Custom Actions & Reusable Workflows