我有 2 个工作流程。一个正在呼叫另一个。
name: call other workflow
on:
push
jobs:
#------------------------------------
prep:
name: prep
runs-on: ubuntu-latest
outputs:
sha:
${{ steps.short-sha.outputs.sha }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
submodules: recursive
- name: Short-Sha
uses: benjlevesque/[email protected]
id: short-sha
with:
length: 8
- name: print SHA
run: echo $SHA
env:
SHA: ${{ env.SHA }}
#------------------------------------
print-sha:
name: print-sha
needs: [ prep ]
runs-on: ubuntu-latest
steps:
- name: print SHA
run: echo $SHA
env:
SHA: ${{ needs.prep.outputs.sha }}
#------------------------------------
call-other-workflow:
name: call-other-workflow
needs: [ print-sha ]
uses: ./.github/workflows/other_workflow.yml
with:
commit-hash: "*c@ller*"
# commit-hash: ${{ needs.prep.outputs.sha }}
上面的工作流程正在调用这个:
name: other workflow
on:
workflow_call:
inputs:
commit-hash:
type: string
required: true
default: "d3faultX"
jobs:
#------------------------------------
prep:
runs-on: ubuntu-latest
steps:
- name: print SHA
run: echo "${{ inputs.commit-hash }}"
如您所见,我想传递提交哈希。正如代码所示,它只是传递一个硬编码的字符串。这样可行。一旦我将其交换为 SHA 的参考,它就不再起作用了。为什么?我已经添加了其他打印步骤来查看我是否有有效的参考等。但我仍然无法弄清楚为什么这不起作用。
感谢@jonrsharpe 编辑我的帖子,感谢@Benjamin W. 在评论中给我答案。基于此,我将代码更改为:
#------------------------------------
call-other-workflow:
name: call-other-workflow
needs: [ print-sha, prep ]
uses: ./.github/workflows/other_workflow.yml
with:
commit-hash: ${{ needs.prep.outputs.sha }}
现在一切正常了。太棒了。