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
This issue I was experiencing was caused by me using
uses:
in an incorrect fashion, see below for the correct syntax: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,This is how you used it below
Have a look at the Github
docs
on how to useuses
However this is how it is used,