Reusing workflows in the same repo

I have a workflow that does the following:

  • build 2 docker images and push them to repo
  • build a Java jar and copy to S3

I need to run this same workflow on 5 separate environments - but an environment can’t be passed as parameter, so a few copies of the same workflow are needed.

To minimize copy-paste, I wanted to use callable workflows. However, it seems that unlike Actions that can be in the same repo, callable workflows are meant to be stored in another repo.

Am I missing an obvious way to do the above?

Callable workflows can be in the same repo, but you still have to specify the full path (including the repository) and an explicit ref to call them. That ref can be the name of the branch you’re working on.

As the doc says, this works:

    uses: me/this-repo/.github/workflows/workflow.yml@main

But this doesn’t:

    uses: me/this-repo/.github/workflows/workflow.yml@${{github.ref_name}}

Which means that the caller and the callee don’t really “live” together - unlike local custom actions.