Search code examples
github-actionsgithub-actions-reusable-workflows

Combine composite actions from the same repo in GitHub Actions


This is my simplified GitHub Actions workflow structure. I have application repository (app_repo) which has build_and_deploy workflow. This workflow is using reusable workflow from the action_repo, which is actually meant to be implemented by using composite actions. Something like:

app_repo.build_and_deploy
* action_repo.deploy_and_deploy (workflow)

action_repo
* build_and_deploy (reusable workflow)
    - .github/actions/build (action)
    - .github/actions/deploy (action)

The problem here is that .github/actions path is relative within action_repo and when I call build_and_deploy workflow from app_repo then this relative path is not working.

How can I build modular workflow in action_repo and use composite actions that reside in the same repo?


Solution

  • IIUC you can specify the composite action you want to use in your reusable workflow with a fully qualified path to the action, namely:

    <organization>/<repository>/.github/actions/deploy@main
    

    instead of

    .github/actions/deploy
    

    An example could be GitHub's cache/restore which is used as follows:

    steps:
      - uses: actions/cache/restore@v4
    

    (instead of @main you may want to use a release tag or commit's sha, pinned dependencies are usually the best idea).

    Please note your repo needs to have access to the private composite action, see here for example.