8

Optimize Pull Requests in Travis CI

 2 years ago
source link: https://blog.travis-ci.com/2022-01-28-pullrequests
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Optimize Pull Requests in Travis CI

Jan 28, 2022 |

Montana Mendy

| news

TCI-Graphics for AdsBlogs (4)

One thing you might want when using Travis or any CI tool is to prevent broken code from getting merged, this makes for quality pull requests and making sure nothing broken gets merged. Let’s take a dive into Pull Requests in Travis.

Branch Protection

Branch protection is something you may not know about, you can create a branch protection rule to enforce certain workflows for one or more branches. So for example we want status checks to pass before merging, let’s take a look in GitHub:

image

This will enforce that the status check pass is required before anything gets merged to a branch.

2 Branches or 1 Branch?

By default in Travis GUI, you’ll see both boxes enabled, this is due to the fact that Travis is running a build on the branch and a build on the pull request:

Screen Shot 2022-01-28 at 12 22 09 PM

Leaving it on will allow you to fully explore all the deploy/branching options we have to offer. What if you want the opposite though? To build on a pull request without redundancy?

Build Pull Requests and Merges to the Master Branch

Assuming you want to build all PRs, something like the following will do the trick, you’ll need to enable both the branch and PR builds on the settings page like we showed above, but have all boxes ticked, and put this line as the first line in your travis.yml:

if: (type = push AND branch IN (master, dev)) OR (type = pull_request AND NOT branch =~ /no-ci/)

This will attempt a push build on all pushes and a PR build on all pushes to an open PR, but will filter out any that don’t meet the conditionals you set it place. Read more about conditional builds here.

Switch this off

If you don’t want this by default in your build (PR’s triggering a build), you can do this in the GUI as well, via:

image

If ON, builds will be run on new pull requests. So the answer would be to turn it off:

image

Conclusion

There you go, you just got an inside look on how flexible pull request management is in Travis! Now, take full advantage of your branches and workflow.

As always if you have any questions, any questions at all, please email me at [email protected].

Happy building!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK