$TRAVIS_EVENT_TYPE != 'pull_request' 和 $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG 之间的区别

Difference between $TRAVIS_EVENT_TYPE != 'pull_request' and $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG

我正在尝试在 Travis 中设置 Chromatic。

我看到 Chromatic document 建议在 Travis 中使用此脚本

if [[ $TRAVIS_EVENT_TYPE != 'pull_request' || $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG ]];
then
  npm run chromatic
fi

有解释

Travis offers two type of builds for commits on pull requests: so called pr and push builds. It only makes sense to run Chromatic once per PR, so we suggest disabling Chromatic on pr builds for internal PRs (i.e. PRs that aren’t from forks). You should make sure that you have push builds turned on, and add the following code: [[THE CODE ABOVE]]

For external PRs (PRs from forks of your repo), the above code will ensure Chromatic does run on the pr build, because Travis does not trigger push builds in such cases.

Note: We recommend running Chromatic on push builds as pr builds can't always run and fall out of the normal git ancestry. For instance, if you change the base branch of a PR, you may find that you need to re-approve changes as some history may be lost.

Chromatic does work with Travis pr builds however!

然后我读了 Travis document 关于 TRAVIS_PULL_REQUEST_SLUGTRAVIS_REPO_SLUG 的文章。

TRAVIS_PULL_REQUEST_SLUG:

  • if the current job is a pull request, the slug (in the form owner_name/repo_name) of the repository from which the PR originated.

  • if the current job is a push build, this variable is empty ("").

TRAVIS_REPO_SLUG:

  • The slug (in form: owner_name/repo_name) of the repository currently being built.

所以我的理解是 $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG 时,它是一个 push 构建,那么为什么它仍然需要 $TRAVIS_EVENT_TYPE != 'pull_request'

它们有什么区别吗?

来自 Chroma 的 Gert。

我们建议 运行 只有当构建不是来自拉取请求(即推送构建),或者是来自分叉的拉取请求构建时,才使用 chromatic,在这种情况下,PR slug 与 repo slug 不同。

根据引用的 Travis 文档,在推送构建的情况下,TRAVIS_PULL_REQUEST_SLUG 为空,在从分叉构建 PR 的情况下,它将引用分叉的回购所有者。在任何一种情况下,它都将不同于 TRAVIS_REPO_SLUG。所以你是对的,这个条件的左边是多余的。随意省略。