> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Composite Actions

> Guide to creating, using, and troubleshooting composite actions in GitHub Actions, including action.yaml setup, calling via relative path, manual workflow runs, and resolving path errors.

A composite action in [GitHub Actions](https://learn.kodekloud.com/user/courses/github-actions) groups multiple steps into a single, reusable action. This is useful for encapsulating common setup, linting, or test sequences and reusing them across workflows in the same repository.

In this guide you'll learn how to:

* Create a composite action (`action.yaml`) in your repo.
* Call that composite action from a workflow with `uses: ./...`.
* Troubleshoot the common “could not find action.yaml” error.
* Run a single workflow manually (useful when testing).

## 1. Create a composite action

1. At the root of your repository create a folder named `composite-action`.
2. Inside that folder add an `action.yaml` file with the following contents:

```yaml theme={null}
name: "Setup Environment"
description: "A simple composite action"
inputs:
  environment:
    required: true
runs:
  using: "composite"
  steps:
    - run: echo "Setting up ${{ inputs.environment }}"
      shell: bash
    - run: echo "Running linter..."
      shell: bash
```

Explanation:

* `inputs.environment` is declared as required so callers must provide a value.
* `runs.using: "composite"` tells GitHub this action is a composite action, composed of the listed `steps`.
* Replace the sample `echo` steps with real tasks (install dependencies, run linters, run tests, etc.) as appropriate for your project.

Quick file reference:

| File / Path | Purpose |
| - | - |
| `./composite-action/action.yaml` | Defines the composite action and the steps it will run |
| `.github/workflows/<name>.yaml` | Workflow that calls the composite action using a relative path |

## 2. Use the composite action in a workflow

Create a workflow file at `.github/workflows/ci2.yaml` (or another name you prefer). This example checks out the repository, then invokes the composite action from the local `./composite-action` directory:

```yaml theme={null}
name: Using Composite Workflow

on:
  push:
  workflow_dispatch:

jobs:
  test-composite-action:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./composite-action
        with:
          environment: production
```

Notes:

* When referencing a composite action stored in the same repository, use a relative path such as `uses: ./composite-action`.
* Provide the `with:` map to pass required inputs (here, `environment`).

Ensure the path you use in `uses: ./...` exactly matches the directory name in the repository. A small typo in the folder name will cause the runner to fail to locate the action.

## 3. When committing

If you want to avoid triggering other workflows while testing this new workflow, include `[skip ci]` or `[ci skip]` in your commit message. This prevents CI from running all workflows on that commit.

![A dark-themed GitHub repository page showing the .github file tree on the left and a centered "Commit changes" dialog with the commit message set to "\[skip ci\]". The right column displays the Actions/Marketplace panel.](https://mintcdn.com/kodekloud-c4ac6d9a/IdpF6mT8Tun72cng/images/GitHub-Administration-Certification/GitHub-Actions-and-Runners/Demo-Composite-Actions/github-dark-tree-commit-skipci-actions.jpg?fit=max\&auto=format\&n=IdpF6mT8Tun72cng\&q=85\&s=38b76026796aec09ea29582ac17a5bcd)

### Run a single workflow manually

If you committed with `[skip ci]` but still want to run only the workflow you just created, open the Actions tab in the GitHub UI, select your workflow (Using Composite Workflow), and click the "Run workflow" button. This option is available for workflows that define `workflow_dispatch` in the `on:` block and will run only that workflow on-demand.

## 4. Troubleshooting

If your workflow fails with an error like:
"could not find action.yaml or action.yml or Dockerfile", check the following:

* The folder name used in your workflow matches the actual folder name in the repository (for example, `./composite-action`).
* `action.yaml` (or `action.yml`) exists at that path and is committed to the branch the workflow runs on.
* The workflow runs on the branch where `action.yaml` was committed.

If your action is inside a subdirectory, make sure the `uses: ./path/to/action` path is relative to the repository root and that the action file (`action.yaml` or `action.yml`) is present and committed to the branch that triggers the workflow.

## 5. Example runner log (successful run)

Below is a typical excerpt from a successful workflow run after resolving a path issue. It shows the checkout step, the composite action invocation, and the two steps inside the composite action executing:

```text theme={null}
test-composite-action
succeeded in 6s

Set up job
Run actions/checkout@v4
Run ./composite-action

1  Prepare all required actions
2  ▸ Run ./composite-action
5  ▾ Run echo "Setting up production"
6  ▸ Run echo "Setting up production"
9      Setting up production
10 ▾ Run echo "Running linter..."
11 ▸ Run echo "Running linter..."
14     Running linter...

Post Run actions/checkout@v4
Complete job
```

This confirms the composite action executed correctly and its steps ran as expected.

## Further reading & references

* [GitHub Actions: Reusing workflows and composite actions](https://docs.github.com/actions/learn-github-actions/reusing-workflows)
* [GitHub Actions: Creating composite actions](https://docs.github.com/actions/creating-actions/creating-a-composite-action)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/github-administration-certification/module/3ba840c5-7afb-4da9-8395-a430a6354557/lesson/9c365109-faac-492c-837a-79d551ca9cb8)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.