I've been using makefiles for a while and find them pretty good. The only downside is adding any arguments to recipes (passed when executing them) is tricky. On the other hand, there was only one scenario where that could be useful (release-staging
from below), but I managed to get what I wanted without arguments.
I like makefiles for portability and automatic shell completion for fish.
Here's a Makefile from one of the projects I'm working on to give a better idea of my usage:
QA_TARGET := "lib/main_qa.dart"
PROD_TARGET := "lib/main_prod.dart"
get-packages:
flutter pub get
code-generation:
dart run build_runner build --delete-conflicting-outputs
localizations:
dart run intl_utils:generate
apk-qa:
flutter build apk --target $(QA_TARGET)
appbundle-prod:
flutter build appbundle --target $(PROD_TARGET)
ipa-qa:
flutter build ipa --target $(QA_TARGET)
ipa-prod:
flutter build ipa --target $(PROD_TARGET)
launcher-icons:
dart run flutter_launcher_icons
release-staging:
$(eval DIFF := $(shell git diff -- pubspec.yaml | grep '^+version'))
@if [ -z "$(DIFF)" ]; then \
echo "Error: No changes in version. Aborting."; \
exit 1; \
fi
@OTHER_DIFF=$$(git diff -- './*' ':!pubspec.yaml'); \
if [ -n "$$OTHER_DIFF" ]; then \
echo "Error: Changes found outside of pubspec.yaml. Aborting."; \
exit 1; \
fi;
$(eval VERSION := $(shell awk '/^version: / {print $$2}' pubspec.yaml))
$(eval LAST_RELEASE_HASH := $(shell git log --pretty=format:'%H %s' | grep 'chore(build): Bump build number to' | awk 'NR==1{print $$1}'))
$(eval CHANGES := $(shell git log --pretty=format:'\n- %s' $(LAST_RELEASE_HASH)...HEAD))
@echo "chore(build): Bump build number to $(VERSION)\n\nChanges:$(CHANGES)" > commit_msg.txt
@echo "Releasing version $(VERSION) to STAGING"
git add pubspec.yaml
git commit -F commit_msg.txt
rm commit_msg.txt
git tag v$(VERSION)
git push
git push --tags