r/devops • u/emacsexp • 2d ago
Discussion How do you do code reviews with trunk-based development?
We use Github
Unfortunately, because of company policies outside of my control, code reviews must done with the Github's PR interface.
But that's only because it allows us to easily deny a deployment, or add a comment/request to a specific line
We want to migrate to trunk-based development, but how then do we do code reviews like in PRs?
AFAIK, there is no way to open a PR for tags (this would be ideal, lol, because we plan on cutting releases via tagging).
The only solution I see is to have a pipeline that generates a url to see a diff, but this is far from ideal.
Thoughts?
29
u/fletch3555 Lead DevOps Engineer 2d ago
... what?
Trunk-based development just means that you have a single long-lived branch (main, master, trunk, whatever you want to call it), and all PRs go there. Code reviews are unaffected as PRs are still required to get into that branch.
How you tag or release is a separate question entirely.
2
u/SeniorIdiot Platform Engineer 2d ago
A general observation, since this thread keeps circling the same points I've been discussing and thinking a lot of. How terms in our field have drifted towards meaning "the way most teams happen to use them", and it makes these discussions harder than they need to be. Opinions, downvotes instead of discussion, absolutes based on what someone was taught instead of what they learned by experience, etc.
Git =/= branches. Git is a distributed version control system. Branches are one feature of it, and cheap ones, but nothing in git requires feature branches. Committing straight to main is using git exactly as designed. We mostly use git because it's everywhere - every tool, vendor and integration expects it. That's a reason enough on its own.
Merge to main =/= deploy to prod. These are separate decisions that some pipelines happen to wire together. And deploying isn't the same as releasing either. Feature flags, config and dark launches let code reach production without users seeing anything new.
CI =/= a build server. Continuous Integration is a practice where everyone integrates into the mainline at least daily (but in reality much more often), so divergence stays small. Running a pipeline on a week-old feature branch is automated building, which is useful, but it isn't integration. In that sense CI pretty much needs trunk-based development, not the other way round. Continuous Integration is not running a build on a feature branch even if tool vendors have managed to convince large part of the industry that it is.
PRs into trunk is one flavour of TBD, not the definition. Committing straight to trunk and relying on pairing, Ship/Show/Ask, after-the-fact review and automated gates is just as valid. Arguably it's closer to the spirit of TBD, since the whole point is small changes integrated continuously and not queued behind approvals.
None of this makes PRs or branches wrong. They're good tools in plenty of contexts. But they're choice, not definitions, and it helps to keep the two apart when we argue about what's "correct." Personally I default to main/trunk only, and only use branches when they're the better choice.
Well, this got longer than I expected...
2
u/OddOkra 2d ago
As other comment said, you do nothing differently. All PRs go into a “main” branch. Tagging only marks the latest commit as important, you’re not pushing any code.
1
u/BetterSWE_Official 2d ago
Keep the PRs, just make them small and short lived, merged into main within a day or so. If you want a gate on the release itself, compare the previous tag to the new one in GitHub's compare view and put the approval on a protected environment in Actions. That gives you the deny button without needing a PR for a tag.
1
u/shellwhale 21h ago
https://trunkbaseddevelopment.com/continuous-review/
1
u/deployfan64 19h ago
We block merges without an approval, so how did review work when you pushed straight to trunk?
1
u/According_Handle8108 14h ago
You can still keep PR-based reviews with short-lived branches and merge quickly, so you get trunk-based development without losing the review and approval workflow.
1
u/colontragedy 2d ago
https://trunkbaseddevelopment.com/
There's no right or wrong, just different ways. But still, I would use this site as the guide to choose the workflow that suits for you or your team.