GitHub Action - 可重用工作流:在调用的工作流上下文中运行 github 动作工作流

问题描述 投票:0回答:1

我有一个“呼叫者”工作流程和一个“被呼叫”工作流程。

来电工作流程:

name: caller

on:
  workflow_dispatch:

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

被调用的工作流:

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

-> 检出错误的存储库(检出调用者存储库而不是所需的被调用存储库)。如果我手动触发调用的工作流('actions/checkout@v3' 正在检出正确的 repo)工作流运行成功。

调用者工作流应该“只是”以某种方式触发被调用的工作流,使工作流像手动触发一样运行。

不幸的是,github 操作文档说:

如果您重用来自不同存储库的工作流,则被调用工作流中的任何操作都将运行,就好像它们是调用者工作流的一部分一样。例如,如果被调用的工作流使用 actions/checkout,则该操作会检出承载调用者工作流的存储库的内容,而不是被调用的工作流。

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

-> 我们是否有可能像我手动触发它那样以一种正在运行的方式触发工作流? 或者,我可以通过 Web 界面从另一个工作流触发工作流。但随后它变得混乱。一些想法?

github github-actions workflow pipeline building-github-actions
1个回答
-2
投票

我认为你最好的选择是使用类似 https://github.com/marketplace/actions/workflow-dispatch-and-wait

© www.soinside.com 2019 - 2024. All rights reserved.