44
55.PHONY : build rebuild lint test _test-version _test-run-one _test-run-two tag pull login push enter
66
7- CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
8-
7+ # --------------------------------------------------------------------------------------------------
8+ # VARIABLES
9+ # --------------------------------------------------------------------------------------------------
910DIR = .
10- FILE = Dockerfile
11+ FILE_012 = Dockerfile-0.12
12+ FILE_011 = Dockerfile-0.11
1113IMAGE = cytopia/terraform-docs
1214TAG = latest
15+ NO_CACHE =
16+
17+
18+ # --------------------------------------------------------------------------------------------------
19+ # DEFAULT TARGET
20+ # --------------------------------------------------------------------------------------------------
21+ help :
22+ @echo " lint Lint this repository."
23+ @echo " build [TAG=x.y.z] Build terraform-docs docker image."
24+ @echo " rebuild [TAG=x.y.z] Build terraform-docs docker image without cache."
25+ @echo " test [TAG=x.y.z] Test built terraform-docs docker image."
1326
27+
28+ # --------------------------------------------------------------------------------------------------
29+ # BUILD TARGETS
30+ # --------------------------------------------------------------------------------------------------
1431build :
15- docker build --build-arg VERSION=$(TAG ) -t $(IMAGE ) -f $(DIR ) /$(FILE ) $(DIR )
32+ if [ " $( TAG) " = " 0.1.0" ] \
33+ || [ " $( TAG) " = " 0.1.1" ] \
34+ || [ " $( TAG) " = " 0.2.0" ] \
35+ || [ " $( TAG) " = " 0.3.0" ] \
36+ || [ " $( TAG) " = " 0.4.0" ] \
37+ || [ " $( TAG) " = " 0.4.5" ] \
38+ || [ " $( TAG) " = " 0.5.0" ] \
39+ || [ " $( TAG) " = " 0.6.0" ] \
40+ || [ " $( TAG) " = " 0.7.0" ]; then \
41+ docker build $(NO_CACHE ) --build-arg VERSION=$(TAG ) -t $(IMAGE ) -f $(DIR ) /$(FILE_011 ) $(DIR ) ; \
42+ else \
43+ docker build $(NO_CACHE ) --build-arg VERSION=$(TAG ) -t $(IMAGE ) -f $(DIR ) /$(FILE_012 ) $(DIR ) ; \
44+ fi
45+
46+ rebuild : NO_CACHE=--no-cache
47+ rebuild : build
1648
17- rebuild : pull
18- docker build --no-cache --build-arg VERSION=$(TAG ) -t $(IMAGE ) -f $(DIR ) /$(FILE ) $(DIR )
1949
50+ # --------------------------------------------------------------------------------------------------
51+ # LINT TARGETS
52+ # --------------------------------------------------------------------------------------------------
2053lint :
21- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-cr --text --ignore ' .git/,.github/,tests/' --path .
22- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-crlf --text --ignore ' .git/,.github/,tests/' --path .
23- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-trailing-single-newline --text --ignore ' .git/,.github/,tests/' --path .
24- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-trailing-space --text --ignore ' .git/,.github/,tests/' --path .
25- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-utf8 --text --ignore ' .git/,.github/,tests/' --path .
26- @docker run --rm -v $(CURRENT_DIR ) :/data cytopia/file-lint file-utf8-bom --text --ignore ' .git/,.github/,tests/' --path .
54+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-cr --text --ignore ' .git/,.github/,tests/' --path .
55+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-crlf --text --ignore ' .git/,.github/,tests/' --path .
56+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-trailing-single-newline --text --ignore ' .git/,.github/,tests/' --path .
57+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-trailing-space --text --ignore ' .git/,.github/,tests/' --path .
58+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-utf8 --text --ignore ' .git/,.github/,tests/' --path .
59+ @docker run --rm -v $(PWD ) :/data cytopia/file-lint file-utf8-bom --text --ignore ' .git/,.github/,tests/' --path .
2760
61+
62+ # --------------------------------------------------------------------------------------------------
63+ # TEST TARGETS
64+ # --------------------------------------------------------------------------------------------------
2865test :
2966 @$(MAKE ) --no-print-directory _test-version
3067 @$(MAKE ) --no-print-directory _test-run-one
@@ -64,7 +101,7 @@ _test-run-one:
64101 @echo ' <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/basic/TEST-$(TAG ) .md
65102 @echo >> tests/basic/TEST-$(TAG ) .md
66103 @echo ' <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/basic/TEST-$(TAG ) .md
67- @if ! docker run --rm -v $(CURRENT_DIR ) /tests/basic:/data $(IMAGE ) terraform-docs-replace md TEST-$(TAG ) .md; then \
104+ @if ! docker run --rm -v $(PWD ) /tests/basic:/data $(IMAGE ) terraform-docs-replace md TEST-$(TAG ) .md; then \
68105 echo " Failed" ; \
69106 exit 1; \
70107 fi ; \
@@ -83,27 +120,31 @@ _test-run-two:
83120 @echo " - Testing terraform-docs (2/2)"
84121 @echo " ------------------------------------------------------------"
85122 $(eval TFDOC_ARG_SORT = $(shell \
86- if [ " $( TAG) " = " latest " ] || [ " $( TAG) " = " 0.7.0 " ] || [ " $( TAG) " = " 0.6 .0" ] || [ " $( TAG) " = " 0.5.0 " ]; then \
123+ if [ " $( TAG) " ! = " 0.1.0 " ] && [ " $( TAG) " ! = " 0.1.1 " ] && [ " $( TAG ) " != " 0.2.0 " ] && [ " $( TAG) " ! = " 0.3 .0" ] && [ " $( TAG) " ! = " 0.4.0 " ] && [ " $( TAG ) " != " 0.4.5 " ]; then \
87124 echo " --sort-inputs-by-required" ; \
88125 fi ; \
89126 ))
90127 $(eval TFDOC_ARG_AGGREGATE = $(shell \
91- if [ " $( TAG) " = " latest " ] || [ " $( TAG ) " = " 0.7 .0" ] || [ " $( TAG) " = " 0.6.0 " ] || [ " $( TAG) " = " 0.5 .0" ] || [ " $( TAG) " = " 0.4.5 " ] || [ " $( TAG ) " = " 0.4 .0" ]; then \
128+ if [ " $( TAG) " ! = " 0.1 .0" ] && [ " $( TAG) " ! = " 0.1.1 " ] && [ " $( TAG) " ! = " 0.2 .0" ] && [ " $( TAG) " ! = " 0.3 .0" ]; then \
92129 echo " --with-aggregate-type-defaults" ; \
93130 fi ; \
94131 ))
95132 @# ---- Test Terraform < 0.12 ----
96- @if ! docker run --rm -v $(CURRENT_DIR ) /tests/default:/data $(IMAGE ) terraform-docs-replace $(TFDOC_ARG_SORT ) $(TFDOC_ARG_AGGREGATE ) md TEST-$(TAG ) .md; then \
133+ @if ! docker run --rm -v $(PWD ) /tests/default:/data $(IMAGE ) terraform-docs-replace $(TFDOC_ARG_SORT ) $(TFDOC_ARG_AGGREGATE ) md TEST-$(TAG ) .md; then \
97134 echo " Failed" ; \
98135 exit 1; \
99136 fi
100137 @# ---- Test Terraform >= 0.12 ----
101- @if ! docker run --rm -v $(CURRENT_DIR ) /tests/0.12:/data $(IMAGE ) terraform-docs-replace-012 $(TFDOC_ARG_SORT ) $(TFDOC_ARG_AGGREGATE ) md TEST-$(TAG ) .md; then \
138+ @if ! docker run --rm -v $(PWD ) /tests/0.12:/data $(IMAGE ) terraform-docs-replace-012 $(TFDOC_ARG_SORT ) $(TFDOC_ARG_AGGREGATE ) md TEST-$(TAG ) .md; then \
102139 echo " Failed" ; \
103140 exit 1; \
104141 fi ; \
105142 echo " Success" ;
106143
144+
145+ # --------------------------------------------------------------------------------------------------
146+ # HELPER TARGETS
147+ # --------------------------------------------------------------------------------------------------
107148tag :
108149 docker tag $(IMAGE ) $(IMAGE ) :$(TAG )
109150
0 commit comments