如何配置Travis-CI来构建拉取请求&合并以掌握没有冗余 [英] How to configure Travis-CI to build pull requests & merges to master w/o redundancy

查看:185
本文介绍了如何配置Travis-CI来构建拉取请求&合并以掌握没有冗余的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以BDD的形式表达:


背景:

鉴于我对a GH repo


当我创建一个pull请求

然后Travis应该建立最新的commit



当我推送到现有的pull请求

然后Travis应该建立最新的commit



当我合并pull request to master

然后Travis应该建立master

我被Travis-CI的build push 和构建PR设置,如下所示:




  • 启用这两种方法都会导致每次请求都由Travis构建两次


    • 在该分支上提交一次

    • 并再次将该分支合并到其目标中


    • 启用构建PR会导致构建PR,但不会导致合并后构建(即在主数据库中)。

    • 启用推送蛮力ce通过建立 all 推动回购协议满足上述标准。你可以尝试用白色&黑名单分支,但这可能会咬你,除非你严格遵守分行名称。



    这在< Travis-CI文档和


    1. .travis.yml 更改为


      To put it in "BDD" terms:

      Background:
      Given I'm contributing to a GH repo

      When I create a pull request
      Then Travis should build the latest commit

      When I push to an existing pull request
      Then Travis should build the latest commit

      When I merge a pull request to master
      Then Travis should build master

      I was confused by Travis-CI's "build pushes" and "build PRs" settings, as:

      • Enabling both causes each Pull Request to be build twice by Travis
        • once for the commit on that branch
        • and once again for the merge commit of that branch into its destination
      • Enabling just "build PRs" causes PRs to be built, but doesn't result in post-merge builds (i.e. on master).
      • Enabling "pushes" brute-force satisfies the above criteria by building all pushes to the repo. You can try to finagle things by white- & black-listing branches, but that will probably bite you unless you're rigorously disciplined with branch names.

      This is explained more in Travis-CI docs and GH issue #3241.

      Anyone know a configuration that satisfies the above criteria?

      解决方案

      I eventually found another GH issue (#2111) which gave me the idea to try enabling both PRs & pushes, but with a whitelist to restrict pushes to a specific branch. This seems to satisfy the criteria for my workflow. Here's what I did:

      1. Enable both PRs & branch pushes in the Travis settings for the repo:

      1. Change .travis.yml to white-list master branch (i.e. only build pushes to master):

      branches:
        only: 
          - master
      

      1. Test it by creating a PR with the .travis.yml change, and another PR with some empty commits to verify it works for forks too.

      2. Verify successful merge commit build from master.

      这篇关于如何配置Travis-CI来构建拉取请求&amp;合并以掌握没有冗余的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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