blob: 4feb29b5132492eee684e47e63aac17a9a89bf56 [file] [log] [blame]
Joey Armstrong9956d972022-11-11 13:07:31 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2017-2022 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo2da72782022-06-13 11:30:07 -07004# SPDX-FileCopyrightText: 2022-present Intel Corporation
5#
6# SPDX-License-Identifier: Apache-2.0
Joey Armstrong9956d972022-11-11 13:07:31 -05007# -----------------------------------------------------------------------
Matteo Scandolo2da72782022-06-13 11:30:07 -07008
Joey Armstrong9956d972022-11-11 13:07:31 -05009.DEFAULT_GOAL := test
Matteo Scandolo2da72782022-06-13 11:30:07 -070010
Joey Armstrong9956d972022-11-11 13:07:31 -050011HIDE ?= @
12SHELL := bash -e -o pipefail
13
14dot ?= .
15TOP ?= $(dot)
16MAKEDIR ?= $(TOP)/makefiles
17
18env-clean = /usr/bin/env --ignore-environment
19
20jq = $(env-clean) jq
21jq-args += --exit-status
22
23YAMLLINT = $(shell which yamllint)
24yamllint := $(env-clean) $(YAMLLINT)
25yamllint-args := -c .yamllint
26
27##-------------------##
28##---] TARGETS [---##
29##-------------------##
30all:
31
32lint += lint-json
33lint += lint-yaml
34
35lint : $(lint)
36test : lint
37
38## -----------------------------------------------------------------------
39## -----------------------------------------------------------------------
40lint-yaml yaml-lint:
41ifeq ($(null),$(shell which yamllint))
Matteo Scandolo2da72782022-06-13 11:30:07 -070042 $(error "Please install yamllint to run linting")
43endif
Joey Armstrong9956d972022-11-11 13:07:31 -050044 $(HIDE)$(env-clean) find . -name '*.yaml' -type f -print0 \
45 | xargs -0 -t -n1 $(yamllint) $(yamllint-args)
46
47## -----------------------------------------------------------------------
48## -----------------------------------------------------------------------
49lint-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## -----------------------------------------------------------------------
55pre-check:
56 @echo "[REQUIRED] Checking for linting tools"
57 $(HIDE)which jq
58 $(HIDE)which yamllint
59 @echo
60
61## -----------------------------------------------------------------------
62## -----------------------------------------------------------------------
Joey Armstrongffd93d22022-12-02 09:37:18 -050063.PHONY: pre-commit
64.PHONY: fixperms
65pre-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## -----------------------------------------------------------------------
71fixperms-args :=$(null)
72fixperms-args += -name '*.conf'
73fixperms-args += -o -name '*.json'
74fixperms-args += -o -name '*.yaml'
75fixperms:
76 $(HIDE)find . \( $(fixperms-args) \) -print0 \
77 | xargs -0 chmod og-rwx
78
79## -----------------------------------------------------------------------
80## -----------------------------------------------------------------------
Joey Armstrong9956d972022-11-11 13:07:31 -050081clean:
82
83## -----------------------------------------------------------------------
84## -----------------------------------------------------------------------
85todo:
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## -----------------------------------------------------------------------
100help:
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 Armstrongffd93d22022-12-02 09:37:18 -0500111 @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 Armstrong9956d972022-11-11 13:07:31 -0500118# [EOF]