-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
100 lines (75 loc) · 2.25 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
SHELL := /bin/bash
BUILD_FLAGS ?= -rp
BUILD_LIST ?=
DOCKER_BUILDKIT ?= 1
# ---
# Read default configuration
include config.default
export $(shell sed 's/=.*//' config.default)
# Read custom configuration if exist
ifneq ($(strip $(CONFIG)),)
include $(CONFIG)
export $(shell sed 's/=.*//' config.custom)
endif
# Pass TEST_FOLDERS env variable to limit which tests to run
TEST_FOLDERS ?=
# Check necessary commands exist
DOCKER := $(shell command -v docker 2> /dev/null)
SHELLCHECK := $(shell command -v shellcheck 2> /dev/null)
SHFMT := $(shell command -v shfmt 2> /dev/null)
YAMLLINT := $(shell command -v yamllint 2> /dev/null)
.DEFAULT_GOAL := all
all : build test
.PHONY : all
################################################################################
.PHONY: init
init: .git/hooks/pre-commit
.git/hooks/%:
@chmod 755 .githooks/*
@find .git/hooks -type l -exec rm {} \;
@find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
################################################################################
format: format-sh
format-sh:
ifndef SHFMT
$(error "shfmt is not installed: https://github.com/mvdan/sh")
endif
@shfmt -i 2 -ci -w .
.PHONY : lint
lint: init
@$(MAKE) -sj lint-docker lint-sh lint-yaml
lint-docker:
ifndef DOCKER
$(error "docker is not installed: https://docs.docker.com/install/")
endif
@find . -type f -name 'Dockerfile' -exec sh -c "cat {} | docker run --rm -i hadolint/hadolint" \;
lint-sh:
ifndef SHELLCHECK
$(error "shellcheck is not installed: https://github.com/koalaman/shellcheck")
endif
ifndef SHFMT
$(error "shfmt is not installed: https://github.com/mvdan/sh")
endif
#@shfmt -f . | xargs shellcheck
@shfmt -i 2 -ci -d .
lint-yaml:
ifndef YAMLLINT
$(error "yamllint is not installed: https://github.com/adrienverge/yamllint")
endif
@find . -type f -name '*.yml' | xargs yamllint
@find . -type f -name '*.yaml' | xargs yamllint
################################################################################
.PHONY : clean
clean :
bin/clean.sh
.PHONY : pull
pull :
pushd bin >/dev/null; ./build.sh -p; popd > /dev/null
.PHONY : build
build : lint
time bin/build.sh $(CONFIG) $(BUILD_FLAGS) $(BUILD_LIST)
.PHONY : test
test :
TEST_FOLDERS=$(TEST_FOLDERS) time tests/test.sh $(CONFIG)
deploy:
./bin/deploy.sh