blob: 504d6b38ebb4143d8435dfe03c88aa8df6bcb8be [file] [log] [blame]
# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
# SPDX-License-Identifier: Apache-2.0
SHELL = bash -e -o pipefail
# Common set of args, set to --debug for more output
COMMON_ARGS ?= --debug
# tooling binaries
VIRTUALENV ?= python3 -m venv
PYTHON ?= python3
# change to be 'python3 -m cProfile -s cumtime' to profile a script
.DEFAULT_GOAL := help
.PHONY: test lint yamllint license help build siterender buildcollector sync
# Create the virtualenv with all the tools installed
VENV_NAME = venv-sjsg
$(VENV_NAME): requirements.txt
$(VIRTUALENV) $@ ;\
source ./$@/bin/activate ; set -u ;\
$(PYTHON) -m pip install -r requirements.txt yamllint
echo "To enter virtualenv, run 'source $@/bin/activate'"
# build targets
products:
mkdir products
site:
mkdir site
build: buildcollector siterender ## Collect build info and create website
buildcollector: $(VENV_NAME) products ## Collect build information from Jenkins jobs
source ./$</bin/activate ; set -u ;\
$(PYTHON) buildcollector.py scrape.yaml --credentials credentials.yaml $(COMMON_ARGS)
siterender: $(VENV_NAME) site ## Create static website from build information
source ./$</bin/activate ; set -u ;\
$(PYTHON) siterender.py $(COMMON_ARGS)
cp -r static/* site/
serve:
cd site && $(PYTHON) -m http.server
sync:
rsync --delete-after -avP site/ ubuntu@static.opennetworking.org:/srv/sites/certification.opennetworking.org/
# testing targets
test: yamllint tox ## run all tests
# YAML files, excluding venv and cookiecutter directories
YAML_FILES ?= $(shell find . -type d \( -path "./venv-sjsg" \) -prune -o -type f \( -name '*.yaml' -o -name '*.yml' \) -print )
yamllint: $(VENV_NAME) ## lint YAML format using yamllint
source ./$</bin/activate ; set -u ;\
yamllint --version ;\
yamllint \
-d "{extends: default, rules: {line-length: {max: 139}}}" \
-s $(YAML_FILES)
tox: $(VENV_NAME) ## test code with tox
source ./$</bin/activate ; set -u ;\
tox
license: ## Check code for licensing with REUSE
reuse --root . lint
clean: ## Delete all temporary files
rm -rf products site *.xml *.egg-info
clean-all: clean ## Delete virtualenv and all cached job information
rm -rf $(VENV_NAME) jobs .tox
help: ## Print help for each target
@echo sjsg test targets
@echo
@grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
| sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'