blob: 8593cc2d35bf79f4c45f29c55c4ace9c7753da33 [file] [log] [blame]
Zack Williamsad45bf02020-03-04 21:37:20 -07001# ONF Ansbile Makefile
2#
3# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
4# SPDX-License-Identifier: Apache-2.0
5
6# Use bash for pushd/popd, and to fail quickly.
7# No -u as virtualenv activate script has undefined vars
8SHELL = bash -e -o pipefail
9
10# tooling
Zack Williamsdea8b772020-12-17 08:22:49 -070011VIRTUALENV ?= python3 -m venv
Zack Williamsad45bf02020-03-04 21:37:20 -070012
13# ansible files is all top-level playbooks
14ANSIBLE_PLAYBOOKS ?= $(wildcard *.yml)
15ANSIBLE_ROLES ?= $(wildcard roles/*)
16
17# YAML files, excluding venv and cookiecutter directories
Wei-Yu Chendda78172021-07-15 23:18:57 +080018YAML_FILES ?= $(shell find . -type d \( -path "./venv_onfansible" -o -path "./cookiecutters" -o -path "./ansible_collections" -o -path "./roles" -o -path "./inventory/host_vars" \) -prune -o -type f \( -name '*.yaml' -o -name '*.yml' \) -print )
Zack Williamsad45bf02020-03-04 21:37:20 -070019
20# all files with extensions
Zack Williams2aeb3ef2021-06-11 17:10:36 -070021PYTHON_FILES ?= $(wildcard scripts/*.py filter_plugins/*.py lint_rules/*.py cookiecutters/*/hooks/*.py roles/*/filter_plugins/*.py)
Zack Williamsad45bf02020-03-04 21:37:20 -070022
23.DEFAULT_GOAL := help
24.PHONY: test lint yamllint ansiblelint license help
25
26# Create the virtualenv with all the tools installed
27VENV_NAME = venv_onfansible
28
29$(VENV_NAME): requirements.txt
30 $(VIRTUALENV) $@ ;\
31 source ./$@/bin/activate ; set -u ;\
32 python -m pip install --upgrade pip;\
33 python -m pip install -r requirements.txt
34 echo "To enter virtualenv, run 'source $@/bin/activate'"
35
36galaxy: $(VENV_NAME) galaxy.yml ## Download ansible galaxy provided collection and roles
37 source ./$</bin/activate ; set -u ;\
38 ansible-galaxy collection install -r galaxy.yml
39
40license: $(VENV_NAME) ## Check license with the reuse tool
41 source ./$</bin/activate ; set -u ;\
42 reuse --version ;\
43 reuse --root . lint
44
45# Cookiecutter tests
46test: yamllint ansiblelint flake8 pylint black ## run all standard tests
47
48yamllint: $(VENV_NAME) ## lint YAML format using yamllint
49 source ./$</bin/activate ; set -u ;\
50 yamllint --version ;\
51 yamllint \
52 -d "{extends: default, rules: {line-length: {max: 99}}}" \
53 -s $(YAML_FILES)
54
55ansiblelint: $(VENV_NAME) ## lint ansible-specific format using ansible-lint
56 source ./$</bin/activate ; set -u ;\
57 ansible-lint --version ;\
58 ansible-lint -R -v $(ANSIBLE_PLAYBOOKS) $(ANSIBLE_ROLES)
59
60flake8: $(VENV_NAME) ## check python formatting with flake8
61 source ./$</bin/activate ; set -u ;\
62 flake8 --version ;\
63 flake8 --max-line-length 99 $(PYTHON_FILES)
64
65pylint: $(VENV_NAME) ## pylint check for python 3 compliance
66 source ./$</bin/activate ; set -u ;\
67 pylint --version ;\
68 pylint --py3k $(PYTHON_FILES)
69
70black: $(VENV_NAME) ## run black on python files in check mode
71 source ./$</bin/activate ; set -u ;\
72 black --version ;\
73 black --check $(PYTHON_FILES)
74
75blacken: $(VENV_NAME) ## run black on python files to reformat
76 source ./$</bin/activate ; set -u ;\
77 black --version ;\
78 black $(PYTHON_FILES)
79
Zack Williamsad45bf02020-03-04 21:37:20 -070080clean:
81 rm -rf $(VENV_NAME) ansible_collections
82
83help: ## Print help for each target
84 @echo infra-playbooks make targets
85 @echo
86 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
87 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'