Created
May 16, 2024 21:47
-
-
Save udovichenko/2c77fffa34d421cd76dfc0cfd66badbe to your computer and use it in GitHub Desktop.
Makefile template with help suggestions and checking environment ability for each command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ONESHELL: | |
$(VERBOSE).SILENT: | |
SHELL := /bin/bash | |
CYAN := \033[0;36m | |
NC := \033[0m | |
.DEFAULT_GOAL := help | |
help: | |
grep -E '^[a-zA-Z_-]+:[ \t]+.*?# .*$$' $(MAKEFILE_LIST) | sort | awk -F ':.*?# ' '{printf " ${CYAN}%-24s${NC}\t%s\n", $$1, $$2}' | |
ifeq (,$(filter check-env,$(MAKECMDGOALS))) | |
ifeq (,$(wildcard .env)) | |
$(error No .env file found. Add it before running any tasks!) | |
endif | |
endif | |
check-env: | |
if [ ! -f .env ]; then echo "No .env file found. Exiting."; exit 1; fi | |
get-env: check-env # get APP_ENV from .env file | |
$(eval APP_ENV := $(shell grep -m 1 ^APP_ENV .env | cut -d '=' -f2)) | |
only-local: get-env # check if local environment | |
if [ "$(APP_ENV)" != "local" ]; then echo "Not a local environment. Exiting."; exit 1; fi | |
echo "Running local tasks..." | |
only-staging: get-env # check if staging environment | |
if [ "$(APP_ENV)" != "staging" ]; then echo "Not a staging environment. Exiting."; exit 1; fi | |
echo "Running staging tasks..." | |
check-prod: get-env # check if prod environment | |
if [ "$(APP_ENV)" != "prod" ]; then echo "Not a production environment. Exiting."; exit 1; fi | |
echo "Running production tasks..." | |
echo-local: only-local # echo only if local | |
echo "Local environment" | |
echo-staging: only-staging # echo only if staging | |
echo "Staging environment" | |
echo-prod: check-prod # echo only if prod | |
echo "Production environment" | |
dev-back: # run PHP development server | |
php artisan serve | |
dev-front: # run nodejs development server | |
npm run dev | |
prod-install: check-prod # install process after deploy to hosting | |
echo "Installing on prod... TODO..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment