技术问询:能否在Composite Action中直接调用Workflow?
能否在Composite Action中直接调用Workflow?
不能。Composite Action的runs.steps里的uses字段仅支持引用Action(包括Docker Action、JavaScript Action、其他Composite Action),无法直接引用.github/workflows/下的Workflow文件,你当前的代码写法会触发执行错误。
正确实现思路
有两种可行的替代方案:
方案1:将原Composite Action转为可被调用的Workflow,在其中调用目标Workflow
把原来的Composite Action改成一个支持workflow_call的Workflow,然后在这个Workflow的job里通过uses调用辅助Workflow。
修改后的主Workflow(替代原Composite Action)
name: Service workflow description: Service workflow (替代原Composite Action) on: workflow_call: inputs: example_input: description: example input required: true type: string jobs: service-job: runs-on: ubuntu-latest steps: - name: Service test id: Service_test shell: bash run: | echo "run the test1" echo "echo the inputs: ${{ inputs.example_input }}" # 调用辅助Workflow - name: Call helper workflow uses: ./.github/workflows/call_in_action_helper.yml
辅助Workflow(清理冗余代码后)
name: call in action on: workflow_call: jobs: job1: runs-on: ubuntu-latest outputs: data: ${{ steps.generate.outputs.data }} steps: - name: Generate data id: generate run: | echo "Hello from Job 1" > data.txt echo "data=$(cat data.txt)" >> $GITHUB_OUTPUT
方案2:将辅助Workflow的逻辑提取为Composite Action,在原Composite Action中调用
如果必须保留Composite Action的形式,把辅助Workflow里的步骤提取成一个新的Composite Action,然后在原Composite Action中引用这个Action。
新的辅助Composite Action(路径:.github/actions/helper-action/action.yml)
name: Helper Action description: Helper action with generate data logic runs: using: "composite" steps: - name: Generate data id: generate shell: bash run: | echo "Hello from Job 1" > data.txt echo "data=$(cat data.txt)" >> $GITHUB_OUTPUT
原Composite Action修改后
name: Service composite description: Service composite inputs: example_input: description: example input required: true type: string runs: using: "composite" steps: - name: Service test id: Service_test shell: bash run: | echo "run the test1" echo "echo the inputs: ${{ inputs.example_input }}" - name: Use helper action uses: ./.github/actions/helper-action
关键说明
- Composite Action的核心是复用步骤集合,而非调用独立的Workflow(Workflow是包含job、运行环境等完整执行单元的定义)。
- 若需要跨Workflow复用完整执行逻辑,优先用
workflow_call实现Workflow之间的调用;若仅复用特定步骤,用Composite Action更合适。
内容的提问来源于stack exchange,提问作者azure action
相关产品推荐
相关产品推荐

