by sparsely · 5y ago · 0 comments
I occasionally see statements like this floating around - does he mean:
* Devs make their changes locally, commit and push directly to main, and then the CI/CD either notifies them that tests failed or deploys to prod
or
* Devs make their changes locally, commit and push on a branch, and rapidly (ideally automatically) merge to main if tests pass. This happens on a cycle of minimum coherent set of code changes, not a whole feature at a time or anything like that.
The first seems like it would be very frustrating if code with failing tests if pushed with any frequency, but seems to be literally what the phase "work on main" means. I also don't really see a drawback to the second one in comparison.
It's very unusual to merge more than one commit to master at a time.
You can think of it as a branch and merge approach, but the set of changes is small - a 100-line diff would be a large change (automated changes and deleting unused code excepted). The process and tooling optimizes for small changes. Refactoring is done incrementally. Big changes are gated with flags so they can be built incrementally and rolled out incrementally and turned off at the first sign of trouble.
For larger features, these changes could be stacked in a list. After each change in the list had been approved, they’d be landed on main as an all or nothing.
Yep, that's the point - it's to discourage devs from checking in failing code (because then they'll be swarmed by annoyed coworkers). It's fairly common to see developer A make a breaking change to some low-level library and then see developer B push a rollback of A's changes a few minutes later (with or without A's permission).
And presumably there is no need for a staging env, since your code is deployed to production as soon as it has passed tests.
Edit: Just to clarify, it isn't ok to break downstream projects, if you do the change gets rolled back almost immediately. And you can run all tests for the change before submitting, but it isn't default since it is expensive for many core projects to run so many tests.
No, in trunk-based development, you push to the trunk, aka master.
The difference is perhaps not that big; with TBD, you have a branch, but only on your machine, which you merge to master before pushing, whereas with the second workflow, you push your master, then merge somehow.
> their intermediate setup seems impractical technically for most setups - how do you run standard tests without committing your code, unless you do everything locally?
I don't understand this. Of course you can and should run all tests locally.
If you follow the ops link there are multiple diagrams where that is not the case.
Not saying I have a better solution off the top of my head, but "just fix it with another commit" is a big red flag IME.
And
"The short-lived feature branch should only last a day or two and never diverge from the trunk enough so that a merge back is problematic. After the seal of approval from code reviewers and CI daemons, it should be merged back into the trunk. It should be deleted, as proof of convergence. The developer in question may then go ahead and make the next short-lived feature branch for the next story/task they’re doing" https://trunkbaseddevelopment.com/youre-doing-it-wrong/#dura...
So yes, you work locally on a fork of the repo but not the main/master repo. I'd surprised if all devs have access to push to main/master.
I think having branches leads to a lot of merging issues. Because technically, the branch will then be used by multiple devs. So it's like dealing with multiple masters, kind of.
Personally, I prefer the TF approach. Oh I forgot to mention, the release tags are branches I think, perhaps read only branches.
For the rest the merging issues are identical. You can still have a merge conflict between downstream/master and origin/master if someone merged something conflicting into origin/master since the fork happened.
https://docs.github.com/en/repositories/configuring-branches...
A fork is still a lot less friction. Otherwise, technically yes it is a branch.