-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
101 lines (76 loc) · 3.58 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
YAML_INSTALLED:=$(shell pip install pyyaml)
NAMESPACE := $(shell python -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["namespace"])')
NAME := $(shell python -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["name"])')
VERSION := $(shell python -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')
MANIFEST := build/collections/ansible_collections/$(NAMESPACE)/$(NAME)/MANIFEST.json
Roles := $(wildcard roles/*)
PLUGIN_TYPES := $(filter-out __%,$(notdir $(wildcard plugins/*)))
METADATA := galaxy.yml LICENSE README.md requirements.txt meta/runtime.yml
$(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(eval _$(PLUGIN_TYPE) := $(filter-out %__init__.py,$(wildcard plugins/$(PLUGIN_TYPE)/*.py))))
DEPENDENCIES := $(METADATA) $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(_$(PLUGIN_TYPE))) $(foreach ROLE,$(ROLES),$(wildcard $(ROLE)/*/*))
PYTHON_VERSION = $(shell python -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')
COLLECTION_COMMAND ?= ansible-galaxy
SANITY_OPTS = --venv
TEST =
PYTEST = pytest -n 4 --boxed -v
SHELL = bash
.ONESHELL:
default: help
help:
@echo "Please use \`make <target>' where <target> is one of:"
@echo " help - to show this message"
@echo " info - to show infomation about the collection"
@echo " lint - to run code linting"
@echo " dist - to build the collection archive"
info:
@echo "Building collection $(NAMESPACE)-$(NAME)-$(VERSION)"
@echo " roles:\n $(foreach ROLE,$(notdir $(ROLES)), - $(ROLE)\n)"
@echo " $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES), $(PLUGIN_TYPE):\n $(foreach PLUGIN,$(basename $(notdir $(_$(PLUGIN_TYPE)))), - $(PLUGIN)\n)\n)"
lint: $(MANIFEST)
flake8 plugins/ tests/
$(MANIFEST): $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ansible-galaxy collection install -p build/collections $< --force
build/src/%: %
install -m 644 -DT $< $@
$(NAMESPACE)-$(NAME)-$(VERSION).tar.gz: $(addprefix build/src/,$(DEPENDENCIES))
ansible-galaxy collection build build/src --force
dist: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
install: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ansible-galaxy collection install $< --force
release-%:
bumpversion $*
antsibull-changelog release
make doc
publish: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ansible-galaxy collection publish --api-key $(GALAXY_API_KEY) $<
clean:
rm -rf build
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -rf {} +
find . -name '*.tar.gz' -delete
docker-compose -f tests/docker/docker-compose.yml stop
docker-compose -f tests/docker/docker-compose.yml rm --force
doc-setup:
pip install -r docs/requirements.txt
doc: $(MANIFEST)
install -d -m 750 ./docs/plugins
antsibull-docs collection --use-current --squash-hierarchy --dest-dir ./docs/plugins codeaffen.phpipam
make -C docs html
test-setup: | tests/test_playbooks/vars/server.yml install-deps install
test -f tests/test_playbooks/vars/server.yml
test-all:
coverage run -m pytest -n 4 --forked -vv 'tests/test_crud.py::test_crud'
test-%:
coverage run -m pytest --forked -vv 'tests/test_crud.py::test_case_crud' --testcase $*
tests/test_playbooks/vars/server.yml:
sed -e "s#~~url~~#$(PHPIPAM_URL)#" -e "s#~~app_id~~#$(PHPIPAM_APPID)#" -e "s#~~username~~#$(PHPIPAM_USERNAME)#" -e "s#~~password~~#$(PHPIPAM_PASSWORD)#" [email protected] > $@
install-deps:
pip install -r requirements-dev.txt
setup-phpipam: test-setup
docker-compose -f tests/docker/docker-compose.yml up -d
sleep 30
sh tests/docker/setup_database.sh
FORCE:
.PHONY: help dist lint doc-setup doc publish test-setup test-all test-% install-deps FORCE