Reusable workflows with local actions

Viewed 3437

Reusable workflows with local actions are not working. Reusable workflow is trying to locate the local action in the main repo

Created sample repositories to reproduce the issue

  1. Repo with reusable workflows and local action - https://github.com/vinodsai-a/github-reusable-workflow-sample
  2. Sample repo which uses above reusable workflows - https://github.com/vinodsai-a/github-example-repo

This is the PR link -> https://github.com/vinodsai-a/github-example-repo/pull/1

Error -> https://github.com/vinodsai-a/github-example-repo/pull/1/checks

enter image description here

5 Answers

There is a workaround, it comes however with the downside of needing to specify the ref for the reusable workflow twice, like this:

jobs:
  build-push:
    uses: <org>/<central-workflow-repo>/.github/workflows/build-push.yml@v1.2 # always change with.workflows-ref, too
    with:
      workflows-ref: v1.2
    secrets:
      # can't use GITHUB_TOKEN as its different repo
      GH_ACCESSTOKEN: ${{ secrets.GH_ACCESSTOKEN }}

The repo of your reusable workflow has this structure:

<org>/<central-workflow-repo>/ (github repo)
├─ .github/
│  ├─ workflows/
│  │  ├─ build-push.yml
├─ actions/
│  ├─ your-action/
│  │  ├─ action.yml
  1. Check-out the repo of the called workflow to workflows
on:
  workflow_call:
    inputs:
      workflows-ref:
        description: "ref of the centralized workflows repo that was specified in 'jobs.<name>.uses'"
        required: true
        type: string
...
    steps:
      - name: Checkout workflows repo # required so we can reference the actions locally
        uses: actions/checkout@v2
        with:
          ref: ${{ inputs.workflows-ref }}
          path: workflows
          repository: <org>/<central-workflow-repo>
          token: ${{ secrets.GH_ACCESSTOKEN }}
  1. (optional) if you want your calling repo checked out, do so, but to a subdirectory
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          path: app
  1. Start referencing your local actions:
      - uses: ./workflows/actions/your-action

The issue here is that you can't call a local action on a repository without using the actions/checkout action to access the files in the repository.

on: [workflow_call]

jobs:
  local-action-testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.3.4 # Necessary to access local action
      - uses: ./actions/local-action

I've got some proofs of concept here if you want to take a look:

I don't think as of now GitHub allows any way to use actions from reusable workflow repo. Currently. reusable workflow functionality is very limited and all the actions in the reusable workflow run as part of the caller workflow. So when you are specifying to run action in path ./actions/local-action GitHub action is trying to find the action in your caller repo and since the path isn't valid for caller repo you are getting the error.

The current workaround is treat your action as if it is hosted in external repo instead of local path as documented. In your case you can specify vinodsai-a/github-reusable-workflow-sample/actions/local-action@main instead of ./actions/local-action.

I also had this issue.

When using local actions they need to be placed at the job level (NOT inside the steps of a job). Your caller action should be changed from:

on: [pull_request]
jobs:
  ci:
    uses: vinodsai-a/github-reusable-workflow-sample/.github/workflows/main.yml@main

to:

on: [pull_request]
jobs:
  uses: vinodsai-a/github-reusable-workflow-sample/.github/workflows/main.yml@main

Reference: https://docs.github.com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow

Related