-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
171 lines (137 loc) · 9.13 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
PYTHON_COMMAND ?= python
NAMESPACE := $(shell $(PYTHON_COMMAND) -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["namespace"])')
NAME := $(shell $(PYTHON_COMMAND) -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["name"])')
VERSION := $(shell $(PYTHON_COMMAND) -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/*)))
RUNTIME_YML := meta/runtime.yml
METADATA := galaxy.yml LICENSE README.md $(RUNTIME_YML) requirements.txt changelogs/changelog.yaml CHANGELOG.rst bindep.txt PSF-license.txt meta/execution-environment.yml
TESTDATA := .ansible-lint Makefile pytest.ini $(shell find tests/ ! -type d ! -path '*/__pycache__/*' ! -path '*/test_playbooks/fixtures/*' ! -path '*/fixtures/apidoc/*')
$(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(eval _$(PLUGIN_TYPE) := $(filter-out %__init__.py,$(wildcard plugins/$(PLUGIN_TYPE)/*.py)) $(wildcard plugins/$(PLUGIN_TYPE)/*.yml)))
DEPENDENCIES := $(METADATA) $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(_$(PLUGIN_TYPE))) $(foreach ROLE,$(ROLES),$(wildcard $(ROLE)/*/*)) $(foreach ROLE,$(ROLES),$(ROLE)/README.md) $(TESTDATA)
PYTHON_VERSION = $(shell $(PYTHON_COMMAND) -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')
COLLECTION_COMMAND ?= ansible-galaxy
SANITY_OPTS = --venv
TEST =
FLAGS =
PYTEST_COMMAND ?= pytest
PYTEST = $(PYTEST_COMMAND) -n 4 --forked
# PYTEST_ADDOPTS is exported to sub-shells and picked up by *all* pytest invocations
PYTEST_ADDOPTS ?= -vv
export PYTEST_ADDOPTS
APIPIE_VERSION ?= v0.5.0
default: help
help:
@echo "Please use \`make <target>' where <target> is one of:"
@echo " help to show this message"
@echo " info to show infos about the collection"
@echo " lint to run code linting"
@echo " test to run unit tests"
@echo " livetest to run test playbooks live (without vcr)"
@echo " sanity to run santy tests"
@echo " setup to set up test, lint"
@echo " test-setup to install test dependencies"
@echo " test_<test> to run a specific unittest"
@echo " livetest_<test> to run a specific unittest live (without vcr)"
@echo " record_<test> to (re-)record the server answers for a specific test"
@echo " clean_<test> to run a specific test playbook with the teardown and cleanup tags"
@echo " dist to build the collection artifact"
info:
@echo "Building collection $(NAMESPACE)-$(NAME)-$(VERSION)"
@echo -e " roles:\n $(foreach ROLE,$(notdir $(ROLES)), - $(ROLE)\n)"
@echo -e " $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES), $(PLUGIN_TYPE):\n $(foreach PLUGIN,$(basename $(notdir $(_$(PLUGIN_TYPE)))), - $(PLUGIN)\n)\n)"
lint: $(MANIFEST) $(RUNTIME_YML) | tests/test_playbooks/vars/server.yml
yamllint -f parsable tests/test_playbooks roles
ansible-lint -v --offline
ansible-playbook --syntax-check tests/test_playbooks/*.yml | grep -v '^$$'
flake8 --ignore=E402,W503 --max-line-length=160 plugins/ tests/
@echo "Check that there are no changes to $(RUNTIME_YML)"
git diff --exit-code $(RUNTIME_YML)
galaxy-importer: $(MANIFEST)
GALAXY_IMPORTER_CONFIG=tests/galaxy-importer.cfg python -m galaxy_importer.main $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
sanity: $(MANIFEST)
# Fake a fresh git repo for ansible-test
cd $(<D) ; git init ; echo tests > .gitignore ; ansible-test sanity $(SANITY_OPTS) --python $(PYTHON_VERSION)
test: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) $(TEST)
test-crud: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) 'tests/test_crud.py::test_crud' 'tests/test_crud.py::test_inventory'
test-check-mode: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) 'tests/test_crud.py::test_check_mode'
test-other:
$(PYTEST) -k 'not test_crud.py'
livetest: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST_COMMAND) 'tests/test_crud.py::test_crud' --vcrmode live $(FLAGS)
test_%: FORCE $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST_COMMAND) 'tests/test_crud.py::test_crud[$*]' 'tests/test_crud.py::test_check_mode[$*]' $(FLAGS)
livetest_%: FORCE $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST_COMMAND) 'tests/test_crud.py::test_crud[$*]' --vcrmode live $(FLAGS)
record_%: FORCE $(MANIFEST)
$(RM) tests/test_playbooks/fixtures/$*-*.yml
$(PYTEST_COMMAND) 'tests/test_crud.py::test_crud[$*]' --vcrmode record $(FLAGS)
clean_%: FORCE $(MANIFEST)
ansible-playbook --tags teardown,cleanup -i tests/inventory/hosts 'tests/test_playbooks/$*.yml'
setup: test-setup
test-setup: | tests/test_playbooks/vars/server.yml
pip install --upgrade pip
pip install --upgrade -r requirements-dev.txt
tests/test_playbooks/vars/server.yml:
cp [email protected] $@
@echo "For recording, please adjust $@ to match your reference server."
dist-test: $(MANIFEST)
SATELLITE_SERVER_URL=https://foreman.example.test ansible -m $(NAMESPACE).$(NAME).organization -a "username=admin password=changeme name=collectiontest" localhost | grep -q "Failed to connect to Foreman server.*foreman.example.test"
SATELLITE_SERVER_URL=https://foreman.example.test ansible -m $(NAMESPACE).$(NAME).foreman_organization -a "username=admin password=changeme name=collectiontest" localhost | grep -q "Failed to connect to Foreman server.*foreman.example.test"
SATELLITE_SERVER_URL=http://foreman.example.test ansible -m $(NAMESPACE).$(NAME).organization -a "username=admin password=changeme name=collectiontest" localhost 2>&1| grep -q "You have configured a plain HTTP server URL."
ansible-doc $(NAMESPACE).$(NAME).organization | grep -q "Manage Organization"
$(MANIFEST): $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ansible-galaxy collection install -p build/collections $< --force
build/src/%: %
install -m 644 -DT $< $@
build/src/tests/test_%.py: FORCE
install -m 644 -DT tests/test_$*.py $@
$(NAMESPACE)-$(NAME)-$(VERSION).tar.gz: $(addprefix build/src/,$(DEPENDENCIES))
ansible-galaxy collection build build/src --force
dist: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
publish: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ansible-galaxy collection publish --api-key $(GALAXY_API_KEY) $<
clean:
rm -rf build docs/plugins
doc-setup:
pip install --upgrade -r docs/requirements.txt
doc: $(MANIFEST)
mkdir -p ./docs/plugins ./docs/roles
cat ./docs/roles.rst.template > ./docs/roles/index.rst
for role_readme in roles/*/README.md; do \
ln -f -s ../../$$role_readme ./docs/roles/$$(basename $$(dirname $$role_readme)).md; \
echo " * :doc:\`$$(basename $$(dirname $$role_readme))\`" >> ./docs/roles/index.rst; \
done
antsibull-docs collection --use-current --squash-hierarchy --dest-dir ./docs/plugins $(NAMESPACE).$(NAME)
make -C docs html
vendor:
git clone --depth=1 --branch=$(APIPIE_VERSION) https://github.com/Apipie/apypie/ build/apypie-git
python vendor.py build/apypie-git/apypie/*.py > plugins/module_utils/_apypie.py
$(RUNTIME_YML): FORCE
$(PYTHON_COMMAND) generate_action_groups.py
branding:
sed -i 's/theforeman\.foreman/redhat.satellite/g' plugins/*/*.py tests/inventory/*.foreman.yml tests/test_callback.py tests/test_module_state.py tests/test_playbooks/*.yml changelogs/config.yaml changelogs/changelog.yaml CHANGELOG.rst roles/*/README.md roles/*/*/*.yml docs/cvmanager.md tests/test_playbooks/fixtures/*.yml $(RUNTIME_YML) .ansible-lint .packit.yaml
sed -i 's/foreman.example.com/satellite.example.com/g' plugins/*/*.py docs/cvmanager.md roles/*/README.md roles/*/*/*.yml
sed -i 's#theforeman/foreman-ansible-modules#RedHatSatellite/satellite-ansible-collection#g' .github/workflows/*.yml
sed -i 's/theforeman-foreman/redhat-satellite/g' .github/workflows/*.yml .packit.yaml
sed -i 's/Foreman Ansible Modules/Red Hat Satellite Ansible Collection/g' docs/index.rst docs/conf.py docs/cvmanager.md docs/_gh_include/*.inc
sed -i 's/The Foreman Project/Red Hat, Inc./g' docs/conf.py
sed -i '/FOREMAN_\w/ s/FOREMAN_/SATELLITE_/g' plugins/doc_fragments/foreman.py plugins/module_utils/foreman_helper.py Makefile
sed -i '/foreman_\w/ s/foreman_/satellite_/g' roles/*/README.md roles/*/*/*.yml
sed -i 's#theforeman.github.io/foreman-ansible-modules#redhatsatellite.github.io/satellite-ansible-collection#g' roles/*/README.md
sed -i '/foreman_\w.*:/ s/foreman_/satellite_/g' tests/test_playbooks/*_role.yml tests/test_playbooks/convert2rhel.yml docs/cvmanager.md
sed -i 's/foreman:/satellite:/' $(RUNTIME_YML)
sed -i 's/foreman/satellite/' generate_action_groups.py .ansible-lint
sed -i '/group/ s/foreman/satellite/' tests/test_playbooks/module_defaults.yml
sed -i 's#packages/plugins#packages/satellite#' .packit.yaml
rm -rf tests/test_playbooks/scc_* tests/test_playbooks/tasks/scc_* tests/test_playbooks/fixtures/scc_* plugins/modules/scc_*.py tests/fixtures/apidoc/scc_*.json
rm -rf tests/test_playbooks/snapshot* tests/test_playbooks/tasks/snapshot* tests/test_playbooks/fixtures/snapshot* plugins/modules/snapshot*.py tests/fixtures/apidoc/snapshot*.json
rm -rf tests/test_playbooks/*_deb.yml
rm -rf tests/test_playbooks/*_ostree.yml
make $(RUNTIME_YML)
FORCE:
.PHONY: help dist lint sanity test test-crud test-check-mode test-other livetest setup test-setup doc-setup doc publish FORCE