Live data from Hacker News

Use Task Runners for Common Coding Tasks

hamvocke.com

31–33 of 33 posts

Re: Use Task Runners for Common Coding Tasks

#31
post #30

Earlier quoted context omitted.

One issue with Just is that by default each line in a recipe is executed in a sub shell. Set a variable in line 1 and you can’t use it in line 2. Mise `run` blocks are embedded shell scripts. Alternatively, you can pull those scripts out into individual files so that you can edit them with syntax highlighting etc with any editor that understands shell scripts. Perhaps you can with just now, too, but mise makes it tri…

> One issue with Just is that by default each line in a recipe is executed in a sub shell. Set a variable in line 1 and you can’t use it in line 2. Mise `run` blocks are embedded shell scripts. just supports the same. If you begin a recipe with a shebang (#!/bin/bash), then it dumps the whole recipe to a file and executes it as a shell script. Not limited to bash - you can do the same with Python, etc. As for scripts…

There was something about the shebang method that made someone else that I wanted to use not work but I forget the details. In any case, just is very nice — I just like mise more at the moment.

The own-file bit comes in nice when you want to run them standalone (CI/CD; maybe someone doesn’t want to use the runner) or you’re fighting against escaping rules. I like having them in the mise file when they’re just a couple of lines. If it turns into a full-on thing, then I prefer to extract it.

Either way, options are nice.

Re: Use Task Runners for Common Coding Tasks

#33
post #9

I do this with plain ol' makefiles. Even for projects where Make isn't part of the build pipeline, like Rails or C++, I have a standardized makefile I put in the project root, using includes for "secrets.mk", so I can do things like "make deploy" and it Just Works(tm). Sometimes the old ways are best!

Another neat and simple trick it to have the first target in the Makefile print out a helpful message that tells the reader what the project is and how to use it. One of those things that is useful both when you are working on the project and when you later return to it, years later.

I use this pattern for my makefiles. First item is for "help", and it dynamically scrapes all the other commands (assuming format : ## ). So if I do 'make help' it'll list all the commands in the makefile without much extra work from me.

.PHONY: help

help: ## Show this help message

@grep -E '^[a-zA-Z_-]+:.?## .$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' @echo "" @echo "Examples:" @echo " make deploy" @echo " make deploy-branch BRANCH=feature-x" @echo " make deploy AUTO_START=true"

.PHONY: deploy

deploy: ## Deploy from current branch (default main) (use AUTO_START=true to restart service after)

@$(MAKE) _deploy BRANCH=$(git branch --show-current)

Post reply on HN