2

I want to use reusable workflows and invoke two other actions, below is the snippet of both caller and called workflows:

az-dev-img-ops-reusable.yml (called workflow1)

on:
  workflow_call:
    inputs:
      cloudProvider:
        required: true
        type: string
      imgAction: 
        required: true
        type: string
      envName: 
        required: true
        type: string
      productImage: 
        required: true
        type: string        
jobs:
  image-actions:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - uses: ./.github/workflows/manage_images
        with:
          imgAction: ${{ inputs.imgAction }}
          cloudProvider: ${{ inputs.cloudProvider }} 
          envName: ${{ inputs.envName }}
          productImage: ${{ inputs.productImage }}


az-dev-tenant-ops-reusable.yml (called workflow2)

on:
  workflow_call:
    inputs:
      cloudProvider:
        required: true
        type: string
      envName: 
        required: true
        type: string    
      action: 
        required: true
        type: string      
jobs:
  tenant-actions:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - uses: ./.github/workflows/refresh_tenant
        with: 
          cloudProvider: azure
          envName: az-dev
          action: pod_refresh

az-dev-cicd.yml (caller workflow)

on:
  workflow_dispatch:

jobs:
  init:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
  image-operations:
    uses: ./.github/workflows/az-dev-img-ops-reusable.yml
    with:
      imgAction: check 
      cloudProvider: azure 
      envName: az-dev 
      productImage: my-server
  tenant-operations:
    needs: image-operations
    uses: ./.github/workflows/az-dev-tenant-ops-reusable.yml
    with: 
      cloudProvider: azure
      envName: az-dev
      action: pod_refresh

But while running, it throws error as below:

Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/opt/my-runner/_work/my-images/my-images/.github/workflows/manage_images'. Did you forget to run actions/checkout before running your local action?

Checked over the web for solutions and tried all i.e.

  1. Have a actions/checkout.
  2. Make sure the caller function makes use of "uses" and not steps.
  3. Tried both absolute path of repo/yaml and relative path.

But haven't been able to resolve it. Any hints/help would be highly appreciated.

jagatjyoti
  • 699
  • 3
  • 10
  • 29
  • Did you try moving the `.github/workflows/manage_images` to another directory instead? Example: `.github/manage_images` directly, as it may be having conflicts with the `.github/workflows` directory. – GuiFalourd Aug 18 '22 at 11:41
  • @GuiFalourd I want to leverage other action files once this starts working. Hence, I cannot move them to another directory. Ideally, in the docs also it states that all yaml files should reside under .github/workflows. Also, subdirectories inside it is restricted I believe. – jagatjyoti Aug 18 '22 at 11:47
  • Just checked it here and indeed, the action.yaml being in a `.github/workflows` subdirectory isn't an issue here. Does it also happen without using self-hosted runners? – GuiFalourd Aug 18 '22 at 11:52
  • Could you also share the `./.github/workflows/manage_images` directory structure / files in the question, to reproduce the full behavior please? – GuiFalourd Aug 18 '22 at 11:57
  • @GuiFalourd The tree structure can be found under https://i.stack.imgur.com/rnbam.jpg – jagatjyoti Aug 18 '22 at 12:25
  • 1
    Ok. There is your issue: When using local actions, you need to create a `action.yaml` file in a directory. In your case, you won't use the `manage_images.yaml` workflow, you should use a `manage_images` folder with the `action.yaml` file in it. Now, if this `manage_images.yaml` is a reusable workflow, you need to add `.yaml` at the end of the `uses: ./.github/workflows/manage_images` line. This [answer](https://stackoverflow.com/questions/73026597/github-actions-suddenly-throwing-no-version-specified-for-reusable-workflows-t/73026906#73026906) could give you more context. – GuiFalourd Aug 18 '22 at 13:09
  • Great, it works ! But unable to understand if this directory structure is a mandate for running reusable workflows. Will it not work if I directly provide the file path location i.e. ./.github/workflows/manage_images.yml ? – jagatjyoti Aug 19 '22 at 04:32
  • Great, I'll add it as official answer I don't know your `manage_images.yaml` file implementation, so I can't say if you could use it as reusable workflow instead of as an action. – GuiFalourd Aug 19 '22 at 10:55

1 Answers1

3

Your issue is that you used the following syntax:

uses: ./.github/workflows/manage_images

... that refers to a directory.

When used that way, the Github Action interpreter expect a local action (using an action in the same repo).

However, to use local actions, you need to create a action.yaml file in a directory, but in your case, the image you shared in the comment shows that you actually have a manage_images.yaml file, that refers to a workflow, not a manage_images folder with an action.yml file in it.

To resolve your issue, if this manage_images.yaml is a reusable workflow (reusing the same workflow in different workflows), you need to add .yaml at the end of uses step, like this:

uses: ./.github/workflows/manage_images.yaml

Or, if you actually want to use a local action, convert this manage_images.yaml workflow to an action.yaml file, and put it inside a .github/workflows/manage_images directory.

Note that this answer could also give you more context about local actions and reusable workflows.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71