1# Make sure we have ansible_collections/sensu/sensu_go as a prefix. This is
2# ugly as heck, but it works. I suggest all future developer to treat next few
3# lines as an opportunity to learn a thing or two about GNU make ;)
4collection := $(notdir $(realpath $(CURDIR)      ))
5namespace  := $(notdir $(realpath $(CURDIR)/..   ))
6toplevel   := $(notdir $(realpath $(CURDIR)/../..))
7
8err_msg := Place collection at <WHATEVER>/ansible_collections/sensu/sensu_go
9ifeq (true,$(CI))
10  $(info Running in CI setting, skipping directory checks.)
11else ifneq (sensu_go,$(collection))
12  $(error $(err_msg))
13else ifneq (sensu,$(namespace))
14  $(error $(err_msg))
15else ifneq (ansible_collections,$(toplevel))
16  $(error $(err_msg))
17endif
18
19python_version := $(shell \
20  python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))' \
21)
22
23molecule_scenarios := $(wildcard tests/integration/molecule/*)
24
25
26.PHONY: help
27help:
28	@echo Available targets:
29	@fgrep "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sort
30
31.PHONY: sanity
32sanity:  ## Run sanity tests
33	pip install -r sanity.requirements -r collection.requirements
34	flake8
35	if which ansible-lint 2> /dev/null; then ansible-lint -p roles/*; fi
36	ansible-test sanity --docker
37	./tests/sanity/validate-role-metadata.py roles/*
38
39.PHONY: units
40units:  ## Run unit tests
41	pip install -r collection.requirements
42	-ansible-test coverage erase # On first run, there is nothing to erase.
43	ansible-test units --docker --coverage
44	ansible-test coverage html --requirements
45	ansible-test coverage report --omit 'tests/*' --show-missing
46
47.PHONY: integration
48integration:  ## Run integration tests
49	pip install -r integration.requirements -r collection.requirements
50	pytest -s --molecule-base-config=base.yml tests/integration/molecule
51
52.PHONY: $(molecule_scenarios)
53$(molecule_scenarios):
54	pytest -s --molecule-base-config=base.yml $@
55
56.PHONY: integration_ci
57integration_ci:  ## Run integration tests on CircleCI
58	pip install -r integration.requirements -r collection.requirements
59	mkdir -p test_results/integration
60	pytest -s \
61	  --junitxml=test_results/integration/junit.xml \
62	  --molecule-base-config=base.yml \
63	  $$(circleci tests glob "tests/integration/molecule/*/molecule.yml" \
64	     | circleci tests split --split-by=timings)
65
66.PHONY: docs
67docs:  ## Build collection documentation
68	$(MAKE) -C docs -f Makefile.custom docs
69
70.PHONY: clean
71clean:  ## Remove all auto-generated files
72	$(MAKE) -C docs -f Makefile.custom clean
73	rm -rf tests/output test_results
74
75.PHONY: check_windows_versions
76check_windows_versions:  ## Check if our and upstream versions drifed apart
77	tools/windows-versions.py check roles/install/vars/Windows.yml
78
79.PHONY: update_windows_versions
80update_windows_versions:  ## Update Windows versions in variable file
81	tools/windows-versions.py update roles/install/vars/Windows.yml
82