AI Hints
Home›CI/CD with GitHub Actions Tutorial›Writing Your Own Actions
CI/CD with GitHub Actions · Lesson 103 of 138

Composite Actions

Bundle steps together.

⏱ 2 min read▶ Video at 1:59:53🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Reusable workflows share whole jobs. But sometimes you just want to share a few steps, like setting up the project. A composite action bundles steps into one action, that you use like any other.

Composite Actions
From the video: Composite Actions
  • Workflows share jobs
  • Actions share steps
  • Composite: a bundle of steps

action.yml

An action lives in its own folder, with an action dot y m l file. It has a name, and inputs, here an optional list of extra packages. Using composite means its steps run in order. Each run step in a composite action must say which shell to use.

.github/actions/setup-shop/action.ymlyaml
name: Set up the shop
description: Install dependencies and show versions
inputs:
  extras:
    description: Extra packages to install
    default: ""
runs:
  using: composite
  steps:
    - run: pip install -q -r requirements.txt ${{ inputs.extras }}
      shell: bash
    - run: python3 --version && pytest --version
      shell: bash

Using it

The workflow uses the action by its folder path, starting with dot slash. Our helper runs local actions too. The setup step installs the packages, and prints the Python and pytest versions. Then the tests run as usual.

Terminal
cat .github/workflows/ci.yml | tail -4
      - uses: actions/checkout@v4
      - name: Set up the shop
        uses: ./.github/actions/setup-shop
      - run: pytest -q
run-steps .github/workflows/ci.yml | grep -vE "^Workflow|↷|100%"
Job: test
  ✓ Set up the shop
      Python 3.12.3
      pytest 7.4.4
  ✓ Run pytest -q
      3 passed in 0.01s
  Job succeeded

Summary

Composite actions bundle steps into one reusable action, with inputs. Next, writing an action with real code.

Key takeaways
  • action.yml
  • using: composite
  • shell: bash
Next up: Writing a Script Action — actions with code