![](/img/trans.png)
[英]GET pull request merge commit sha from pull request number using github api
[英]What is a predictable commit sha to use when merging pull request to a master using GitHub actions?
我正在使用 [github-actions]。 我有兩個工作流程:
pull_request
觸發push
觸發on:
workflow_dispatch:
pull_request:
branches:
- master
on:
workflow_dispatch:
push:
branches:
- master
pull_request
工作流生成需要在push
工作流中使用的資產。 我需要某種標識符來連接兩個工作流,最好是 git merge commit 的 SHA。 但是,我無法確定可靠的使用參考。
目前我在pull_request
工作流中使用${{ github.event.pull_request.head.sha }}
,在push
工作流中我使用:
- name: Setup repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set CI_COMMIT_SHORT_SHA env property
shell: bash
run: echo "CI_COMMIT_SHORT_SHA=$(git rev-parse --short=8 HEAD^2)" >> $GITHUB_ENV
這在大多數情況下都有效,但是當提交在合並之前被強制推送到 PR 分支時會中斷。
將pull_request
與push
工作流相關聯的可靠git參考是什么?
如果您只想在 PR 合並到 master 時觸發第二個工作流,您可以使用pull_request.closed
事件。 在該工作流程中, $GITHUB_REF
應該讓您獲得對 PR 合並分支 (refs/pull/:prNumber/merge) 的引用。 將這兩個工作流程聯系在一起對您有用嗎?
on:
pull_request:
branches:
- master
types: [closed]
另外,請注意,要忽略未合並的已關閉 PR,您需要在作業中添加一個條件以在這種情況下跳過它: if: github.event.pull_request.merged == true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.