FYI this will be a real pain the first time somebody on your team needs to push up code that won’t compile so that a team member can help them.
I agree with @hauleth, this is the problem to solve. You can put specific rules about specific branches, rules about how PRs get merged etc, and it lets you handle mix credo and mix test centrally too.
I have a shell script in every project I work on called bin/dev/shipit.
It does all the things such as:
runs mix audit
runs the formatter
If all those things pass, then it pushes. It’s very simple but it works (if everyone remembers to run it instead of just git push). If you for some reason need to push with one or more of those steps failing, you can just not run the script but instead just run git push.
I am strongly against imposing workflows on developers collaborating on a project. Everybody has a different order/process for producing code that is ready for review, and until its ready for review (and CI) all barriers and challenges should be minimized. If part of your process is to autoformat your code on every commit using a git hook, by all means do that, but please, please don’t impose that on your fellow devs who do not want to think about formatting at all until everything is ready.
I like writing a custom mix ci task/alias. The CI server should be configured to execute that, but also each developer can choose to run that on their own machine in case they need help diagnosing a problem that only occurs on CI.
I agree with this. My approach is simply just to have our CI pipeline runs mix format --check-formatted.
It is then up to the individual developer to choose how to ensure that all the code they push is formatted. Most of our devs use VS Code and have “format on save” configured, one dev uses vim and simply does mix format && git add -p whenever they’re setting up a commit.
Where are you hosting your code? It can be very simple to set up CI (at least a basic one that checks formatting and runs tests), and I can probably suggest a simple way of doing it based on where your code lives.