Skip to content

Commit

Permalink
Update makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
oanhnn committed Jan 30, 2023
1 parent fca24c1 commit e3f6cf9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Run TFLint
run: |
terraform fmt
terraform fmt --recursive
tflint -f compact --module
- name: Commit changes
Expand Down
76 changes: 57 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e3f6cf9

Please sign in to comment.