-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
151 lines (121 loc) · 3.67 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
148
149
150
151
###
### Variables
###
export ANSIBLE_FORCE_COLOR = 1
export PY_COLORS = 1
export PYTHONIOENCODING = UTF-8
export LC_CTYPE = en_US.UTF-8
export LANG = en_US.UTF-8
# https://serverfault.com/questions/1031491/display-ansible-playbook-output-properly-formatted
# https://stackoverflow.com/questions/50009505/ansible-stdout-formatting
export ANSIBLE_STDOUT_CALLBACK = unixy
TASK_TAGS ?= "brew-install,brew-analytics,brew-update,brew-taps,brew-packages,brew-casks"
PLAYBOOK ?= test.yml
WORKDIR ?= ./tests
INVENTORY ?= inventory.yml
REQS ?= requirements.yml
INSTALL_POETRY ?= true
POETRY_BIN ?= poetry
POETRY_RUNNER ?= poetry run
ANSIBLE_LATER_BIN = ansible-later
MACOS_NATIVE_PY_PATH ?= /usr/bin/python3
PY_PATH ?= $(shell which python3)
# leave empty to disable
# -v - verbose;
# -vv - more details
# -vvv - enable connection debugging
DEBUG_VERBOSITY ?= -vvv
TEST_PLAYBOOK = $(POETRY_RUNNER) ansible-playbook $(PLAYBOOK) -i $(INVENTORY) $(DEBUG_VERBOSITY) --ask-become
TEST_IDEMPOTENT = $(TEST_PLAYBOOK) | tee /dev/tty | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)
### Lint yaml files
lint: check-syntax
$(POETRY_RUNNER) yamllint .
$(POETRY_RUNNER) ansible-lint . --force-color
.PHONY: lint
### Run tests
test:
cd $(WORKDIR) && $(TEST_PLAYBOOK)
.PHONY: test
test-idempotent:
cd $(WORKDIR) && $(TEST_IDEMPOTENT)
.PHONY: test-idempotent
test-install: TASK_TAGS="brew-install"
test-install: test-tag
test-analytics: TASK_TAGS="brew-analytics"
test-analytics: test-tag
test-update: TASK_TAGS="brew-update"
test-update: test-tag
test-taps: TASK_TAGS="brew-taps"
test-taps: test-tag
test-packages: TASK_TAGS="brew-packages"
test-packages: test-tag
test-casks: TASK_TAGS="brew-casks"
test-casks: test-tag
test-tag:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --tags $(TASK_TAGS)
.PHONY: test-tag
m-local:
$(POETRY_RUNNER) molecule test --scenario-name default-macos-on-localhost -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-local
m-remote:
$(POETRY_RUNNER) molecule test --scenario-name default-macos-over-ssh -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-remote
m-linux:
$(POETRY_RUNNER) molecule test --scenario-name default -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-linux
login-mac:
$(POETRY_RUNNER) molecule login \
--host macos-12-vm \
--scenario-name default-macos-over-ssh
.PHONY: login-mac
login-deb:
$(POETRY_RUNNER) molecule login \
--host debian-based-instance \
--scenario-name default
.PHONY: login-deb
debug-version:
$(POETRY_RUNNER) ansible --version
.PHONY: debug-version
check:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --check
.PHONY: check
### List all hostnames
ls-host:
cd $(WORKDIR) && $(POETRY_RUNNER) ansible all -i $(INVENTORY) -m shell -a "hostname;"
.PHONY: ls-host
### Check playbook syntax
check-syntax:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --syntax-check
.PHONY: check-syntax
later:
$(POETRY_RUNNER) $(ANSIBLE_LATER_BIN) **/*.yml
.PHONY: later
### Install ansible dependencies
install: update-pip install-poetry install-deps
.PHONY: install
install-deps:
$(POETRY_BIN) install
$(POETRY_RUNNER) ansible-galaxy install -r $(REQS)
.PHONY: install-deps
install-poetry:
ifeq ($(INSTALL_POETRY),true)
sudo sh contrib/poetry-bin/install.sh
else
@echo "Poetry installation disabled by global variable! Exiting..."
@exit 0
endif
.PHONY: install-poetry
update-pip:
ifeq ($(PY_PATH),$(MACOS_NATIVE_PY_PATH))
@echo "Native macOS python binary detected at" $(MACOS_NATIVE_PY_PATH)
sudo pip3 install --upgrade pip
else
@echo "External python binary detected at" $(PY_PATH)
@exit 0
endif
.PHONY: update-pip
### Git
hooks:
$(POETRY_RUNNER) pre-commit install
$(POETRY_RUNNER) pre-commit autoupdate
.PHONY: hooks