|
1 | | -ARCH ?= amd64 |
2 | | -OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:']) |
3 | | -CURL ?= curl --fail -sSL |
4 | | -XARGS ?= xargs -I {} |
5 | | -BIN_DIR ?= ${HOME}/bin |
6 | | -TMP ?= /tmp |
7 | | -FIND_EXCLUDES ?= -not \( -name .terraform -prune \) -not \( -name .terragrunt-cache -prune \) |
| 1 | +SHELL := /bin/bash |
8 | 2 |
|
9 | | -PATH := $(BIN_DIR):${PATH} |
10 | | - |
11 | | -MAKEFLAGS += --no-print-directory |
12 | | -SHELL := bash |
13 | | -.SHELLFLAGS := -eu -o pipefail -c |
14 | | - |
15 | | -.PHONY: guard/% %/install %/lint |
16 | | - |
17 | | -GITHUB_ACCESS_TOKEN ?= 4224d33b8569bec8473980bb1bdb982639426a92 |
18 | | -# Macro to return the download url for a github release |
19 | | -# For latest release, use version=latest |
20 | | -# To pin a release, use version=tags/<tag> |
21 | | -# $(call parse_github_download_url,owner,repo,version,asset select query) |
22 | | -parse_github_download_url = $(CURL) https://api.github.com/repos/$(1)/$(2)/releases/$(3)?access_token=$(GITHUB_ACCESS_TOKEN) | jq --raw-output '.assets[] | select($(4)) | .browser_download_url' |
23 | | - |
24 | | -# Macro to download a github binary release |
25 | | -# $(call download_github_release,file,owner,repo,version,asset select query) |
26 | | -download_github_release = $(CURL) -o $(1) $(shell $(call parse_github_download_url,$(2),$(3),$(4),$(5))) |
27 | | - |
28 | | -# Macro to download a hashicorp archive release |
29 | | -# $(call download_hashicorp_release,file,app,version) |
30 | | -download_hashicorp_release = $(CURL) -o $(1) https://releases.hashicorp.com/$(2)/$(3)/$(2)_$(3)_$(OS)_$(ARCH).zip |
31 | | - |
32 | | -guard/env/%: |
33 | | - @ _="$(or $($*),$(error Make/environment variable '$*' not present))" |
34 | | - |
35 | | -guard/program/%: |
36 | | - @ which $* > /dev/null || $(MAKE) $*/install |
37 | | - |
38 | | -$(BIN_DIR): |
39 | | - @ echo "[make]: Creating directory '$@'..." |
40 | | - mkdir -p $@ |
41 | | - |
42 | | -install/gh-release/%: guard/env/FILENAME guard/env/OWNER guard/env/REPO guard/env/VERSION guard/env/QUERY |
43 | | -install/gh-release/%: |
44 | | - @ echo "[$@]: Installing $*..." |
45 | | - $(call download_github_release,$(FILENAME),$(OWNER),$(REPO),$(VERSION),$(QUERY)) |
46 | | - chmod +x $(FILENAME) |
47 | | - $* --version |
48 | | - @ echo "[$@]: Completed successfully!" |
49 | | - |
50 | | -install/pip/%: PYTHON ?= python |
51 | | -install/pip/%: | guard/env/PYPI_PKG_NAME |
52 | | - @ echo "[$@]: Installing $*..." |
53 | | - $(PYTHON) -m pip install --user $(PYPI_PKG_NAME) |
54 | | - ln -sf ~/.local/bin/$* $(BIN_DIR)/$* |
55 | | - $* --version |
56 | | - @ echo "[$@]: Completed successfully!" |
57 | | - |
58 | | -black/install: |
59 | | - @ $(MAKE) install/pip/$(@D) PYPI_PKG_NAME=$(@D) |
60 | | - |
61 | | -zip/install: |
62 | | - @ echo "[$@]: Installing $(@D)..." |
63 | | - apt-get install zip -y |
64 | | - @ echo "[$@]: Completed successfully!" |
65 | | - |
66 | | -terraform/install: TERRAFORM_VERSION_LATEST := $(CURL) https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | sed 's/^v//' |
67 | | -terraform/install: TERRAFORM_VERSION ?= $(shell $(TERRAFORM_VERSION_LATEST)) |
68 | | -terraform/install: | $(BIN_DIR) guard/program/jq |
69 | | - @ echo "[$@]: Installing $(@D)..." |
70 | | - $(call download_hashicorp_release,$(@D).zip,$(@D),$(TERRAFORM_VERSION)) |
71 | | - unzip $(@D).zip && rm -f $(@D).zip && chmod +x $(@D) |
72 | | - mv $(@D) "$(BIN_DIR)" |
73 | | - $(@D) --version |
74 | | - @ echo "[$@]: Completed successfully!" |
75 | | - |
76 | | -#terraform-docs/install: TFDOCS_VERSION ?= latest |
77 | | -terraform-docs/install: TFDOCS_VERSION ?= tags/v0.7.0 |
78 | | -terraform-docs/install: | $(BIN_DIR) guard/program/jq |
79 | | - @ $(MAKE) install/gh-release/$(@D) FILENAME="$(BIN_DIR)/$(@D)" OWNER=segmentio REPO=$(@D) VERSION=$(TFDOCS_VERSION) QUERY='.name | endswith("$(OS)-$(ARCH)")' |
80 | | - |
81 | | -jq/install: JQ_VERSION ?= latest |
82 | | -jq/install: | $(BIN_DIR) |
83 | | - @ $(MAKE) install/gh-release/$(@D) FILENAME="$(BIN_DIR)/$(@D)" OWNER=stedolan REPO=$(@D) VERSION=$(JQ_VERSION) QUERY='.name | endswith("$(OS)64")' |
84 | | - |
85 | | -shellcheck/install: SHELLCHECK_VERSION ?= latest |
86 | | -shellcheck/install: SHELLCHECK_URL ?= https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz |
87 | | -shellcheck/install: $(BIN_DIR) guard/program/xz |
88 | | - $(CURL) $(SHELLCHECK_URL) | tar -xJv |
89 | | - mv $(@D)-*/$(@D) $(BIN_DIR) |
90 | | - rm -rf $(@D)-* |
91 | | - $(@D) --version |
92 | | - |
93 | | -terraform/lint: | guard/program/terraform |
94 | | - @ echo "[$@]: Linting Terraform files..." |
95 | | - terraform fmt -check=true -diff=true |
96 | | - @ echo "[$@]: Terraform files PASSED lint test!" |
97 | | - |
98 | | -terraform/format: | guard/program/terraform |
99 | | - @ echo "[$@]: Formatting Terraform files..." |
100 | | - terraform fmt -recursive |
101 | | - @ echo "[$@]: Successfully formatted terraform files!" |
102 | | - |
103 | | -sh/%: FIND_SH := find . $(FIND_EXCLUDES) -name '*.sh' -type f -print0 |
104 | | -sh/lint: | guard/program/shellcheck |
105 | | - @ echo "[$@]: Linting shell scripts..." |
106 | | - $(FIND_SH) | $(XARGS) shellcheck {} |
107 | | - @ echo "[$@]: Shell scripts PASSED lint test!" |
108 | | - |
109 | | -json/%: FIND_JSON := find . $(FIND_EXCLUDES) -name '*.json' -type f |
110 | | -json/lint: | guard/program/jq |
111 | | - @ echo "[$@]: Linting JSON files..." |
112 | | - $(FIND_JSON) | $(XARGS) bash -c 'cmp {} <(jq --indent 4 -S . {}) || (echo "[{}]: Failed JSON Lint Test"; exit 1)' |
113 | | - @ echo "[$@]: JSON files PASSED lint test!" |
114 | | - |
115 | | -json/format: | guard/program/jq |
116 | | - @ echo "[$@]: Formatting JSON files..." |
117 | | - $(FIND_JSON) | $(XARGS) bash -c 'echo "$$(jq --indent 4 -S . "{}")" > "{}"' |
118 | | - @ echo "[$@]: Successfully formatted JSON files!" |
119 | | - |
120 | | -tfdocs-awk/install: $(BIN_DIR) |
121 | | -tfdocs-awk/install: ARCHIVE := https://github.com/plus3it/tfdocs-awk/archive/0.0.2.tar.gz |
122 | | -tfdocs-awk/install: |
123 | | - $(CURL) $(ARCHIVE) | tar -C $(BIN_DIR) --strip-components=1 --wildcards '*.sh' --wildcards '*.awk' -xzvf - |
124 | | - |
125 | | -docs/generate: | tfdocs-awk/install guard/program/terraform-docs |
126 | | - @ echo "[$@]: Creating documentation files.." |
127 | | - @ bash -eu -o pipefail autodocs.sh -g |
128 | | - @ echo "[$@]: Documentation generated!" |
129 | | - |
130 | | -docs/lint: | tfdocs-awk/install guard/program/terraform-docs |
131 | | - @ echo "[$@] Linting documentation files.." |
132 | | - @ bash -eu -o pipefail autodocs.sh -l |
133 | | - @ echo "[$@] documentation linting complete!" |
134 | | - |
135 | | -python/lint: | guard/program/black |
136 | | - @ echo "[$@]: Linting Python files..." |
137 | | - black --check . |
138 | | - @ echo "[$@]: Python files PASSED lint test!" |
139 | | - |
140 | | -python/format: | guard/program/black |
141 | | - @ echo "[$@]: Formatting Python files..." |
142 | | - black . |
143 | | - @ echo "[$@]: Successfully formatted Python files!" |
144 | | - |
145 | | -terratest/install: | guard/program/go |
146 | | - cd tests && go mod init terraform-aws-codecommit-pr-reminders/tests |
147 | | - cd tests && go build ./... |
148 | | - cd tests && go mod tidy |
149 | | - |
150 | | -terratest/test: | guard/program/go |
151 | | - cd tests && go test -count=1 -timeout 20m |
152 | | - |
153 | | -test: terratest/test |
| 3 | +-include $(shell curl -sSL -o .tardigrade-ci "https://raw.githubusercontent.com/plus3it/tardigrade-ci/master/bootstrap/Makefile.bootstrap"; echo .tardigrade-ci) |
0 commit comments