-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
96 lines (81 loc) · 2.7 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
SHELL=/bin/bash
-include .env
STATIC_ANALYSIS_CHECKER := $(shell which shellcheck 2> /dev/null)
LINTER_CHECKER := $(shell which ec 2> /dev/null)
GIT_DIR = $(shell git rev-parse --git-dir 2> /dev/null)
OS:=
ifeq ($(OS),Windows_NT)
OS +=WIN32
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
OS +=_AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
OS +=_IA32
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS+=LINUX
endif
ifeq ($(UNAME_S),Darwin)
OS+=OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
OS +=_AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
OS+=_IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
OS+=_ARM
endif
endif
help:
@echo ""
@echo "Usage: make [command]"
@echo ""
@echo "Commands:"
@echo " test Run the tests"
@echo " test/list List all tests under the tests directory"
@echo " test/watch Automatically run tests every second"
@echo " docker/alpine Run into a Docker Linux/Alpine:latest image"
@echo " pre_commit/install Install the pre-commit hook"
@echo " pre_commit/run Function that will be called when the pre-commit hook runs"
@echo " sa Run shellcheck static analysis tool"
@echo " lint Run editorconfig linter tool"
SRC_SCRIPTS_DIR=src
TEST_SCRIPTS_DIR=tests
EXAMPLE_TEST_SCRIPTS=./example/logic_test.sh
PRE_COMMIT_SCRIPTS_FILE=./bin/pre-commit
TEST_SCRIPTS = $(wildcard $(TEST_SCRIPTS_DIR)/*/*[tT]est.sh)
test/list:
@echo "Test scripts found:"
@echo $(TEST_SCRIPTS) | tr ' ' '\n'
test: $(TEST_SCRIPTS)
@./bashunit $(TEST_SCRIPTS)
test/watch: $(TEST_SCRIPTS)
@./bashunit $(TEST_SCRIPTS)
@fswatch -m poll_monitor -or $(SRC_SCRIPTS_DIR) $(TEST_SCRIPTS_DIR) .env Makefile | xargs -n1 ./bashunit $(TEST_SCRIPTS)
docker/alpine:
@docker run --rm -it -v "$(shell pwd)":/project -w /project alpine:latest \
sh -c "apk add bash make shellcheck git && bash"
docker/ubuntu:
@docker run --rm -it -v "$(shell pwd)":/project -w /project ubuntu:latest \
sh -c "apt update && apt install -y bash make shellcheck git && bash"
pre_commit/install:
@echo "Installing pre-commit hook"
cp $(PRE_COMMIT_SCRIPTS_FILE) $(GIT_DIR)/hooks/
pre_commit/run: test sa lint
sa:
ifndef STATIC_ANALYSIS_CHECKER
@printf "\e[1m\e[31m%s\e[0m\n" "Shellcheck not installed: Static analysis not performed!" && exit 1
else
@find . -name "*.sh" -not -path "./local/*" | xargs shellcheck -xC && printf "\e[1m\e[32m%s\e[0m\n" "ShellCheck: OK!"
endif
lint:
ifndef LINTER_CHECKER
@printf "\e[1m\e[31m%s\e[0m\n" "Editorconfig not installed: Lint not performed!" && exit 1
else
@ec -config .editorconfig && printf "\e[1m\e[32m%s\e[0m\n" "editorconfig-check: OK!"
endif