blob: 08886e36b6e0e05831d5723f7e291f6666f4028d [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)
Zack Williamsad45bf02020-03-04 21:37:20 -070015
16# YAML files, excluding venv and cookiecutter directories
Wei-Yu Chendda78172021-07-15 23:18:57 +080017YAML_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 -070018
19# all files with extensions
Zack Williamsdac2be42021-08-19 16:14:31 -070020PYTHON_FILES ?= $(wildcard scripts/*.py scripts/*/*.py filter_plugins/*.py lint_rules/*.py cookiecutters/*/hooks/*.py)
Zack Williamsad45bf02020-03-04 21:37:20 -070021
22.DEFAULT_GOAL := help
23.PHONY: test lint yamllint ansiblelint license help
24
25# Create the virtualenv with all the tools installed
26VENV_NAME = venv_onfansible
27
28$(VENV_NAME): requirements.txt
29 $(VIRTUALENV) $@ ;\
30 source ./$@/bin/activate ; set -u ;\
31 python -m pip install --upgrade pip;\
32 python -m pip install -r requirements.txt
33 echo "To enter virtualenv, run 'source $@/bin/activate'"
34
35galaxy: $(VENV_NAME) galaxy.yml ## Download ansible galaxy provided collection and roles
36 source ./$</bin/activate ; set -u ;\
37 ansible-galaxy collection install -r galaxy.yml
38
39license: $(VENV_NAME) ## Check license with the reuse tool
40 source ./$</bin/activate ; set -u ;\
41 reuse --version ;\
42 reuse --root . lint
43
44# Cookiecutter tests
Zack Williamsdac2be42021-08-19 16:14:31 -070045test: ansiblelint flake8 pylint black ## run all standard tests
Zack Williamsad45bf02020-03-04 21:37:20 -070046
47yamllint: $(VENV_NAME) ## lint YAML format using yamllint
48 source ./$</bin/activate ; set -u ;\
49 yamllint --version ;\
50 yamllint \
51 -d "{extends: default, rules: {line-length: {max: 99}}}" \
52 -s $(YAML_FILES)
53
54ansiblelint: $(VENV_NAME) ## lint ansible-specific format using ansible-lint
55 source ./$</bin/activate ; set -u ;\
56 ansible-lint --version ;\
Zack Williamsdac2be42021-08-19 16:14:31 -070057 ansible-lint -R -v $(ANSIBLE_PLAYBOOKS)
Zack Williamsad45bf02020-03-04 21:37:20 -070058
59flake8: $(VENV_NAME) ## check python formatting with flake8
60 source ./$</bin/activate ; set -u ;\
61 flake8 --version ;\
Zack Williamsdac2be42021-08-19 16:14:31 -070062 flake8 --max-line-length 99 --per-file-ignores="__init__.py:F401" $(PYTHON_FILES)
Zack Williamsad45bf02020-03-04 21:37:20 -070063
64pylint: $(VENV_NAME) ## pylint check for python 3 compliance
65 source ./$</bin/activate ; set -u ;\
66 pylint --version ;\
Zack Williamsdac2be42021-08-19 16:14:31 -070067 pylint --rcfile=pylint.ini $(PYTHON_FILES)
Zack Williamsad45bf02020-03-04 21:37:20 -070068
69black: $(VENV_NAME) ## run black on python files in check mode
70 source ./$</bin/activate ; set -u ;\
71 black --version ;\
72 black --check $(PYTHON_FILES)
73
74blacken: $(VENV_NAME) ## run black on python files to reformat
75 source ./$</bin/activate ; set -u ;\
76 black --version ;\
77 black $(PYTHON_FILES)
78
Zack Williamsad45bf02020-03-04 21:37:20 -070079clean:
80 rm -rf $(VENV_NAME) ansible_collections
81
82help: ## Print help for each target
83 @echo infra-playbooks make targets
84 @echo
85 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
86 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'