-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
61 lines (49 loc) · 2.36 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
CURL ?= curl --fail -sSL
XARGS ?= xargs -I {}
BIN_DIR ?= ${HOME}/bin
PATH := $(BIN_DIR):$(PATH)
VERSION ?= $$(grep -E '^current_version' .bumpversion.cfg | sed 's/^.*= //')
MAKEFLAGS += --no-print-directory
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.SUFFIXES:
.PHONY: %/lint %/format
.PHONY: deploy
guard/program/%:
@ which $* > /dev/null || $(MAKE) $*/install
deploy:
@echo "make: Deploying files to S3 bucket, using aws sync"
aws s3 sync --delete --exclude '.git/*' . s3://$(BUCKET)/$(PREFIX)
@echo "make: Applying version tag to bucket objects"
aws s3api list-objects --bucket $(BUCKET) --query "Contents[?starts_with(Key, \`$(PREFIX)\`)].{Key:Key}" --out text | $(XARGS) -n1 -P8 -t aws s3api put-object-tagging --bucket $(BUCKET) --tagging "TagSet=[{Key=Version,Value=$(VERSION)}]" --key {}
jq/install: JQ_VERSION ?= jq-1.5
jq/install: JQ_URL ?= https://github.com/stedolan/jq/releases/download/$(JQ_VERSION)/jq-linux64
jq/install: | $(BIN_DIR)
@ echo "[$@]: Installing $(@D)..."
@ echo "[$@]: JQ_URL=$(JQ_URL)"
$(CURL) -o $(BIN_DIR)/$(@D) "$(JQ_URL)"
chmod +x $(BIN_DIR)/$(@D)
$(@D) --version
@ echo "[$@]: Completed successfully!"
json/%: FIND_JSON := find . -name '*.json' -type f
json/lint: | guard/program/jq
@ echo "[$@]: Linting JSON files..."
$(FIND_JSON) | $(XARGS) bash -c 'cmp {} <(jq --indent 4 -S . {}) || (echo "[{}]: Failed JSON Lint Test"; exit 1)'
@ echo "[$@]: JSON files PASSED lint test!"
json/format: | guard/program/jq
@ echo "[$@]: Formatting JSON files..."
$(FIND_JSON) | $(XARGS) bash -c 'echo "$$(jq --indent 4 -S . "{}")" > "{}"'
@ echo "[$@]: Successfully formatted JSON files!"
sh/%: FIND_SH ?= find . -name '*.sh' -type f
sh/lint: | guard/program/shellcheck
$(FIND_SH) | $(XARGS) shellcheck {}
yaml/lint: | guard/program/yamllint
yamllint --strict .
cfn/%: FIND_CFN_JSON ?= find . -name '*.template.cfn.json' -type f
cfn/%: FIND_CFN_YAML ?= find . -name '*.template.cfn.yaml' -type f
cfn/lint: | guard/program/cfn-lint
$(FIND_CFN_JSON) | $(XARGS) cfn-lint -t {}
$(FIND_CFN_YAML) | $(XARGS) cfn-lint -t {}
cfn/version:
$(FIND_CFN_JSON) | $(XARGS) bash -c "jq -e '.Metadata.Version | test(\"^$(VERSION)$$\")' {} > /dev/null || (echo '[{}]: BAD/MISSING Cfn Version Metadata'; exit 1)"
$(FIND_CFN_YAML) | $(XARGS) bash -c "yq -e '.Metadata.Version | test(\"^$(VERSION)$$\")' {} > /dev/null || (echo '[{}]: BAD/MISSING Cfn Version Metadata'; exit 1)"