Running multiple reusable actions in succession

I’m currently experimenting with reusable actions. In my head I was going to separate each part of my action into reusable actions, then call them whenever needed on a step-by-step basis.

This is what I came up with:

name: Opened Pull Request

on:
  pull_request:
    branches:
      - master
      - staging
    # Allows you to run this workflow manually from the Actions tab
    workflow_dispatch:

jobs:
  pr:
    steps:
      - name: Build and Test
        uses: creativiii/commentcarp-api/.github/workflows/action.build-and-test.yml@staging
        secrets:
          APP_SECRET: "${{ secrets.APP_SECRET }}"

      - name: Compare coverage
        uses: creativiii/commentcarp-api/.github/workflows/action.compare-coverage.yml@staging

But trying to run this errors out with:

Error : .github#L1
reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps

So I’m confused how to get multiple reusable workflows in a single action.

I can get it running like this, but they they won’t be run in the order I want them to.

jobs:
  build:
    uses: creativiii/commentcarp-api/.github/workflows/action.build-and-test.yml@staging
    secrets:
      APP_SECRET: "${{ secrets.APP_SECRET }}"

  compare:
    uses: creativiii/commentcarp-api/.github/workflows/action.compare-coverage.yml@staging

Any tips?

What you’re using there are reusable workflows, though it sounds like composite actions might be a better fit for what you want to do: Creating a composite action - GitHub Docs

Alternatively, if you really want to use reusable workflows, you could create a needs relationship between the jobs. Transferring data will be harder that way, though.

1 Like

Oops, I assumed the two were one and the same. I’ll try composite actions, thank you!

1 Like