Use Makefiles in hanami gems

Hi everyone. I was wondering if any of you ever has experienced the use the “make” utiliity for project tasks?

It’s a simple technique that I’ve learnt in my previous job 10 years ago, that I’m still using today with my team. I’m loving it so much that I cannot resist to share it with you all.

The idea is to wrap main project commands (related to build, test, setup…) in a Makefile with (phony) targets. It has several advantages:

  • leveraging muscle memory to speed up repetitive actions around project contributions
  • documenting the “entry points” for contributors without writing to much bash scripts
  • reducing cognitive load between projects, because most of the tasks often have the same name

Here how it can look like in real life:

# Makefile
.PHONY: install update ci test
	
# Install gems & deps
install:
	bundle install
	npm install

# Update gems & dependencies
update: install
	bundle update
	npm update

# Launch CI checks
ci:
	./script/ci

# Launch automated tests only
test:
	bundle exec rake

You can then use any of the previously described tasks like that:

make install
make update
make test
make ci

It’s so simple that even on projects on which I contribute, I create this file without commiting it, to help me go faster.

Is it just a personnal taste, or do you think it would benefit to others?
Let me know!

Cheers, Edouard

You are certainly not alone. The biggest Ruby project using Makefiles I know is RailsEventStore. I’m personally not a fan of the syntax, but the idea alone is fine IMO. I would, however, probably opt for Just myself.

Yeah you’re very likely not alone, but personally I wouldn’t be sure about including Makefiles as a default. Ruby’s default tends to be to use rake, not make, and Hanami does already generate a Rakefile for applications!

Thank you for the feedback. “Just” indeed looks awesome, more modern than Make, but with the same idea of productivity in mind.
I’d love to help deploying it across hanami gems

Thank you for the feedback. As a heavy user of Rakefile for my project tasks, I still think that they do not serve the same purpose as Makefile (or equivalent). Rake is for the “inside” of the project, the ruby part, whereas Makefile is for the outside, the gluing of tools together, that are not necessarily in ruby.

“Just”, proposed by @katafrakt , seems like a great approach, and does things really differently than rake tasks.

One advantage of Make compared to Just, however, is how widespread it is in operating systems & distros. There’s nowhere that you don’t have (or can’t easily get) make installed.