Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2017-2022 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 4 | # SPDX-FileCopyrightText: 2022-present Intel Corporation |
| 5 | # |
| 6 | # SPDX-License-Identifier: Apache-2.0 |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 7 | # ----------------------------------------------------------------------- |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 8 | |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 9 | .DEFAULT_GOAL := test |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 10 | |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 11 | HIDE ?= @ |
| 12 | SHELL := bash -e -o pipefail |
| 13 | |
| 14 | dot ?= . |
| 15 | TOP ?= $(dot) |
| 16 | MAKEDIR ?= $(TOP)/makefiles |
| 17 | |
| 18 | env-clean = /usr/bin/env --ignore-environment |
| 19 | |
| 20 | jq = $(env-clean) jq |
| 21 | jq-args += --exit-status |
| 22 | |
| 23 | YAMLLINT = $(shell which yamllint) |
| 24 | yamllint := $(env-clean) $(YAMLLINT) |
| 25 | yamllint-args := -c .yamllint |
| 26 | |
| 27 | ##-------------------## |
| 28 | ##---] TARGETS [---## |
| 29 | ##-------------------## |
| 30 | all: |
| 31 | |
| 32 | lint += lint-json |
| 33 | lint += lint-yaml |
| 34 | |
| 35 | lint : $(lint) |
| 36 | test : lint |
| 37 | |
| 38 | ## ----------------------------------------------------------------------- |
| 39 | ## ----------------------------------------------------------------------- |
| 40 | lint-yaml yaml-lint: |
| 41 | ifeq ($(null),$(shell which yamllint)) |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 42 | $(error "Please install yamllint to run linting") |
| 43 | endif |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 44 | $(HIDE)$(env-clean) find . -name '*.yaml' -type f -print0 \ |
| 45 | | xargs -0 -t -n1 $(yamllint) $(yamllint-args) |
| 46 | |
| 47 | ## ----------------------------------------------------------------------- |
| 48 | ## ----------------------------------------------------------------------- |
| 49 | lint-json: |
| 50 | $(HIDE)$(env-clean) find . -name '*.json' -type f -print0 \ |
| 51 | | xargs -0 -t -n1 $(jq) $(jq-args) $(dot) >/dev/null |
| 52 | |
| 53 | ## ----------------------------------------------------------------------- |
| 54 | ## ----------------------------------------------------------------------- |
| 55 | pre-check: |
| 56 | @echo "[REQUIRED] Checking for linting tools" |
| 57 | $(HIDE)which jq |
| 58 | $(HIDE)which yamllint |
| 59 | @echo |
| 60 | |
| 61 | ## ----------------------------------------------------------------------- |
| 62 | ## ----------------------------------------------------------------------- |
Joey Armstrong | ffd93d2 | 2022-12-02 09:37:18 -0500 | [diff] [blame^] | 63 | .PHONY: pre-commit |
| 64 | .PHONY: fixperms |
| 65 | pre-commit: lint fixperms |
| 66 | |
| 67 | ## ----------------------------------------------------------------------- |
| 68 | ## Scrub volume messages from jenksins logs and help secure nodes. |
| 69 | ## WARNING: Kubernetes configuration file is group-readable. This is insecure |
| 70 | ## ----------------------------------------------------------------------- |
| 71 | fixperms-args :=$(null) |
| 72 | fixperms-args += -name '*.conf' |
| 73 | fixperms-args += -o -name '*.json' |
| 74 | fixperms-args += -o -name '*.yaml' |
| 75 | fixperms: |
| 76 | $(HIDE)find . \( $(fixperms-args) \) -print0 \ |
| 77 | | xargs -0 chmod og-rwx |
| 78 | |
| 79 | ## ----------------------------------------------------------------------- |
| 80 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 81 | clean: |
| 82 | |
| 83 | ## ----------------------------------------------------------------------- |
| 84 | ## ----------------------------------------------------------------------- |
| 85 | todo: |
| 86 | @echo |
| 87 | @echo "USAGE: $(MAKE)" |
| 88 | @echo "[TODO]" |
| 89 | @echo " o Update to support standard makefile target behavior:" |
| 90 | @echo " all taget is test not default behavior for automation." |
| 91 | @echo " o Change lint target dep from test to check -or smoke" |
| 92 | @echo " target test sould be more involved with content validation" |
| 93 | @echo " o Refactor lint target(s) with voltha-system-tests/makefiles" |
| 94 | @echo " o Linting should be dependency driven," |
| 95 | @echo " only check when sources are modified." |
| 96 | @echo |
| 97 | |
| 98 | ## ----------------------------------------------------------------------- |
| 99 | ## ----------------------------------------------------------------------- |
| 100 | help: |
| 101 | @echo |
| 102 | @echo "USAGE: $(MAKE)" |
| 103 | @echo " lint perform syntax checks on source" |
| 104 | @echo " test perform syntax checks on source" |
| 105 | @echo " pre-check Verify tools and deps are available for testing" |
| 106 | @echo |
| 107 | @echo "[LINT]" |
| 108 | @echo " lint-json Syntax check .json sources" |
| 109 | @echo " lint-yaml Syntax check .yaml sources" |
| 110 | @echo |
Joey Armstrong | ffd93d2 | 2022-12-02 09:37:18 -0500 | [diff] [blame^] | 111 | @echo "[PRE:check]" |
| 112 | @echo " pre-check Verify tools and deps are available for testing" |
| 113 | @echo |
| 114 | @echo "[PRE:commit]" |
| 115 | @echo " pre-commit Perform common repairs on source" |
| 116 | @echo " fixperms Remove group write permission on config files" |
| 117 | @echo |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame] | 118 | # [EOF] |