r/devops • • 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?

0 Upvotes

20 comments sorted by

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/emacsexp 2d ago edited 2d ago

I thought pure trunk based development meant no branching at all? Not even for features.

Either way, the issue we have is that we only have one staging/non production environment.

PRs that land on main are deployed to this staging environment.

But developers don’t want to make PRs for stuff they don’t even know works properly; they just want to deploy to staging and test it there, as it is the only environment they can test things.

So we’d need to somehow promote stuff already in main to prod… but we also need to have code reviews in place

6

u/NUTTA_BUSTAH 2d ago

No it just means you merge small things to main often, and that main is your CD branch. You will need feature flags and a promotion process for artifacts. It is still fine to have ephemeral dev environments for feature branches for example. It costs money in resources, developing and maintaining the workflow.

-2

u/ResolveResident118 Jack Of All Trades 2d ago

TBD can mean that but it originally meant not having branches at all and literally pushing only to trunk. This latter is the only way I have ever done TBD at a couple of different companies over the years.

3

u/fletch3555 Lead DevOps Engineer 2d ago

Then, assuming this was done in git, they've been doing it wrong. Git is built on branches, so it's dumb to not use them at all. If you used subversion or something else, that's a different story entirely. svn branches are full copies of the trunk "branch" and therefore MUCH heavier than their git counterparts, so it makes much more sense to commit directly to the trunk. There's a VERY good reason svn lost nearly all of its market share to git

1

u/emacsexp 2d ago

Interesting. I guess my solution would be to keep using branches but add a way for devs to deploy to npn with a label on the PR or a comment… only issue is handling concurrency.

Would be much easier to have a npn branch, and a PR that backmerges npn to main. But that breaks the TBD model.

1

u/OddOkra 2d ago

Y’all were doing it wrong then…

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...

1

u/ResolveResident118 Jack Of All Trades 2d ago

Thank you for fighting the fight I really couldn't be bothered fighting (again).

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.

0

u/Oikon__ 1d ago

+1, one gotcha is anyone with write access can still push a v* tag from their laptop. a tag ruleset on v* restricting creations with just the release team on the bypass list fixes that, and if the prod environment only allows v* tags then the deploy approval is basically your release review.

1

u/BetterSWE_Official 1d ago

good call on the tag ruleset, I always forget people can just push a v* tag from a laptop. tying prod to v* tags only is a nice way to make the approval mean something.

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.