Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions: How to call a reusable workflow as a step?

I have a main GitHub Actions workflow that is triggered via the workflow_dispatch event, and a reusable workflow that is triggered via the workflow_call event.

Is it possible to run a reusable workflow via a step in your main workflow and not as a job?

Main workflow:

name: main-workflow
on:
  workflow_dispatch:
    inputs:
      message:
       type: string
       description: 'A message to pass to reusable workflow'

jobs:
  use-reusable-workflow:
    runs-on: ubuntu-latest
    steps:
      - name: Call reusable workflow
        uses: my-org/reusable-workflow@main
        with:
          workflow: reusable-workflow.yml
          inputs: |
            message=${{ github.event.inputs.message }}
          secrets: |
            A_SECRET: ${{ secrets.A_SECRET }}

When running the main workflow I am getting the following error:

Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under

like image 264
Coder3000 Avatar asked Sep 10 '25 20:09

Coder3000


2 Answers

According to the GitHub official documentation:

You call a reusable workflow by using the uses keyword. Unlike when you are using actions within a workflow, you call reusable workflows directly within a job, and not from within job steps.

Therefore, you can't call a reusable workflow from a job step.


A workaround in your case could be using a local action, which basically allows you to use an action in the same repository as the workflow.

Example of a local action call:

jobs:
  my_first_job:
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Use local my-action
        uses: ./.github/actions/my-action

Note that you need to inform the path to the directory that contains the action in your workflow's repository. Therefore, to access the action file, you must check out your repository before using the action with the actions/checkout.

This local action could be a composite action, similar to what a reusable workflow could achieve using actions, scripts or shell commands. I recommend this article to understand the difference between composite actions and reusable workflows.

like image 188
GuiFalourd Avatar answered Sep 12 '25 10:09

GuiFalourd


A reusable workflow which is marked with

on:
  workflow_call:

can only be called from uses within jobs but not from steps for e.g.

jobs:
      reusable_workflow:
        uses: ./.github/workflows/_reusable_workflow.yml

But, it won't work if you are trying to use the same workflow in some steps for e.g. like below

steps:
- name: Checkout code
  uses: actions/checkout@v4

- name: Call Reusable workflow
  uses: ./.github/workflows/_reusable_workflow.yml

This gives error saying the ./.github/workflows/_reusable_workflow.yml is not resolved. But actual problem is, we cannot call from steps.

The solution is to define as a action and then use it.

So. create a new action in .github/actions/my-reusable-action/action.yaml which could have multiple steps as below. Note: The file name has to be action.yml as its default file to be picked.

name: My Reusable action
runs:
  using: "composite"
  steps:
    - name: Setup Node
      uses: actions/setup-node@v4
      with:
        node-version: 20

    - name: Install asyncapi/cli
      shell: bash
      run: npm install -g @asyncapi/cli

And now this can easily reused from the steps

steps:
    - name: Checkout code
      uses: actions/checkout@v4
    
    - name: Call Reusable workflow
      uses: .github/actions/my-reusable-action

Notice we are not defining the path until action.yml as it will be picked default

like image 39
Sanjay Bharwani Avatar answered Sep 12 '25 09:09

Sanjay Bharwani