This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
generated from fmjstudios/boilerplate-terraform-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
165 lines (136 loc) · 3.86 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Copyright (C) 2023 The FMJ Terraform Authors <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
DBG_MAKEFILE ?=
ifeq ($(DBG_MAKEFILE),1)
$(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)")
$(warning ***** $(shell date))
else
# If we're not debugging the Makefile, don't echo recipes.
MAKEFLAGS += -s
endif
# #####################################
# CONFIGURATION
# #####################################
SHELL := /usr/bin/env bash -o errexit -o pipefail -o nounset
VIRTUAL_ENV := $(PWD)/.venv
export ROOT_DIR = $(shell git rev-parse --show-toplevel)
# #####################################
# SOURCES
# #####################################
FIND_FLAGS := -mindepth 1 -maxdepth 1 -type d
MODULES := $(shell find $(ROOT_DIR)/modules $(FIND_FLAGS))
SOURCES := $(COLLECTIONS)
# Only export variables from here since we do not want to mix the top-level
# Makfile's notion of 'SOURCES' with the different sub-makes
export
# BUILD OUTPUT
OUT_DIR := $(ROOT_DIR)/dist
COLLECTIONS_OUT_DIR := $(OUT_DIR)/collections
ROLES_OUT_DIR := $(OUT_DIR)/roles
SCRIPT_DIR := $(ROOT_DIR)/scripts
DOCS_DIR := $(ROOT_DIR)/docs
GIT_CLIFF_CONFIG := $(DOCS_DIR)/cliff.toml
DATE := $(shell date '+%d.%m.%y-%T')
# #####################################
# GENERAL VARIABLES
# #####################################
PRINT_HELP ?=
WHAT ?=
# #####################################
# CUSTOM FUNCTIONS
# #####################################
define log
@case ${2} in \
gray) echo -e "\e[90m${1}\e[0m" ;; \
red) echo -e "\e[91m${1}\e[0m" ;; \
green) echo -e "\e[92m${1}\e[0m" ;; \
yellow) echo -e "\e[93m${1}\e[0m" ;; \
*) echo -e "\e[97m${1}\e[0m" ;; \
esac
endef
define log_info
$(call log, $(1), "gray")
endef
define log_success
$(call log, $(1), "green")
endef
define log_notice
$(call log, $(1), "yellow")
endef
define log_attention
$(call log, $(1), "red")
endef
# #####################################
# TARGETS
# #####################################
# make / make all - Build code
define ALL_HELP_INFO
# Build all or some Terraform modules.
#
# Arguments:
# WHAT: The module names to build.
endef
.PHONY: all
ifeq ($(PRINT_HELP),1)
all:
echo "$$ALL_HELP_INFO"
else
all:
$(call log_notice, "Building artifact for: $(WHAT)")
$(MAKE) -C $(WHAT) build
$(call log_success, "Test for $(WHAT) succeeded!")
endif
# make test - Test code
define TEST_HELP_INFO
# Test all or some Terraform modules.
#
# Arguments:
# WHAT: ...
# TESTS: ...
endef
.PHONY: test
ifeq ($(PRINT_HELP),1)
test:
echo "$$TEST_HELP_INFO"
else
test:
$(call log_notice, "Testing $(WHAT)")
$(MAKE) -C $(WHAT) test
$(call log_success, "Test for $(WHAT) succeeded!")
endif
# make changelog - Generate CHANGELOG documents
define CHANGELOG_HELP_INFO
# Generate CHANGELOG documents for all or some Terraform modules.
#
# Arguments:
# WHAT: ...
endef
.PHONY: changelog
ifeq ($(PRINT_HELP),1)
changelog:
echo "$$CHANGELOG_HELP_INFO"
else
changelog:
$(call log_notice, "Generating CHANGELOG's for: $(WHAT)")
$(MAKE) -C $(WHAT) changelog
$(call log_success, "CHANGELOG generation for $(WHAT) succeeded!")
endif
# make clean - Clean up after builds
.PHONY: clean
clean:
@echo Removing temporary distribution directories..
@rm -rf $(OUT_DIR)
# #####################################
# DEPENDANT RECIPES
# #####################################