簡體   English   中英

使用 GitHub 操作將拉取請求合並到主節點時要使用的可預測提交 sha 是什么?

[英]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_requestpush工作流相關聯的可靠參考是什么?

如果您只想在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM