GitHub操作:向触发当前工作流的公关工作流发布评论 [英] Github actions: Post comment to PR workflow that triggered the current workflow
本文介绍了GitHub操作:向触发当前工作流的公关工作流发布评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个工作流,第一个运行构建脚本并生成构件。 第一个是在创建拉流请求时触发的:
name: build
on:
pull_request:
types: [opened, edited, ready_for_review, reopened]
第二个流程在第一个流程完成时运行,使用如下workflow_run
触发器:
on:
workflow_run:
workflows: ["build"]
types:
- "completed"
第二个流必须是独立的,并在第一个流之后运行。完成后,它应该在触发第一个工作流程的PR上发布评论,但我无法找到如何操作。
根据Github Action Docs,这是一个典型的用例,根据这个问题:
For example, if your pull_request workflow generates build artifacts, you can create
a new workflow that uses workflow_run to analyze the results and add a comment to the
original pull request.
但我似乎找不到办法。我可以在第二个工作流的context.payload.workflow_run.id
中获取第一个工作流的ID,但workflow_run
也应该有关于拉入请求的ID,但它们是空的。
我做错了什么,我在哪里可以找到必要的信息,以便能够对我创建的拉式请求发表评论?
推荐答案
您没有做错什么,只是第一个工作流中的拉取请求数据不在第二个工作流的Github Context
中。
若要解决问题,您可以将所需的拉式请求数据从第一个工作流发送到第二个工作流。
有多种不同的方法,例如使用dispatch event(而不是工作流运行)或项目。
对于该构件,它将如下所示:
在第一个工作流中,您从githorb.Event获取请愿书编号。然后将该数字保存到文件中,并将其作为人工制品上载。
- name: Save the PR number in an artifact
shell: bash
env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}
run: echo $PULL_REQUEST_NUMBER > pull_request_number.txt
- name: Upload the PULL REQUEST number
uses: actions/upload-artifact@v2
with:
name: pull_request_number
path: ./pull_request_number.txt
在第二个工作流中,您将使用以下GitHub应用程序从第一个工作流中获取项目和Pull Request number
:
- name: Download workflow artifact
uses: dawidd6/action-download-artifact@v2.11.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: <first_workflow_name>.yml
run_id: ${{ github.event.workflow_run.id }}
- name: Read the pull_request_number.txt file
id: pull_request_number_reader
uses: juliangruber/read-file-action@v1.0.0
with:
path: ./pull_request_number/pull_request_number.txt
- name: Step to add comment on PR
[...]
这篇关于GitHub操作:向触发当前工作流的公关工作流发布评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文