-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
147 lines (117 loc) · 3.81 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
CLEAN_FILES := $(foreach file,GPATH GRTAGS GTAGS TAGS,test/fixture/gtags/$(file))
INSTALL_ARGS :=
SHELLCHECK_OPTS := -s bash -e SC1090
SHELLCHECK_DOCKER_IMAGE := koalaman/shellcheck:stable
RUBOCOP_CONFIG_FILE := .rubocop.yml
RUBOCOP_DOCKER_IMAGE := ruby:3-alpine
TEST_RUNNER := test/support/runner.sh
TEST_FILES := $(wildcard test/*-test.sh)
TEST_BASH_FILES := $(wildcard test/bash*-test.sh)
TEST_BASH_DOCKER_IMAGES := bash!5 bash!4.4
TEST_DEBIAN_FILES := test/gtags-test.sh test/yaml2json-test.sh
TEST_DEBIAN_DOCKER_IMAGE := debian!11
.PHONY: help
help: SHELL := bash
help:
@echo -e "$(subst $(newline),\n,$(help_text))"
.PHONY: install
install:
./install.sh $(INSTALL_ARGS)
.PHONY: clean
clean:
rm -f $(CLEAN_FILES)
.PHONY: lint
lint: lint-shellcheck lint-rubocop
.PHONY: lint-docker
lint-docker: lint-shellcheck-docker lint-rubocop-docker
.PHONY: lint-shellcheck
lint-shellcheck: SHELL := bash
lint-shellcheck:
shellcheck $$(< .shellcheck-files)
.PHONY: lint-shellcheck-docker
lint-shellcheck-docker: SHELL := bash
lint-shellcheck-docker:
docker run \
--rm \
-t \
-v "$(CURDIR):/dotfiles:ro" \
-w /dotfiles \
-e SHELLCHECK_OPTS="$(SHELLCHECK_OPTS)" \
$(SHELLCHECK_DOCKER_IMAGE) \
$$(< .shellcheck-files)
.PHONY: lint-rubocop
lint-rubocop: SHELL := bash
lint-rubocop:
rubocop --config $(CURDIR)/$(RUBOCOP_CONFIG_FILE) $$(< .rubocop-files)
.PHONY: lint-rubocop-docker
lint-rubocop-docker:
docker run \
--rm \
-t \
-v "$(CURDIR):/dotfiles:ro" \
-w /dotfiles \
$(RUBOCOP_DOCKER_IMAGE) \
sh -c "$(subst $(newline),; ,$(test_rubocop_docker_cmds))"
.PHONY: test
test:
$(TEST_RUNNER) $(TEST_FILES)
.PHONY: test-docker
test-docker: test-bash-docker test-debian-docker
.PHONY: test-bash-docker
test-bash-docker: $(TEST_BASH_DOCKER_IMAGES)
.PHONY: $(TEST_BASH_DOCKER_IMAGES)
$(TEST_BASH_DOCKER_IMAGES):
docker run \
--rm \
-t \
-v "$(CURDIR):/dotfiles:ro" \
-w /dotfiles \
-e SHELL=/usr/local/bin/bash \
$(subst !,:,$@) \
bash -c "$(subst $(newline),; ,$(test_bash_docker_cmds))"
.PHONY: test-debian-docker
test-debian-docker:
docker run \
--rm \
-t \
-v "$(CURDIR):/dotfiles:ro" \
-v "$(CURDIR)/test/fixture:/dotfiles/test/fixture" \
-w /dotfiles \
-e SHELL=/bin/bash \
$(subst !,:,$(TEST_DEBIAN_DOCKER_IMAGE)) \
bash -c "$(subst $(newline),; ,$(test_debian_docker_cmds))"
define newline
endef
define test_rubocop_docker_cmds
set -x
gem install rubocop
rubocop --config /dotfiles/$(RUBOCOP_CONFIG_FILE) $$(tr '\n' ' ' < .rubocop-files)
endef
define test_bash_docker_cmds
set -x
./install.sh -f $(INSTALL_ARGS)
$(TEST_RUNNER) $(TEST_BASH_FILES)
endef
define test_debian_docker_cmds
set -x
apt-get update
apt-get install --yes --no-install-recommends --quiet make universal-ctags python3-pygments global ruby
./install.sh -f $(INSTALL_ARGS)
bash --login -c '$(TEST_RUNNER) $(TEST_DEBIAN_FILES)'
endef
define help_text
Targets:
help Show this guide
clean Remove test artifacts
install Install dotfiles; for more options, see \`make install INSTALL_ARGS=-h\`
lint Run linters on source files
lint-docker Run linters on source files in a Docker container
lint-shellcheck Run ShellCheck on source files
lint-shellcheck-docker Run ShellCheck on source files in a Docker container
lint-rubocop Run RuboCop on source files
lint-rubocop-docker Run RuboCop on source files in a Docker container
test Run tests (requires install) (select: TEST_FILES=test/*-test.sh)
test-docker Run tests in Docker containers
test-bash-docker Run Bash specific tests in Docker containers
test-debian-docker Run tests requiring complex dependencies in a Docker container
endef