blob: 504d6b38ebb4143d8435dfe03c88aa8df6bcb8be [file] [log] [blame]
Zack Williams712caf62020-04-28 13:37:41 -07001# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
2# SPDX-License-Identifier: Apache-2.0
3
4SHELL = bash -e -o pipefail
5
6# Common set of args, set to --debug for more output
7COMMON_ARGS ?= --debug
8
9# tooling binaries
Zack Williams483de862021-02-12 15:07:33 -070010VIRTUALENV ?= python3 -m venv
Zack Williams712caf62020-04-28 13:37:41 -070011PYTHON ?= python3
12# change to be 'python3 -m cProfile -s cumtime' to profile a script
13
14.DEFAULT_GOAL := help
15.PHONY: test lint yamllint license help build siterender buildcollector sync
16
17# Create the virtualenv with all the tools installed
Zack Williams483de862021-02-12 15:07:33 -070018VENV_NAME = venv-sjsg
Zack Williams712caf62020-04-28 13:37:41 -070019
20$(VENV_NAME): requirements.txt
21 $(VIRTUALENV) $@ ;\
22 source ./$@/bin/activate ; set -u ;\
23 $(PYTHON) -m pip install -r requirements.txt yamllint
24 echo "To enter virtualenv, run 'source $@/bin/activate'"
25
26# build targets
Zack Williamscb2746d2020-12-16 10:27:24 -070027products:
28 mkdir products
29
30site:
31 mkdir site
32
Zack Williams712caf62020-04-28 13:37:41 -070033build: buildcollector siterender ## Collect build info and create website
34
Zack Williamscb2746d2020-12-16 10:27:24 -070035buildcollector: $(VENV_NAME) products ## Collect build information from Jenkins jobs
Zack Williams712caf62020-04-28 13:37:41 -070036 source ./$</bin/activate ; set -u ;\
37 $(PYTHON) buildcollector.py scrape.yaml --credentials credentials.yaml $(COMMON_ARGS)
38
Zack Williamscb2746d2020-12-16 10:27:24 -070039siterender: $(VENV_NAME) site ## Create static website from build information
Zack Williams712caf62020-04-28 13:37:41 -070040 source ./$</bin/activate ; set -u ;\
41 $(PYTHON) siterender.py $(COMMON_ARGS)
42 cp -r static/* site/
43
44serve:
45 cd site && $(PYTHON) -m http.server
46
47sync:
48 rsync --delete-after -avP site/ ubuntu@static.opennetworking.org:/srv/sites/certification.opennetworking.org/
49
50# testing targets
51test: yamllint tox ## run all tests
52
53# YAML files, excluding venv and cookiecutter directories
Zack Williams483de862021-02-12 15:07:33 -070054YAML_FILES ?= $(shell find . -type d \( -path "./venv-sjsg" \) -prune -o -type f \( -name '*.yaml' -o -name '*.yml' \) -print )
Zack Williams712caf62020-04-28 13:37:41 -070055
56yamllint: $(VENV_NAME) ## lint YAML format using yamllint
57 source ./$</bin/activate ; set -u ;\
58 yamllint --version ;\
59 yamllint \
60 -d "{extends: default, rules: {line-length: {max: 139}}}" \
61 -s $(YAML_FILES)
62
Zack Williams483de862021-02-12 15:07:33 -070063tox: $(VENV_NAME) ## test code with tox
64 source ./$</bin/activate ; set -u ;\
65 tox
Zack Williams712caf62020-04-28 13:37:41 -070066
67license: ## Check code for licensing with REUSE
68 reuse --root . lint
69
70clean: ## Delete all temporary files
Zack Williams483de862021-02-12 15:07:33 -070071 rm -rf products site *.xml *.egg-info
Zack Williams712caf62020-04-28 13:37:41 -070072
73clean-all: clean ## Delete virtualenv and all cached job information
Zack Williamscb2746d2020-12-16 10:27:24 -070074 rm -rf $(VENV_NAME) jobs .tox
Zack Williams712caf62020-04-28 13:37:41 -070075
76help: ## Print help for each target
Zack Williamscb2746d2020-12-16 10:27:24 -070077 @echo sjsg test targets
Zack Williams712caf62020-04-28 13:37:41 -070078 @echo
79 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
80 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'