skip to Main Content

I’m pretty sure I’m misunderstanding something here about how GitHub actions work and would love some help. When this debugging.yml action runs on pull_request it looks to see if any files have changed in the repo.

Files have indeed changed, and the debug-check-output then picks up on the fact that the debugging.yml file has changed and executes. This then runs and the "List files in the repository" step correctly prints out the test-hello-world.yml file so I know it exists where it should. However when it gets to the step, "Attempt to trigger workflow via workflow call" the job fails with this error message:

Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/repo_name/repo_name/.github/workflows/test-hello-world.yml'. Did you forget to run actions/checkout before running your local action?

What am I misunderstanding or doing incorrectly here? Is it something to do with the runner itself and the fact that repo_name appears twice in the path in the error that is printed out, or something else?

# debugging.yml

name: Debugging workflow call and dispatch

on:
  pull_request:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - '.github/workflows/debugging.yml'
      - '.github/workflows/test-hello-world.yml'
      - '.github/workflows/**'
jobs:
  changed_files:
    runs-on: ubuntu-latest
    outputs:
      files: ${{ steps.set_output.outputs.files }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get changed files
        id: get_changes
        run: |
          git diff --name-only origin/main...HEAD > changed_files.txt
          cat changed_files.txt
        shell: bash

      - name: Set changed files output
        id: set_output
        run: |
          # Safely set the output using a here-doc for multiline content
          echo "files<<EOF" >> $GITHUB_ENV
          cat changed_files.txt >> $GITHUB_ENV
          echo "EOF" >> $GITHUB_ENV

          # Also set the output for further job consumption
          files=$(cat changed_files.txt | tr 'n' ' ')
          echo "::set-output name=files::$files"
        shell: bash

      - name: Debug - Show Changed Files Output
        run: cat changed_files.txt
        shell: bash

  debug-check-output:
    runs-on: ubuntu-latest
    needs: [changed_files]
    if: contains(needs.changed_files.outputs.files, '.github/workflows/debugging.yml')
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Echo Changed Files
        run: echo "${{ needs.changed_files.outputs.files }}"

      - name: List files in the repository
        run: ls -la ./.github/workflows/

      - name: Attempt to trigger workflow via workflow call # This fails with the error I posted above
        uses: ./.github/workflows/test-hello-world.yml
# test-hello-world.yml

name: Test Hello World

on:
  workflow_call:
  workflow_dispatch:

jobs:
  hello-world:
    runs-on: ubuntu-latest
    steps:
      - name: Print Hello World
        run: echo "Hello, World!"

2

Answers


  1. Chosen as BEST ANSWER

    This issue I was experiencing was caused by me using uses: in an incorrect fashion, see below for the correct syntax:

    #debugging.yml
    
    name: Debugging workflow call and dispatch
    
    on:
      pull_request:
      workflow_dispatch:
      push:
        branches:
          - main
        paths:
          - '.github/workflows/debugging.yml'
    
    jobs:
      changed_files:
        runs-on: ubuntu-latest
        outputs:
          files: ${{ steps.set_output.outputs.files }}
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0
    
          - name: Get changed files
            id: get_changes
            run: |
              git diff --name-only origin/main...HEAD > changed_files.txt
              cat changed_files.txt
            shell: bash
    
          - name: Set changed files output
            id: set_output
            run: |
              echo "files<<EOF" >> $GITHUB_ENV
              cat changed_files.txt >> $GITHUB_ENV
              echo "EOF" >> $GITHUB_ENV
    
              files=$(cat changed_files.txt | tr 'n' ' ')
              echo "::set-output name=files::$files"
            shell: bash
    
          - name: Debug - Show Changed Files Output
            run: cat changed_files.txt
            shell: bash
    
      debug-check-output:
        needs: [changed_files]
        if: contains(needs.changed_files.outputs.files, '.github/workflows/debugging.yml')
        uses: ./.github/workflows/test-hello-world.yml
    

  2. Github is quite picky about the keyword terms which is a good thing, what I can see here is a case of using uses as workflow to workflow,

    1. reusing yaml files.
    2. making references to github actions. etc

    This is how you used it below

    - name: Checkout code
      uses: actions/checkout@v4
    

    Have a look at the Github docs on how to use uses

    However this is how it is used,

    on:
      workflow_call: {}
    
    jobs:
      pass-secret-to-action:
        runs-on: ubuntu-latest
        steps:
          - name: Use a repo or org secret from the calling workflow.
            run: echo ${{ secrets.CALLING_WORKFLOW_SECRET }}
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search