From e3f6cf98e28c878f83ebc753dd81d16130aa1b29 Mon Sep 17 00:00:00 2001 From: Oanh Nguyen Date: Mon, 30 Jan 2023 18:50:04 +0700 Subject: [PATCH] Update makefile --- .github/workflows/run-linting.yml | 2 +- Makefile | 76 +++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/.github/workflows/run-linting.yml b/.github/workflows/run-linting.yml index 8de3f12..6d25d9f 100644 --- a/.github/workflows/run-linting.yml +++ b/.github/workflows/run-linting.yml @@ -35,7 +35,7 @@ jobs: - name: Run TFLint run: | - terraform fmt + terraform fmt --recursive tflint -f compact --module - name: Commit changes diff --git a/Makefile b/Makefile index 2864183..a17d852 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,65 @@ -.PHONY: all init docs lint format help +SHELL=/bin/bash -all: format lint docs +# to see all colors, run +# bash -c 'for c in {0..255}; do tput setaf $c; tput setaf $c | cat -v; echo =$c; done' +# the first 15 entries are the 8-bit colors -docs: - terraform-docs markdown . \ - --sort-by required \ - --output-file README.md \ - --output-mode insert +# define standard colors +ifneq (,$(findstring xterm,${TERM})) + BLACK := $(shell tput -Txterm setaf 0) + RED := $(shell tput -Txterm setaf 1) + GREEN := $(shell tput -Txterm setaf 2) + YELLOW := $(shell tput -Txterm setaf 3) + LIGHTPURPLE := $(shell tput -Txterm setaf 4) + PURPLE := $(shell tput -Txterm setaf 5) + BLUE := $(shell tput -Txterm setaf 6) + WHITE := $(shell tput -Txterm setaf 7) + RESET := $(shell tput -Txterm sgr0) +else + BLACK := "" + RED := "" + GREEN := "" + YELLOW := "" + LIGHTPURPLE := "" + PURPLE := "" + BLUE := "" + WHITE := "" + RESET := "" +endif -format: - terraform fmt --recursive +# HELP +# This will output the help for each task +# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.DEFAULT_GOAL := help -init: +.PHONY: help +help: ## This help + @echo "Usage:" + @echo "" + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST) + @echo "" + +.PHONY: build +build: install lint validate docs ## Build module + +.PHONY: install +install: ## Setup development environment tflint --init + terraform init -upgrade -lint: - terraform fmt --check +.PHONY: lint +lint: ## Lint Terraform files + terraform fmt --recursive tflint --format compact --module -help: - @echo "Usage:" - @echo " make Format, lint and generate document" - @echo " make init Install tflint plugins" - @echo " make format Format all *.tf files" - @echo " make lint Lint check" - @echo " make docs Generating document (README.md)" +.PHONY: validate +validate: ## Validate Terraform files + terraform fmt --check + terraform validate + +.PHONY: docs +docs: ## Generate README.md + terraform-docs markdown . \ + --sort-by required \ + --output-file README.md \ + --output-mode insert