在GitHub上进行PR操作期间,实际上运行什么版本的代码? [英] During a PR action on GitHub, what version of the code is actually run?

查看:50
本文介绍了在GitHub上进行PR操作期间,实际上运行什么版本的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试阅读有关此内容的GitHub文档,并尝试在Google上搜索有关它的一些信息,但是这些信息丢失了,或者我只是无法理解它:)

I've tried to read the GitHub documentation on this and tried to google some information about it, but either the information is missing or I'm just unable to understand it :)

无论哪种方式,我都会使用一个示例(python)来说明问题:

Either way, I'll use an example (python) to illustrate the problem:

foo.py :

my_list = [
    1,
    2,
]
assert len(my_list) == 2

到目前为止,很好.

创建新分支:

foo.py 在分支 feat_a

my_list = [
    0,
    1,
    2,
]
assert len(my_list) == 3

还有一个单独的功能分支:

And a separate feature branch:

foo.py 在分支 feat_b

my_list = [
    1,
    2,
    3,
]
assert len(my_list) == 3

然后我将 feat_a 合并到 master 中.现在的问题是我的 feat_b 的PR可以完美地合并,这将创建从0到3的4个项的列表.但是assert语句将在合并提交之后失败.换句话说,我有两个分支,它们可以很好地运行并且可以合并,但是在合并提交之后处于不良状态.

I then merge feat_a into master. The problem now is that my PR for feat_b is perfectly mergeable which will create the list with 4 items from 0 to 3. But the assert statement will fail after the merge commit takes place. In other words, I have two branches that runs perfectly fine on their own and are mergeable, but are in a bad state AFTER the merge commit.

所以我的问题是这样的:当我运行GitHub操作时,如何确保该操作运行合并的代码?这是默认行为吗?

So my question is this: When I run a GitHub action, how can I make sure that the action runs the merged code? Is this the default behavior or not?

推荐答案

如果您使用

It will run on the merged code if you, f.e., use the checkout action with default values.

如果您查看

If you look at the event data of a pull request you get something like the following (shortened)

{
  "ref": "refs/pull/1/merge",
  "sha": "<sha-1>",
  "event": {
    "number": 1,
    "pull_request": {
      "head": {
        "ref": "<base-branch>",
        "sha": "<sha-2>"
      }
    }
  }
}

并且工作流运行的哈希与您的拉取请求的基本分支上的提交的哈希不同.

and the hash the workflow is running on is different to the hash of the commit on the base branch of your pull request.

这篇关于在GitHub上进行PR操作期间,实际上运行什么版本的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