4

I got a "caller" workflow and a "called" workflow.

Caller workflow:

name: caller

on:
  workflow_dispatch:

jobs:
  call-another-workflow: 
    uses: project/called/.github/workflows/main.yml@main

Called workflow:

name: called

on:
  workflow_dispatch:
  workflow_call:

jobs:
  run_python_script:
    runs-on: [ self-hosted ]
    steps:
      # Following step will be executed in the caller context (should be executed in the called context)
      - uses: actions/checkout@v3
      - name: Setup python
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      # Cannot find requirements.txt (wrong repository is checked out)
      - name: Install python packages
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Execute the python script
        run: python some_python_code.py
Error: <path> can't open file <path> [Errno 2] No such file or directory

-> The wrong repository is checked out (caller repo is checked out instead of the called which is needed). If I trigger the called workflow manually (the 'actions/checkout@v3' is checking out the right repo) the workflow runs successfully.

The caller workflow should 'just' trigger the called workflow in a way, that the workflow runs like it was triggered manually.

Unfortunately the github actions documentation says:

If you reuse a workflow from a different repository, any actions in the called workflow run as if they were part of the caller workflow. For example, if the called workflow uses actions/checkout, the action checks out the contents of the repository that hosts the caller workflow, not the called workflow.

(reference: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview)

-> Do we have the possibility to just trigger the workflow in a way that it is running like I triggered it manually? Alternatively, I can trigger the workflow from another workflow via web interface. But then it gets messy. Some ideas?

Matteo
  • 37,680
  • 11
  • 100
  • 115
StackOverflow
  • 116
  • 1
  • 6

0 Answers0