<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chris Allen</title>
    <description>The latest articles on DEV Community by Chris Allen (@chrisallen).</description>
    <link>https://dev.to/chrisallen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1419556%2F335efb8a-a0bc-43a8-aff9-1c2ba018198e.jpeg</url>
      <title>DEV Community: Chris Allen</title>
      <link>https://dev.to/chrisallen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chrisallen"/>
    <language>en</language>
    <item>
      <title>Only Building Pull Requests on CircleCI  -  How Greed Hinders Efficiency</title>
      <dc:creator>Chris Allen</dc:creator>
      <pubDate>Thu, 11 Apr 2024 20:07:30 +0000</pubDate>
      <link>https://dev.to/chrisallen/only-building-pull-requests-on-circleci-how-greed-hinders-efficiency-95e</link>
      <guid>https://dev.to/chrisallen/only-building-pull-requests-on-circleci-how-greed-hinders-efficiency-95e</guid>
      <description>&lt;p&gt;At a surface level, it should make sense why you would only want to run CI builds on pull requests. If you're like me, you're constantly force pushing &lt;a href="https://en.wikipedia.org/wiki/Work_in_process"&gt;WIP&lt;/a&gt; commits to a git remote either because you're switching between machines or you just want piece of mind knowing it's okay if your laptop bites the dust. If we strive for &lt;a href="https://dev.to/samuelfaure/how-atomic-git-commits-dramatically-increased-my-productivity-and-will-increase-yours-too-4a84"&gt;atomic commits&lt;/a&gt;, there are few reasons why we should be burning Earth's resources on linting and testing our work prior to opening a PR.&lt;/p&gt;

&lt;p&gt;CircleCI provides an easy way to only run builds on PRs. You can navigate to &lt;strong&gt;Project Settings&lt;/strong&gt; &amp;gt; &lt;strong&gt;Advanced&lt;/strong&gt; and toggle "Only build pull requests".&lt;/p&gt;

&lt;h2&gt;
  
  
  That was easy. What's the gotcha?
&lt;/h2&gt;

&lt;p&gt;So far the UX for setting up your CircleCI project has been pretty straight forward. You toggled a setting on. You pushed a feature branch up. As you hoped, it doesn't build until you open a PR. It &lt;em&gt;rebuilds&lt;/em&gt; when you push updates to the branch. You even convinced someone to stamp the PR 😉. Life is great.&lt;/p&gt;

