Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org> |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | SHELL = bash -e -o pipefail |
| 5 | |
| 6 | # Common set of args, set to --debug for more output |
| 7 | COMMON_ARGS ?= --debug |
| 8 | |
| 9 | # tooling binaries |
Zack Williams | 483de86 | 2021-02-12 15:07:33 -0700 | [diff] [blame] | 10 | VIRTUALENV ?= python3 -m venv |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 11 | PYTHON ?= 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 Williams | 483de86 | 2021-02-12 15:07:33 -0700 | [diff] [blame] | 18 | VENV_NAME = venv-sjsg |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 19 | |
| 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 Williams | cb2746d | 2020-12-16 10:27:24 -0700 | [diff] [blame] | 27 | products: |
| 28 | mkdir products |
| 29 | |
| 30 | site: |
| 31 | mkdir site |
| 32 | |
Zack Williams | 7c32b91 | 2021-09-08 16:59:29 -0700 | [diff] [blame] | 33 | jobs: |
| 34 | mkdir jobs |
| 35 | |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 36 | build: buildcollector siterender ## Collect build info and create website |
| 37 | |
Zack Williams | 7c32b91 | 2021-09-08 16:59:29 -0700 | [diff] [blame] | 38 | buildcollector: $(VENV_NAME) jobs products ## Collect build information from Jenkins jobs |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 39 | source ./$</bin/activate ; set -u ;\ |
| 40 | $(PYTHON) buildcollector.py scrape.yaml --credentials credentials.yaml $(COMMON_ARGS) |
| 41 | |
Zack Williams | cb2746d | 2020-12-16 10:27:24 -0700 | [diff] [blame] | 42 | siterender: $(VENV_NAME) site ## Create static website from build information |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 43 | source ./$</bin/activate ; set -u ;\ |
| 44 | $(PYTHON) siterender.py $(COMMON_ARGS) |
| 45 | cp -r static/* site/ |
| 46 | |
| 47 | serve: |
| 48 | cd site && $(PYTHON) -m http.server |
| 49 | |
| 50 | sync: |
| 51 | rsync --delete-after -avP site/ ubuntu@static.opennetworking.org:/srv/sites/certification.opennetworking.org/ |
| 52 | |
| 53 | # testing targets |
| 54 | test: yamllint tox ## run all tests |
| 55 | |
| 56 | # YAML files, excluding venv and cookiecutter directories |
Zack Williams | 483de86 | 2021-02-12 15:07:33 -0700 | [diff] [blame] | 57 | YAML_FILES ?= $(shell find . -type d \( -path "./venv-sjsg" \) -prune -o -type f \( -name '*.yaml' -o -name '*.yml' \) -print ) |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 58 | |
| 59 | yamllint: $(VENV_NAME) ## lint YAML format using yamllint |
| 60 | source ./$</bin/activate ; set -u ;\ |
| 61 | yamllint --version ;\ |
| 62 | yamllint \ |
| 63 | -d "{extends: default, rules: {line-length: {max: 139}}}" \ |
| 64 | -s $(YAML_FILES) |
| 65 | |
Zack Williams | 483de86 | 2021-02-12 15:07:33 -0700 | [diff] [blame] | 66 | tox: $(VENV_NAME) ## test code with tox |
| 67 | source ./$</bin/activate ; set -u ;\ |
| 68 | tox |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 69 | |
| 70 | license: ## Check code for licensing with REUSE |
| 71 | reuse --root . lint |
| 72 | |
| 73 | clean: ## Delete all temporary files |
Zack Williams | 7c32b91 | 2021-09-08 16:59:29 -0700 | [diff] [blame] | 74 | rm -rf products site jobs *.xml *.egg-info |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 75 | |
| 76 | clean-all: clean ## Delete virtualenv and all cached job information |
Zack Williams | cb2746d | 2020-12-16 10:27:24 -0700 | [diff] [blame] | 77 | rm -rf $(VENV_NAME) jobs .tox |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 78 | |
| 79 | help: ## Print help for each target |
Zack Williams | cb2746d | 2020-12-16 10:27:24 -0700 | [diff] [blame] | 80 | @echo sjsg test targets |
Zack Williams | 712caf6 | 2020-04-28 13:37:41 -0700 | [diff] [blame] | 81 | @echo |
| 82 | @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 83 | | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};' |