&lt;p&gt;You press merge, drag the ticket to the QA column and pat yourself on the back. There's just one problem. The PR was merged in to the &lt;strong&gt;dev&lt;/strong&gt; branch and CircleCI didn't run a build (the one that's supposed to … deploy the changes). At this point, you should say to yourself "&lt;em&gt;I must've missed something&lt;/em&gt;". Let's read the fine print of this "Only build pull requests" setting:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0iz6fecv8c9xdanaltvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0iz6fecv8c9xdanaltvk.png" alt="For your default branch and tags, we well always build all commits" width="532" height="53"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That seems useful! The default branch is usually &lt;strong&gt;main&lt;/strong&gt; or &lt;strong&gt;prod&lt;/strong&gt;. But what about &lt;strong&gt;dev&lt;/strong&gt;, &lt;strong&gt;uat&lt;/strong&gt;, &lt;strong&gt;staging&lt;/strong&gt;,  or any branch you want to automatically deploy using CircleCI? There's likely more git refs you want to run builds on other than "default branch and tags".&lt;/p&gt;

&lt;h2&gt;
  
  
  Greed is the root of all evil
&lt;/h2&gt;

&lt;p&gt;Your likely next step is to mash the keyboard on google until you find someone else with the same problem. To your disgust, you find multiple accounts (&lt;a href="https://discuss.circleci.com/t/allow-branch-whitelist-to-override-only-build-pull-requests/6392"&gt;2016&lt;/a&gt; &lt;a href="https://circleci.canny.io/cloud-feature-requests/p/allow-branch-whitelist-to-override-only-build-pull-requests"&gt;2018&lt;/a&gt;) of this limitation and varying solutions that mostly rely on manually hitting the CircleCI API to achieve the desired behavior of triggering builds both on pull requests and deploy branches.&lt;/p&gt;

&lt;p&gt;This seems like a very simple feature that &lt;strong&gt;&lt;em&gt;many&lt;/em&gt;&lt;/strong&gt; users desire. Why would CircleCI, a company valued at $1.7 billion in 2021, not invest the man-hours for such an easy feature?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwh7kou8nou9zdccvdk6q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwh7kou8nou9zdccvdk6q.gif" alt="Scrooge counting his money" width="498" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The alternative to only running builds on PRs is, you guessed it, run builds on &lt;em&gt;every&lt;/em&gt; commit. I'm speculating, but I'd wager that this feature was discussed internally as it kept popping up in community posts. I like to think that it went down like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Dev Team:&lt;/strong&gt; This is a really easy ticket and a feature we would want as a user. Can we just knock it out?&lt;br&gt;
&lt;strong&gt;Product Manager:&lt;/strong&gt; Let me run it up the flagpole.&lt;br&gt;
&lt;strong&gt;Finance:&lt;/strong&gt; So, it would be really useful but incentivize users to run less builds by orders of magnitude?&lt;br&gt;
&lt;strong&gt;Product Manager:&lt;/strong&gt; Yes.&lt;br&gt;
&lt;strong&gt;Finance:&lt;/strong&gt; Yeah no chance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A wild solution appears
&lt;/h2&gt;

&lt;p&gt;Fast forward to April 2023. A CircleCI employee creates a forum &lt;a href="https://discuss.circleci.com/t/product-launch-override-only-build-prs-setting/47807"&gt;post&lt;/a&gt; outlining a new field exposed through the API for tweaking project settings. This field, called &lt;strong&gt;pr-only-branch-overrides&lt;/strong&gt;, is exactly what we've needed for nearly a &lt;em&gt;decade&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;As outlined in the post, you can do a simple, one-time curl to set the list of branches to run builds on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; PUT &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Circle-Token: &amp;lt;token&amp;gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Accept: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data&lt;/span&gt; &lt;span class="s1"&gt;'{"feature_flags":{"pr-only-branch-overrides": "prod, dev, staging"}}'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"https://circleci.com/api/v1.1/project/&amp;lt;vcs_type&amp;gt;/&amp;lt;org_slug&amp;gt;/&amp;lt;repo_name&amp;gt;/settings"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Despite the endpoint existing since April, documentation only hit open preview as of &lt;a href="https://discuss.circleci.com/t/project-settings-api-v2-endpoints-now-in-open-preview/49999"&gt;December&lt;/a&gt; which you have to dig for.&lt;/p&gt;

&lt;p&gt;As of this writing, it's been a year since the endpoint was introduced. Why isn't it configurable from the UI? Why did we get the endpoint at all? I could take a guess...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;2016 Hobby user:&lt;/strong&gt; We need this feature!&lt;br&gt;
&lt;strong&gt;CircleCI:&lt;/strong&gt; **crickets**&lt;br&gt;
&lt;strong&gt;2018 Hobby user:&lt;/strong&gt; If we don't get this feature, I'm just going to use Github actions!&lt;br&gt;
&lt;strong&gt;CircleCI:&lt;/strong&gt; **crickets**&lt;br&gt;
&lt;strong&gt;2023 Cash-Cow Client:&lt;/strong&gt; If we don't get this feature, we're moving elsewhere.&lt;br&gt;
&lt;strong&gt;CircleCI:&lt;/strong&gt; Here's an endpoint!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I enjoy the product that CircleCI offers, but this is not a good look and I've lost a fair amount of trust (all &lt;a href="https://circleci.com/blog/jan-4-2023-incident-report/"&gt;breaches&lt;/a&gt; aside). I would've hoped that competition in the CI/CD space would push &lt;em&gt;all&lt;/em&gt; services forward, but alas, money talks.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
